LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCAsmParserExtension.h
Go to the documentation of this file.
1 //===-- llvm/MC/MCAsmParserExtension.h - Asm Parser Hooks -------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_MC_MCPARSER_MCASMPARSEREXTENSION_H
11 #define LLVM_MC_MCPARSER_MCASMPARSEREXTENSION_H
12 
13 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/SMLoc.h"
16 
17 namespace llvm {
18 class Twine;
19 
20 /// \brief Generic interface for extending the MCAsmParser,
21 /// which is implemented by target and object file assembly parser
22 /// implementations.
25  void operator=(const MCAsmParserExtension &) LLVM_DELETED_FUNCTION;
26 
27  MCAsmParser *Parser;
28 
29 protected:
31 
32  // Helper template for implementing static dispatch functions.
33  template<typename T, bool (T::*Handler)(StringRef, SMLoc)>
35  StringRef Directive,
36  SMLoc DirectiveLoc) {
37  T *Obj = static_cast<T*>(Target);
38  return (Obj->*Handler)(Directive, DirectiveLoc);
39  }
40 
42 
43 public:
44  virtual ~MCAsmParserExtension();
45 
46  /// \brief Initialize the extension for parsing using the given \p Parser.
47  /// The extension should use the AsmParser interfaces to register its
48  /// parsing routines.
49  virtual void Initialize(MCAsmParser &Parser);
50 
51  /// @name MCAsmParser Proxy Interfaces
52  /// @{
53 
56  MCAsmParser &getParser() { return *Parser; }
59  bool Warning(SMLoc L, const Twine &Msg) {
60  return getParser().Warning(L, Msg);
61  }
62  bool Error(SMLoc L, const Twine &Msg) {
63  return getParser().Error(L, Msg);
64  }
65  bool TokError(const Twine &Msg) {
66  return getParser().TokError(Msg);
67  }
68 
69  const AsmToken &Lex() { return getParser().Lex(); }
70 
71  const AsmToken &getTok() { return getParser().getTok(); }
72 
74 
75  /// @}
76 };
77 
78 } // End llvm namespace
79 
80 #endif
virtual bool Warning(SMLoc L, const Twine &Msg, ArrayRef< SMRange > Ranges=None)=0
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser. The extension should use the AsmParser i...
virtual const AsmToken & Lex()=0
virtual SourceMgr & getSourceManager()=0
bool TokError(const Twine &Msg, ArrayRef< SMRange > Ranges=None)
Report an error at the current lexer location.
Definition: MCAsmParser.cpp:36
AsmToken - Target independent representation for an assembler token.
Definition: MCAsmLexer.h:21
const AsmToken & getTok()
getTok - Get the current AsmToken from the stream.
Definition: MCAsmParser.cpp:32
virtual MCContext & getContext()=0
bool Warning(SMLoc L, const Twine &Msg)
bool TokError(const Twine &Msg)
virtual MCAsmLexer & getLexer()=0
static bool HandleDirective(MCAsmParserExtension *Target, StringRef Directive, SMLoc DirectiveLoc)
virtual bool Error(SMLoc L, const Twine &Msg, ArrayRef< SMRange > Ranges=None)=0
bool Error(SMLoc L, const Twine &Msg)
virtual MCStreamer & getStreamer()=0
getStreamer - Return the output streamer for the assembler.
#define LLVM_DELETED_FUNCTION
Definition: Compiler.h:137
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
Represents a location in source code.
Definition: SMLoc.h:23