LLVM 23.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"
16#include "llvm/Support/SMLoc.h"
17
18namespace llvm {
19
20class MCLFIRewriter;
21class 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 = nullptr;
28
29protected:
31
32 // Helper template for implementing static dispatch functions.
33 template<typename T, bool (T::*Handler)(StringRef, SMLoc)>
36 SMLoc DirectiveLoc) {
37 T *Obj = static_cast<T*>(Target);
38 return (Obj->*Handler)(Directive, DirectiveLoc);
39 }
40
42
43public:
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
56 MCContext &getContext() { return getParser().getContext(); }
57
58 AsmLexer &getLexer() { return getParser().getLexer(); }
59 const AsmLexer &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
68 SourceMgr &getSourceManager() { return getParser().getSourceManager(); }
69 MCStreamer &getStreamer() { return getParser().getStreamer(); }
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 bool parseEOL() { return getParser().parseEOL(); }
94
95 bool parseMany(function_ref<bool()> parseOne, bool hasComma = true) {
96 return getParser().parseMany(parseOne, hasComma);
97 }
98
100 return getParser().parseOptionalToken(T);
101 }
102
103 bool parseDirectiveCGProfile(StringRef, SMLoc);
104
105 bool maybeParseUniqueID(int64_t &UniqueID);
106
107 bool check(bool P, const Twine &Msg) {
108 return getParser().check(P, Msg);
109 }
110
111 bool check(bool P, SMLoc Loc, const Twine &Msg) {
112 return getParser().check(P, Loc, Msg);
113 }
114
115 bool addErrorSuffix(const Twine &Suffix) {
116 return getParser().addErrorSuffix(Suffix);
117 }
118
120
121 /// @}
122};
123
124LLVM_ABI MCAsmParserExtension *createDarwinAsmParser();
125LLVM_ABI MCAsmParserExtension *createELFAsmParser();
126LLVM_ABI MCAsmParserExtension *createCOFFAsmParser();
127LLVM_ABI MCAsmParserExtension *createCOFFMasmParser();
128LLVM_ABI MCAsmParserExtension *createGOFFAsmParser();
129LLVM_ABI MCAsmParserExtension *createXCOFFAsmParser();
130LLVM_ABI MCAsmParserExtension *createWasmAsmParser();
131LLVM_ABI MCAsmParserExtension *createLFIAsmParser(MCLFIRewriter *Exp);
132
133} // end namespace llvm
134
135#endif // LLVM_MC_MCPARSER_MCASMPARSEREXTENSION_H
#define LLVM_ABI
Definition Compiler.h:213
#define T
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
#define P(N)
Target independent representation for an assembler token.
Definition MCAsmMacro.h:22
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)
const AsmLexer & getLexer() const
Generic assembler parser interface, for use by target specific assembly parsers.
Context object for machine code objects.
Definition MCContext.h:83
Streaming machine code generation interface.
Definition MCStreamer.h:221
Represents a location in source code.
Definition SMLoc.h:22
Represents a range in source code.
Definition SMLoc.h:47
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition SourceMgr.h:37
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
An efficient, type-erasing, non-owning reference to a callable.
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
LLVM_ABI MCAsmParserExtension * createCOFFAsmParser()
LLVM_ABI MCAsmParserExtension * createLFIAsmParser(MCLFIRewriter *Exp)
LLVM_ABI MCAsmParserExtension * createXCOFFAsmParser()
LLVM_ABI MCAsmParserExtension * createGOFFAsmParser()
LLVM_ABI MCAsmParserExtension * createCOFFMasmParser()
LLVM_ABI MCAsmParserExtension * createWasmAsmParser()
LLVM_ABI MCAsmParserExtension * createELFAsmParser()
LLVM_ABI MCAsmParserExtension * createDarwinAsmParser()