LLVM  8.0.1
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/STLExtras.h"
14 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Support/SMLoc.h"
18 
19 namespace llvm {
20 
21 class Twine;
22 
23 /// Generic interface for extending the MCAsmParser,
24 /// which is implemented by target and object file assembly parser
25 /// implementations.
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:
46  virtual ~MCAsmParserExtension();
47 
48  /// Initialize the extension for parsing using the given \p Parser.
49  /// The extension should use the AsmParser interfaces to register its
50  /// parsing routines.
51  virtual void Initialize(MCAsmParser &Parser);
52 
53  /// \name MCAsmParser Proxy Interfaces
54  /// @{
55 
57 
59  const MCAsmLexer &getLexer() const {
60  return const_cast<MCAsmParserExtension *>(this)->getLexer();
61  }
62 
63  MCAsmParser &getParser() { return *Parser; }
64  const MCAsmParser &getParser() const {
65  return const_cast<MCAsmParserExtension*>(this)->getParser();
66  }
67 
70 
71  bool Warning(SMLoc L, const Twine &Msg) {
72  return getParser().Warning(L, Msg);
73  }
74 
75  bool Error(SMLoc L, const Twine &Msg, SMRange Range = SMRange()) {
76  return getParser().Error(L, Msg, Range);
77  }
78 
79  void Note(SMLoc L, const Twine &Msg) {
80  getParser().Note(L, Msg);
81  }
82 
83  bool TokError(const Twine &Msg) {
84  return getParser().TokError(Msg);
85  }
86 
87  const AsmToken &Lex() { return getParser().Lex(); }
88  const AsmToken &getTok() { return getParser().getTok(); }
90  const Twine &Msg = "unexpected token") {
91  return getParser().parseToken(T, Msg);
92  }
93 
94  bool parseMany(function_ref<bool()> parseOne, bool hasComma = true) {
95  return getParser().parseMany(parseOne, hasComma);
96  }
97 
99  return getParser().parseOptionalToken(T);
100  }
101 
102  bool check(bool P, const Twine &Msg) {
103  return getParser().check(P, Msg);
104  }
105 
106  bool check(bool P, SMLoc Loc, const Twine &Msg) {
107  return getParser().check(P, Loc, Msg);
108  }
109 
110  bool addErrorSuffix(const Twine &Suffix) {
111  return getParser().addErrorSuffix(Suffix);
112  }
113 
115 
116  /// @}
117 };
118 
119 } // end namespace llvm
120 
121 #endif // LLVM_MC_MCPARSER_MCASMPARSEREXTENSION_H
Represents a range in source code.
Definition: SMLoc.h:49
bool addErrorSuffix(const Twine &Suffix)
bool parseMany(function_ref< bool()> parseOne, bool hasComma=true)
This class represents lattice values for constants.
Definition: AllocatorList.h:24
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:110
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
const MCAsmLexer & getLexer() const
bool parseOptionalToken(AsmToken::TokenKind T)
bool check(bool P, const Twine &Msg)
Definition: MCAsmParser.cpp:74
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:117
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
const AsmToken & getTok() const
Get the current AsmToken from the stream.
Definition: MCAsmParser.cpp:34
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:40
Target independent representation for an assembler token.
Definition: MCAsmMacro.h:22
Context object for machine code objects.
Definition: MCContext.h:63
bool check(bool P, SMLoc Loc, const Twine &Msg)
const MCAsmParser & getParser() const
bool parseToken(AsmToken::TokenKind T, const Twine &Msg="unexpected token")
Definition: MCAsmParser.cpp:50
#define P(N)
virtual MCContext & getContext()=0
Streaming machine code generation interface.
Definition: MCStreamer.h:189
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)
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:88
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:42
virtual MCStreamer & getStreamer()=0
Return the output streamer for the assembler.
bool parseMany(function_ref< bool()> parseOne, bool hasComma=true)
bool addErrorSuffix(const Twine &Suffix)
Target - Wrapper for Target specific information.
bool check(bool P, const 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.
bool TokError(const Twine &Msg, SMRange Range=None)
Report an error at the current lexer location.
Definition: MCAsmParser.cpp:84
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:67
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
MCAsmParserExtension & operator=(const MCAsmParserExtension &)=delete
Represents a location in source code.
Definition: SMLoc.h:24