123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- #pragma once
- #ifdef __GNUC__
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wunused-parameter"
- #endif
- #ifndef LLVM_MC_MCPARSER_MCASMPARSER_H
- #define LLVM_MC_MCPARSER_MCASMPARSER_H
- #include "llvm/ADT/STLFunctionalExtras.h"
- #include "llvm/ADT/SmallString.h"
- #include "llvm/ADT/SmallVector.h"
- #include "llvm/ADT/StringRef.h"
- #include "llvm/ADT/Twine.h"
- #include "llvm/MC/MCAsmMacro.h"
- #include "llvm/Support/SMLoc.h"
- #include <cstdint>
- #include <string>
- #include <utility>
- namespace llvm {
- class MCAsmLexer;
- class MCAsmInfo;
- class MCAsmParserExtension;
- class MCContext;
- class MCExpr;
- class MCInstPrinter;
- class MCInstrInfo;
- class MCStreamer;
- class MCTargetAsmParser;
- class SourceMgr;
- struct InlineAsmIdentifierInfo {
- enum IdKind {
- IK_Invalid,
- IK_Label,
- IK_EnumVal,
- IK_Var
- };
-
- struct EnumIdentifier {
- int64_t EnumVal;
- };
-
- struct LabelIdentifier {
- void *Decl;
- };
-
- struct VariableIdentifier {
- void *Decl;
- bool IsGlobalLV;
- unsigned Length;
- unsigned Size;
- unsigned Type;
- };
-
- union {
- EnumIdentifier Enum;
- LabelIdentifier Label;
- VariableIdentifier Var;
- };
- bool isKind(IdKind kind) const { return Kind == kind; }
-
- void setEnum(int64_t enumVal) {
- assert(isKind(IK_Invalid) && "should be initialized only once");
- Kind = IK_EnumVal;
- Enum.EnumVal = enumVal;
- }
- void setLabel(void *decl) {
- assert(isKind(IK_Invalid) && "should be initialized only once");
- Kind = IK_Label;
- Label.Decl = decl;
- }
- void setVar(void *decl, bool isGlobalLV, unsigned size, unsigned type) {
- assert(isKind(IK_Invalid) && "should be initialized only once");
- Kind = IK_Var;
- Var.Decl = decl;
- Var.IsGlobalLV = isGlobalLV;
- Var.Size = size;
- Var.Type = type;
- Var.Length = size / type;
- }
- InlineAsmIdentifierInfo() : Kind(IK_Invalid) {}
- private:
-
- IdKind Kind;
- };
- struct AsmTypeInfo {
- StringRef Name;
- unsigned Size = 0;
- unsigned ElementSize = 0;
- unsigned Length = 0;
- };
- struct AsmFieldInfo {
- AsmTypeInfo Type;
- unsigned Offset = 0;
- };
- class MCAsmParserSemaCallback {
- public:
- virtual ~MCAsmParserSemaCallback();
- virtual void LookupInlineAsmIdentifier(StringRef &LineBuf,
- InlineAsmIdentifierInfo &Info,
- bool IsUnevaluatedContext) = 0;
- virtual StringRef LookupInlineAsmLabel(StringRef Identifier, SourceMgr &SM,
- SMLoc Location, bool Create) = 0;
- virtual bool LookupInlineAsmField(StringRef Base, StringRef Member,
- unsigned &Offset) = 0;
- };
- class MCAsmParser {
- public:
- using DirectiveHandler = bool (*)(MCAsmParserExtension*, StringRef, SMLoc);
- using ExtensionDirectiveHandler =
- std::pair<MCAsmParserExtension*, DirectiveHandler>;
- struct MCPendingError {
- SMLoc Loc;
- SmallString<64> Msg;
- SMRange Range;
- };
- private:
- MCTargetAsmParser *TargetParser = nullptr;
- protected:
- MCAsmParser();
- SmallVector<MCPendingError, 0> PendingErrors;
-
- bool HadError = false;
- bool ShowParsedOperands = false;
- public:
- MCAsmParser(const MCAsmParser &) = delete;
- MCAsmParser &operator=(const MCAsmParser &) = delete;
- virtual ~MCAsmParser();
- virtual void addDirectiveHandler(StringRef Directive,
- ExtensionDirectiveHandler Handler) = 0;
- virtual void addAliasForDirective(StringRef Directive, StringRef Alias) = 0;
- virtual SourceMgr &getSourceManager() = 0;
- virtual MCAsmLexer &getLexer() = 0;
- const MCAsmLexer &getLexer() const {
- return const_cast<MCAsmParser*>(this)->getLexer();
- }
- virtual MCContext &getContext() = 0;
-
- virtual MCStreamer &getStreamer() = 0;
- MCTargetAsmParser &getTargetParser() const { return *TargetParser; }
- void setTargetParser(MCTargetAsmParser &P);
- virtual unsigned getAssemblerDialect() { return 0;}
- virtual void setAssemblerDialect(unsigned i) { }
- bool getShowParsedOperands() const { return ShowParsedOperands; }
- void setShowParsedOperands(bool Value) { ShowParsedOperands = Value; }
-
- virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false) = 0;
- virtual void setParsingMSInlineAsm(bool V) = 0;
- virtual bool isParsingMSInlineAsm() = 0;
- virtual bool discardLTOSymbol(StringRef) const { return false; }
- virtual bool isParsingMasm() const { return false; }
- virtual bool defineMacro(StringRef Name, StringRef Value) { return true; }
- virtual bool lookUpField(StringRef Name, AsmFieldInfo &Info) const {
- return true;
- }
- virtual bool lookUpField(StringRef Base, StringRef Member,
- AsmFieldInfo &Info) const {
- return true;
- }
- virtual bool lookUpType(StringRef Name, AsmTypeInfo &Info) const {
- return true;
- }
-
- virtual bool parseMSInlineAsm(
- std::string &AsmString, unsigned &NumOutputs, unsigned &NumInputs,
- SmallVectorImpl<std::pair<void *, bool>> &OpDecls,
- SmallVectorImpl<std::string> &Constraints,
- SmallVectorImpl<std::string> &Clobbers, const MCInstrInfo *MII,
- const MCInstPrinter *IP, MCAsmParserSemaCallback &SI) = 0;
-
- virtual void Note(SMLoc L, const Twine &Msg,
- SMRange Range = std::nullopt) = 0;
-
-
-
- virtual bool Warning(SMLoc L, const Twine &Msg,
- SMRange Range = std::nullopt) = 0;
-
-
-
-
-
- bool Error(SMLoc L, const Twine &Msg, SMRange Range = std::nullopt);
-
-
-
-
- virtual bool printError(SMLoc L, const Twine &Msg,
- SMRange Range = std::nullopt) = 0;
- bool hasPendingError() { return !PendingErrors.empty(); }
- bool printPendingErrors() {
- bool rv = !PendingErrors.empty();
- for (auto Err : PendingErrors) {
- printError(Err.Loc, Twine(Err.Msg), Err.Range);
- }
- PendingErrors.clear();
- return rv;
- }
- void clearPendingErrors() { PendingErrors.clear(); }
- bool addErrorSuffix(const Twine &Suffix);
-
-
- virtual const AsmToken &Lex() = 0;
-
- const AsmToken &getTok() const;
-
- bool TokError(const Twine &Msg, SMRange Range = std::nullopt);
- bool parseTokenLoc(SMLoc &Loc);
- bool parseToken(AsmToken::TokenKind T, const Twine &Msg = "unexpected token");
-
-
- bool parseOptionalToken(AsmToken::TokenKind T);
- bool parseComma() { return parseToken(AsmToken::Comma, "expected comma"); }
- bool parseRParen() { return parseToken(AsmToken::RParen, "expected ')'"); }
- bool parseEOL();
- bool parseEOL(const Twine &ErrMsg);
- bool parseMany(function_ref<bool()> parseOne, bool hasComma = true);
- bool parseIntToken(int64_t &V, const Twine &ErrMsg);
- bool check(bool P, const Twine &Msg);
- bool check(bool P, SMLoc Loc, const Twine &Msg);
-
-
- virtual bool parseIdentifier(StringRef &Res) = 0;
-
-
-
- virtual StringRef parseStringToEndOfStatement() = 0;
-
-
- virtual bool parseEscapedString(std::string &Data) = 0;
-
-
- virtual bool parseAngleBracketString(std::string &Data) = 0;
-
- virtual void eatToEndOfStatement() = 0;
-
-
-
-
-
- virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
- bool parseExpression(const MCExpr *&Res);
-
-
-
-
-
- virtual bool parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc,
- AsmTypeInfo *TypeInfo) = 0;
-
-
-
-
-
-
- virtual bool parseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
-
-
-
-
-
- virtual bool parseAbsoluteExpression(int64_t &Res) = 0;
-
-
-
- virtual bool checkForValidSection() = 0;
-
-
-
-
-
-
-
-
- virtual bool parseParenExprOfDepth(unsigned ParenDepth, const MCExpr *&Res,
- SMLoc &EndLoc) = 0;
-
- bool parseGNUAttribute(SMLoc L, int64_t &Tag, int64_t &IntegerValue);
- };
- MCAsmParser *createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &,
- const MCAsmInfo &, unsigned CB = 0);
- MCAsmParser *createMCMasmParser(SourceMgr &, MCContext &, MCStreamer &,
- const MCAsmInfo &, struct tm, unsigned CB = 0);
- }
- #endif
- #ifdef __GNUC__
- #pragma GCC diagnostic pop
- #endif
|