LLVM  4.0.0
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 &) = delete;
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 
55 
57  const MCAsmLexer &getLexer() const {
58  return const_cast<MCAsmParserExtension *>(this)->getLexer();
59  }
60 
61  MCAsmParser &getParser() { return *Parser; }
62  const MCAsmParser &getParser() const {
63  return const_cast<MCAsmParserExtension*>(this)->getParser();
64  }
65 
68  bool Warning(SMLoc L, const Twine &Msg) {
69  return getParser().Warning(L, Msg);
70  }
71  bool Error(SMLoc L, const Twine &Msg, SMRange Range = SMRange()) {
72  return getParser().Error(L, Msg, Range);
73  }
74  void Note(SMLoc L, const Twine &Msg) {
75  getParser().Note(L, Msg);
76  }
77  bool TokError(const Twine &Msg) {
78  return getParser().TokError(Msg);
79  }
80 
81  const AsmToken &Lex() { return getParser().Lex(); }
82  const AsmToken &getTok() { return getParser().getTok(); }
84  const Twine &Msg = "unexpected token") {
85  return getParser().parseToken(T, Msg);
86  }
87 
88  bool parseMany(std::function<bool()> parseOne, bool hasComma = true) {
89  return getParser().parseMany(parseOne, hasComma);
90  }
91 
93  return getParser().parseOptionalToken(T);
94  }
95 
96  bool check(bool P, const llvm::Twine &Msg) {
97  return getParser().check(P, Msg);
98  }
99 
100  bool check(bool P, SMLoc Loc, const llvm::Twine &Msg) {
101  return getParser().check(P, Loc, Msg);
102  }
103 
104  bool addErrorSuffix(const Twine &Suffix) {
105  return getParser().addErrorSuffix(Suffix);
106  }
107 
109 
110  /// @}
111 };
112 
113 } // End llvm namespace
114 
115 #endif
MachineLoop * L
Represents a range in source code.
Definition: SMLoc.h:49
bool addErrorSuffix(const Twine &Suffix)
virtual bool Warning(SMLoc L, const Twine &Msg, SMRange Range=None)=0
Emit a warning at the location L, with the message Msg.
Generic assembler parser interface, for use by target specific assembly parsers.
Definition: MCAsmParser.h:66
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
bool parseOptionalToken(AsmToken::TokenKind T)
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
virtual SourceMgr & getSourceManager()=0
bool Error(SMLoc L, const Twine &Msg, SMRange Range=SMRange())
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
Generic assembler lexer interface, for use by target specific assembly lexers.
Definition: MCAsmLexer.h:147
Target independent representation for an assembler token.
Definition: MCAsmLexer.h:25
Context object for machine code objects.
Definition: MCContext.h:51
bool parseMany(std::function< bool()> parseOne, bool hasComma=true)
const AsmToken & getTok() const
Get the current AsmToken from the stream.
Definition: MCAsmParser.cpp:33
bool parseToken(AsmToken::TokenKind T, const Twine &Msg="unexpected token")
Definition: MCAsmParser.cpp:54
#define P(N)
virtual MCContext & getContext()=0
Streaming machine code generation interface.
Definition: MCStreamer.h:161
bool Warning(SMLoc L, const Twine &Msg)
bool TokError(const Twine &Msg)
const MCAsmParser & getParser() const
virtual MCAsmLexer & getLexer()=0
static bool HandleDirective(MCAsmParserExtension *Target, StringRef Directive, SMLoc DirectiveLoc)
bool parseToken(AsmToken::TokenKind T, const Twine &Msg="unexpected token")
bool Error(SMLoc L, const Twine &Msg, SMRange Range=None)
Return an error at the location L, with the message Msg.
Definition: MCAsmParser.cpp:95
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:35
bool parseMany(std::function< bool()> parseOne, bool hasComma=true)
virtual MCStreamer & getStreamer()=0
Return the output streamer for the assembler.
static const char * Target
bool addErrorSuffix(const Twine &Suffix)
bool check(bool P, const llvm::Twine &Msg)
Definition: MCAsmParser.cpp:81
Target - Wrapper for Target specific information.
bool check(bool P, SMLoc Loc, const llvm::Twine &Msg)
void Note(SMLoc L, const Twine &Msg)
virtual void Note(SMLoc L, const Twine &Msg, SMRange Range=None)=0
Emit a note at the location L, with the message Msg.
const MCAsmLexer & getLexer() const
bool TokError(const Twine &Msg, SMRange Range=None)
Report an error at the current lexer location.
Definition: MCAsmParser.cpp:91
bool check(bool P, const llvm::Twine &Msg)
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
bool parseOptionalToken(AsmToken::TokenKind T)
Attempt to parse and consume token, returning true on success.
Definition: MCAsmParser.cpp:71
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
Represents a location in source code.
Definition: SMLoc.h:24