LLVM 19.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
13#include "llvm/ADT/StringRef.h"
15#include "llvm/Support/SMLoc.h"
16
17namespace llvm {
18
19class Twine;
20
21/// Generic interface for extending the MCAsmParser,
22/// which is implemented by target and object file assembly parser
23/// implementations.
25 MCAsmParser *Parser = nullptr;
26
27protected:
29
30 // Helper template for implementing static dispatch functions.
31 template<typename T, bool (T::*Handler)(StringRef, SMLoc)>
34 SMLoc DirectiveLoc) {
35 T *Obj = static_cast<T*>(Target);
36 return (Obj->*Handler)(Directive, DirectiveLoc);
37 }
38
40
41public:
45
46 /// 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
69 bool Warning(SMLoc L, const Twine &Msg) {
70 return getParser().Warning(L, Msg);
71 }
72
73 bool Error(SMLoc L, const Twine &Msg, SMRange Range = SMRange()) {
74 return getParser().Error(L, Msg, Range);
75 }
76
77 void Note(SMLoc L, const Twine &Msg) {
78 getParser().Note(L, Msg);
79 }
80
81 bool TokError(const Twine &Msg) {
82 return getParser().TokError(Msg);
83 }
84
85 const AsmToken &Lex() { return getParser().Lex(); }
86 const AsmToken &getTok() { return getParser().getTok(); }
88 const Twine &Msg = "unexpected token") {
89 return getParser().parseToken(T, Msg);
90 }
91 bool parseEOL() { return getParser().parseEOL(); }
92
93 bool parseMany(function_ref<bool()> parseOne, bool hasComma = true) {
94 return getParser().parseMany(parseOne, hasComma);
95 }
96
99 }
100
102
103 bool check(bool P, const Twine &Msg) {
104 return getParser().check(P, Msg);
105 }
106
107 bool check(bool P, SMLoc Loc, const Twine &Msg) {
108 return getParser().check(P, Loc, Msg);
109 }
110
111 bool addErrorSuffix(const Twine &Suffix) {
112 return getParser().addErrorSuffix(Suffix);
113 }
114
116
117 /// @}
118};
119
120} // end namespace llvm
121
122#endif // LLVM_MC_MCPARSER_MCASMPARSEREXTENSION_H
#define P(N)
Target independent representation for an assembler token.
Definition: MCAsmMacro.h:21
Generic assembler lexer interface, for use by target specific assembly lexers.
Definition: MCAsmLexer.h:37
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
const MCAsmParser & getParser() const
bool parseOptionalToken(AsmToken::TokenKind T)
static bool HandleDirective(MCAsmParserExtension *Target, StringRef Directive, SMLoc DirectiveLoc)
bool addErrorSuffix(const Twine &Suffix)
MCAsmParserExtension & operator=(const MCAsmParserExtension &)=delete
bool parseMany(function_ref< bool()> parseOne, bool hasComma=true)
bool parseToken(AsmToken::TokenKind T, const Twine &Msg="unexpected token")
MCAsmParserExtension(const MCAsmParserExtension &)=delete
bool Warning(SMLoc L, const Twine &Msg)
virtual void Initialize(MCAsmParser &Parser)
Initialize the extension for parsing using the given Parser.
bool TokError(const Twine &Msg)
bool check(bool P, const Twine &Msg)
void Note(SMLoc L, const Twine &Msg)
bool Error(SMLoc L, const Twine &Msg, SMRange Range=SMRange())
bool check(bool P, SMLoc Loc, const Twine &Msg)
bool ParseDirectiveCGProfile(StringRef, SMLoc)
ParseDirectiveCGProfile ::= .cg_profile identifier, identifier, <number>
const MCAsmLexer & getLexer() const
Generic assembler parser interface, for use by target specific assembly parsers.
Definition: MCAsmParser.h:123
bool parseMany(function_ref< bool()> parseOne, bool hasComma=true)
bool parseToken(AsmToken::TokenKind T, const Twine &Msg="unexpected token")
Definition: MCAsmParser.cpp:63
bool addErrorSuffix(const Twine &Suffix)
bool check(bool P, const Twine &Msg)
Definition: MCAsmParser.cpp:87
virtual MCStreamer & getStreamer()=0
Return the output streamer for the assembler.
virtual void Note(SMLoc L, const Twine &Msg, SMRange Range=std::nullopt)=0
Emit a note at the location L, with the message Msg.
virtual SourceMgr & getSourceManager()=0
const AsmToken & getTok() const
Get the current AsmToken from the stream.
Definition: MCAsmParser.cpp:40
bool parseOptionalToken(AsmToken::TokenKind T)
Attempt to parse and consume token, returning true on success.
Definition: MCAsmParser.cpp:80
virtual const AsmToken & Lex()=0
Get the next AsmToken in the stream, possibly handling file inclusion first.
virtual MCAsmLexer & getLexer()=0
virtual bool Warning(SMLoc L, const Twine &Msg, SMRange Range=std::nullopt)=0
Emit a warning at the location L, with the message Msg.
bool TokError(const Twine &Msg, SMRange Range=std::nullopt)
Report an error at the current lexer location.
Definition: MCAsmParser.cpp:97
virtual MCContext & getContext()=0
bool Error(SMLoc L, const Twine &Msg, SMRange Range=std::nullopt)
Return an error at the location L, with the message Msg.
Context object for machine code objects.
Definition: MCContext.h:81
Streaming machine code generation interface.
Definition: MCStreamer.h:212
Represents a location in source code.
Definition: SMLoc.h:23
Represents a range in source code.
Definition: SMLoc.h:48
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition: SourceMgr.h:31
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
An efficient, type-erasing, non-owning reference to a callable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18