File indexing completed on 2026-05-10 08:44:12
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_MC_MCPARSER_MCASMPARSEREXTENSION_H
0010 #define LLVM_MC_MCPARSER_MCASMPARSEREXTENSION_H
0011
0012 #include "llvm/ADT/STLFunctionalExtras.h"
0013 #include "llvm/ADT/StringRef.h"
0014 #include "llvm/MC/MCParser/MCAsmParser.h"
0015 #include "llvm/Support/SMLoc.h"
0016
0017 namespace llvm {
0018
0019 class Twine;
0020
0021
0022
0023
0024 class MCAsmParserExtension {
0025 MCAsmParser *Parser = nullptr;
0026
0027 protected:
0028 MCAsmParserExtension();
0029
0030
0031 template<typename T, bool (T::*Handler)(StringRef, SMLoc)>
0032 static bool HandleDirective(MCAsmParserExtension *Target,
0033 StringRef Directive,
0034 SMLoc DirectiveLoc) {
0035 T *Obj = static_cast<T*>(Target);
0036 return (Obj->*Handler)(Directive, DirectiveLoc);
0037 }
0038
0039 bool BracketExpressionsSupported = false;
0040
0041 public:
0042 MCAsmParserExtension(const MCAsmParserExtension &) = delete;
0043 MCAsmParserExtension &operator=(const MCAsmParserExtension &) = delete;
0044 virtual ~MCAsmParserExtension();
0045
0046
0047
0048
0049 virtual void Initialize(MCAsmParser &Parser);
0050
0051
0052
0053
0054 MCContext &getContext() { return getParser().getContext(); }
0055
0056 MCAsmLexer &getLexer() { return getParser().getLexer(); }
0057 const MCAsmLexer &getLexer() const {
0058 return const_cast<MCAsmParserExtension *>(this)->getLexer();
0059 }
0060
0061 MCAsmParser &getParser() { return *Parser; }
0062 const MCAsmParser &getParser() const {
0063 return const_cast<MCAsmParserExtension*>(this)->getParser();
0064 }
0065
0066 SourceMgr &getSourceManager() { return getParser().getSourceManager(); }
0067 MCStreamer &getStreamer() { return getParser().getStreamer(); }
0068
0069 bool Warning(SMLoc L, const Twine &Msg) {
0070 return getParser().Warning(L, Msg);
0071 }
0072
0073 bool Error(SMLoc L, const Twine &Msg, SMRange Range = SMRange()) {
0074 return getParser().Error(L, Msg, Range);
0075 }
0076
0077 void Note(SMLoc L, const Twine &Msg) {
0078 getParser().Note(L, Msg);
0079 }
0080
0081 bool TokError(const Twine &Msg) {
0082 return getParser().TokError(Msg);
0083 }
0084
0085 const AsmToken &Lex() { return getParser().Lex(); }
0086 const AsmToken &getTok() { return getParser().getTok(); }
0087 bool parseToken(AsmToken::TokenKind T,
0088 const Twine &Msg = "unexpected token") {
0089 return getParser().parseToken(T, Msg);
0090 }
0091 bool parseEOL() { return getParser().parseEOL(); }
0092
0093 bool parseMany(function_ref<bool()> parseOne, bool hasComma = true) {
0094 return getParser().parseMany(parseOne, hasComma);
0095 }
0096
0097 bool parseOptionalToken(AsmToken::TokenKind T) {
0098 return getParser().parseOptionalToken(T);
0099 }
0100
0101 bool parseDirectiveCGProfile(StringRef, SMLoc);
0102
0103 bool check(bool P, const Twine &Msg) {
0104 return getParser().check(P, Msg);
0105 }
0106
0107 bool check(bool P, SMLoc Loc, const Twine &Msg) {
0108 return getParser().check(P, Loc, Msg);
0109 }
0110
0111 bool addErrorSuffix(const Twine &Suffix) {
0112 return getParser().addErrorSuffix(Suffix);
0113 }
0114
0115 bool HasBracketExpressions() const { return BracketExpressionsSupported; }
0116
0117
0118 };
0119
0120 }
0121
0122 #endif