LLVM  14.0.0git
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)>
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  bool parseEOL() { return getParser().parseEOL(); }
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 
103 
104  bool check(bool P, const Twine &Msg) {
105  return getParser().check(P, Msg);
106  }
107 
108  bool check(bool P, SMLoc Loc, const Twine &Msg) {
109  return getParser().check(P, Loc, Msg);
110  }
111 
112  bool addErrorSuffix(const Twine &Suffix) {
113  return getParser().addErrorSuffix(Suffix);
114  }
115 
117 
118  /// @}
119 };
120 
121 } // end namespace llvm
122 
123 #endif // LLVM_MC_MCPARSER_MCASMPARSEREXTENSION_H
llvm::MCAsmParser
Generic assembler parser interface, for use by target specific assembly parsers.
Definition: MCAsmParser.h:124
llvm::MCAsmParser::getSourceManager
virtual SourceMgr & getSourceManager()=0
llvm::MCAsmParser::Error
bool Error(SMLoc L, const Twine &Msg, SMRange Range=None)
Return an error at the location L, with the message Msg.
Definition: MCAsmParser.cpp:99
llvm::MCAsmParserExtension::operator=
MCAsmParserExtension & operator=(const MCAsmParserExtension &)=delete
llvm::MCAsmParser::getStreamer
virtual MCStreamer & getStreamer()=0
Return the output streamer for the assembler.
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::MCAsmParserExtension::Error
bool Error(SMLoc L, const Twine &Msg, SMRange Range=SMRange())
Definition: MCAsmParserExtension.h:74
llvm::MCAsmParserExtension::HasBracketExpressions
bool HasBracketExpressions() const
Definition: MCAsmParserExtension.h:116
llvm::MCAsmParserExtension::Note
void Note(SMLoc L, const Twine &Msg)
Definition: MCAsmParserExtension.h:78
llvm::MCAsmLexer
Generic assembler lexer interface, for use by target specific assembly lexers.
Definition: MCAsmLexer.h:39
llvm::MCAsmParserExtension::ParseDirectiveCGProfile
bool ParseDirectiveCGProfile(StringRef, SMLoc)
ParseDirectiveCGProfile ::= .cg_profile identifier, identifier, <number>
Definition: MCAsmParserExtension.cpp:25
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::MCAsmParser::parseEOL
bool parseEOL()
Definition: MCAsmParser.cpp:47
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:137
llvm::MCAsmParserExtension::Lex
const AsmToken & Lex()
Definition: MCAsmParserExtension.h:86
llvm::MCAsmParserExtension::addErrorSuffix
bool addErrorSuffix(const Twine &Suffix)
Definition: MCAsmParserExtension.h:112
llvm::MCAsmParserExtension::~MCAsmParserExtension
virtual ~MCAsmParserExtension()
llvm::MCAsmParserExtension::parseToken
bool parseToken(AsmToken::TokenKind T, const Twine &Msg="unexpected token")
Definition: MCAsmParserExtension.h:88
llvm::MCAsmParser::parseOptionalToken
bool parseOptionalToken(AsmToken::TokenKind T)
Attempt to parse and consume token, returning true on success.
Definition: MCAsmParser.cpp:78
llvm::AMDGPU::Exp::Target
Target
Definition: SIDefines.h:739
T
#define T
Definition: Mips16ISelLowering.cpp:341
STLExtras.h
MCAsmParser.h
llvm::MCAsmParserExtension::parseOptionalToken
bool parseOptionalToken(AsmToken::TokenKind T)
Definition: MCAsmParserExtension.h:98
llvm::AsmToken
Target independent representation for an assembler token.
Definition: MCAsmMacro.h:21
llvm::MCAsmParser::Lex
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:199
llvm::MCAsmParserExtension::getStreamer
MCStreamer & getStreamer()
Definition: MCAsmParserExtension.h:68
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
llvm::MCAsmParserExtension::getContext
MCContext & getContext()
Definition: MCAsmParserExtension.h:55
llvm::MCAsmParserExtension::check
bool check(bool P, const Twine &Msg)
Definition: MCAsmParserExtension.h:104
llvm::MCAsmParserExtension::TokError
bool TokError(const Twine &Msg)
Definition: MCAsmParserExtension.h:82
llvm::MCAsmParser::getContext
virtual MCContext & getContext()=0
SMLoc.h
llvm::MCAsmParser::Note
virtual void Note(SMLoc L, const Twine &Msg, SMRange Range=None)=0
Emit a note at the location L, with the message Msg.
llvm::MCAsmParserExtension::parseEOL
bool parseEOL()
Definition: MCAsmParserExtension.h:92
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:168
MCAsmLexer.h
llvm::MCAsmParserExtension::getParser
const MCAsmParser & getParser() const
Definition: MCAsmParserExtension.h:63
llvm::MCAsmParserExtension::check
bool check(bool P, SMLoc Loc, const Twine &Msg)
Definition: MCAsmParserExtension.h:108
llvm::MCAsmParser::addErrorSuffix
bool addErrorSuffix(const Twine &Suffix)
Definition: MCAsmParser.cpp:115
llvm::MCAsmParser::parseMany
bool parseMany(function_ref< bool()> parseOne, bool hasComma=true)
Definition: MCAsmParser.cpp:124
llvm::MCAsmParserExtension::Initialize
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
Definition: MCAsmParserExtension.cpp:19
llvm::MCAsmParser::check
bool check(bool P, const Twine &Msg)
Definition: MCAsmParser.cpp:85
llvm::MCAsmParserExtension::MCAsmParserExtension
MCAsmParserExtension()
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::MCAsmParserExtension::parseMany
bool parseMany(function_ref< bool()> parseOne, bool hasComma=true)
Definition: MCAsmParserExtension.h:94
llvm::MCAsmParser::getTok
const AsmToken & getTok() const
Get the current AsmToken from the stream.
Definition: MCAsmParser.cpp:38
llvm::MCAsmParserExtension
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
Definition: MCAsmParserExtension.h:25
llvm::SourceMgr
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition: SourceMgr.h:31
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::MCAsmParser::TokError
bool TokError(const Twine &Msg, SMRange Range=None)
Report an error at the current lexer location.
Definition: MCAsmParser.cpp:95
llvm::MCAsmParserExtension::getTok
const AsmToken & getTok()
Definition: MCAsmParserExtension.h:87
llvm::MCAsmParserExtension::getLexer
const MCAsmLexer & getLexer() const
Definition: MCAsmParserExtension.h:58
llvm::AsmToken::TokenKind
TokenKind
Definition: MCAsmMacro.h:23
llvm::MCAsmParser::getLexer
virtual MCAsmLexer & getLexer()=0
llvm::SMRange
Represents a range in source code.
Definition: SMLoc.h:48
llvm::MCAsmParserExtension::BracketExpressionsSupported
bool BracketExpressionsSupported
Definition: MCAsmParserExtension.h:40
llvm::MCAsmParserExtension::getLexer
MCAsmLexer & getLexer()
Definition: MCAsmParserExtension.h:57
llvm::MCAsmParser::Warning
virtual bool Warning(SMLoc L, const Twine &Msg, SMRange Range=None)=0
Emit a warning at the location L, with the message Msg.
llvm::MCAsmParserExtension::getSourceManager
SourceMgr & getSourceManager()
Definition: MCAsmParserExtension.h:67
llvm::Directive
Definition: DirectiveEmitter.h:100
llvm::MCAsmParserExtension::Warning
bool Warning(SMLoc L, const Twine &Msg)
Definition: MCAsmParserExtension.h:70
llvm::MCAsmParserExtension::getParser
MCAsmParser & getParser()
Definition: MCAsmParserExtension.h:62
llvm::MCAsmParser::parseToken
bool parseToken(AsmToken::TokenKind T, const Twine &Msg="unexpected token")
Definition: MCAsmParser.cpp:61
llvm::MCAsmParserExtension::HandleDirective
static bool HandleDirective(MCAsmParserExtension *Target, StringRef Directive, SMLoc DirectiveLoc)
Definition: MCAsmParserExtension.h:33