Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:12

0001 //===- llvm/MC/MCAsmParserExtension.h - Asm Parser Hooks --------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
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 /// Generic interface for extending the MCAsmParser,
0022 /// which is implemented by target and object file assembly parser
0023 /// implementations.
0024 class MCAsmParserExtension {
0025   MCAsmParser *Parser = nullptr;
0026 
0027 protected:
0028   MCAsmParserExtension();
0029 
0030   // Helper template for implementing static dispatch functions.
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   /// Initialize the extension for parsing using the given \p Parser.
0047   /// The extension should use the AsmParser interfaces to register its
0048   /// parsing routines.
0049   virtual void Initialize(MCAsmParser &Parser);
0050 
0051   /// \name MCAsmParser Proxy Interfaces
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 } // end namespace llvm
0121 
0122 #endif // LLVM_MC_MCPARSER_MCASMPARSEREXTENSION_H