LLVM  10.0.0svn
MCAsmParserExtension.h
Go to the documentation of this file.
1 //===- llvm/MC/MCAsmParserExtension.h - Asm Parser Hooks --------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_MC_MCPARSER_MCASMPARSEREXTENSION_H
10 #define LLVM_MC_MCPARSER_MCASMPARSEREXTENSION_H
11 
12 #include "llvm/ADT/STLExtras.h"
13 #include "llvm/ADT/StringRef.h"
16 #include "llvm/Support/SMLoc.h"
17 
18 namespace llvm {
19 
20 class Twine;
21 
22 /// Generic interface for extending the MCAsmParser,
23 /// which is implemented by target and object file assembly parser
24 /// implementations.
26  MCAsmParser *Parser;
27 
28 protected:
30 
31  // Helper template for implementing static dispatch functions.
32  template<typename T, bool (T::*Handler)(StringRef, SMLoc)>
34  StringRef Directive,
35  SMLoc DirectiveLoc) {
36  T *Obj = static_cast<T*>(Target);
37  return (Obj->*Handler)(Directive, DirectiveLoc);
38  }
39 
41 
42 public:
45  virtual ~MCAsmParserExtension();
46 
47  /// Initialize the extension for parsing using the given \p Parser.
48  /// The extension should use the AsmParser interfaces to register its
49  /// parsing routines.
50  virtual void Initialize(MCAsmParser &Parser);
51 
52  /// \name MCAsmParser Proxy Interfaces
53  /// @{
54 
56 
58  const MCAsmLexer &getLexer() const {
59  return const_cast<MCAsmParserExtension *>(this)->getLexer();
60  }
61 
62  MCAsmParser &getParser() { return *Parser; }
63  const MCAsmParser &getParser() const {
64  return const_cast<MCAsmParserExtension*>(this)->getParser();
65  }
66 
69 
70  bool Warning(SMLoc L, const Twine &Msg) {
71  return getParser().Warning(L, Msg);
72  }
73 
74  bool Error(SMLoc L, const Twine &Msg, SMRange Range = SMRange()) {
75  return getParser().Error(L, Msg, Range);
76  }
77 
78  void Note(SMLoc L, const Twine &Msg) {
79  getParser().Note(L, Msg);
80  }
81 
82  bool TokError(const Twine &Msg) {
83  return getParser().TokError(Msg);
84  }
85 
86  const AsmToken &Lex() { return getParser().Lex(); }
87  const AsmToken &getTok() { return getParser().getTok(); }
89  const Twine &Msg = "unexpected token") {
90  return getParser().parseToken(T, Msg);
91  }
92 
93  bool parseMany(function_ref<bool()> parseOne, bool hasComma = true) {
94  return getParser().parseMany(parseOne, hasComma);
95  }
96 
98  return getParser().parseOptionalToken(T);
99  }
100 
101  bool check(bool P, const Twine &Msg) {
102  return getParser().check(P, Msg);
103  }
104 
105  bool check(bool P, SMLoc Loc, const Twine &Msg) {
106  return getParser().check(P, Loc, Msg);
107  }
108 
109  bool addErrorSuffix(const Twine &Suffix) {
110  return getParser().addErrorSuffix(Suffix);
111  }
112 
114 
115  /// @}
116 };
117 
118 } // end namespace llvm
119 
120 #endif // LLVM_MC_MCPARSER_MCASMPARSEREXTENSION_H
Represents a range in source code.
Definition: SMLoc.h:48
bool addErrorSuffix(const Twine &Suffix)
bool parseMany(function_ref< bool()> parseOne, bool hasComma=true)
This class represents lattice values for constants.
Definition: AllocatorList.h:23
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:109
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:73
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:104
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:33
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:80
Generic assembler lexer interface, for use by target specific assembly lexers.
Definition: MCAsmLexer.h:39
Target independent representation for an assembler token.
Definition: MCAsmMacro.h:21
Context object for machine code objects.
Definition: MCContext.h:65
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:49
#define P(N)
virtual MCContext & getContext()=0
Streaming machine code generation interface.
Definition: MCStreamer.h:190
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:87
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:41
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:83
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:66
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
MCAsmParserExtension & operator=(const MCAsmParserExtension &)=delete
Represents a location in source code.
Definition: SMLoc.h:23