1 //===-- llvm/MC/MCAsmParser.h - Abstract Asm Parser Interface ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_MCASMPARSER_H
11 #define LLVM_MC_MCASMPARSER_H
13 #include "llvm/Support/DataTypes.h"
14 #include "llvm/ADT/ArrayRef.h"
20 class MCAsmParserExtension;
25 class MCParsedAsmOperand;
27 class MCTargetAsmParser;
34 /// MCAsmParserSemaCallback - Generic Sema callback for assembly parser.
35 class MCAsmParserSemaCallback {
37 virtual ~MCAsmParserSemaCallback();
38 virtual void *LookupInlineAsmIdentifier(StringRef Name, void *Loc,
40 virtual bool LookupInlineAsmField(StringRef Base, StringRef Member,
41 unsigned &Offset) = 0;
44 /// MCAsmParser - Generic assembler parser interface, for use by target specific
48 typedef bool (*DirectiveHandler)(MCAsmParserExtension*, StringRef, SMLoc);
51 MCAsmParser(const MCAsmParser &) LLVM_DELETED_FUNCTION;
52 void operator=(const MCAsmParser &) LLVM_DELETED_FUNCTION;
54 MCTargetAsmParser *TargetParser;
56 unsigned ShowParsedOperands : 1;
58 protected: // Can only create subclasses.
62 virtual ~MCAsmParser();
64 virtual void AddDirectiveHandler(MCAsmParserExtension *Object,
66 DirectiveHandler Handler) = 0;
68 virtual SourceMgr &getSourceManager() = 0;
70 virtual MCAsmLexer &getLexer() = 0;
72 virtual MCContext &getContext() = 0;
74 /// getStreamer - Return the output streamer for the assembler.
75 virtual MCStreamer &getStreamer() = 0;
77 MCTargetAsmParser &getTargetParser() const { return *TargetParser; }
78 void setTargetParser(MCTargetAsmParser &P);
80 virtual unsigned getAssemblerDialect() { return 0;}
81 virtual void setAssemblerDialect(unsigned i) { }
83 bool getShowParsedOperands() const { return ShowParsedOperands; }
84 void setShowParsedOperands(bool Value) { ShowParsedOperands = Value; }
86 /// Run - Run the parser on the input source buffer.
87 virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false) = 0;
89 virtual void setParsingInlineAsm(bool V) = 0;
90 virtual bool isParsingInlineAsm() = 0;
92 /// ParseMSInlineAsm - Parse ms-style inline assembly.
93 virtual bool ParseMSInlineAsm(void *AsmLoc, std::string &AsmString,
94 unsigned &NumOutputs, unsigned &NumInputs,
95 SmallVectorImpl<std::pair<void *, bool> > &OpDecls,
96 SmallVectorImpl<std::string> &Constraints,
97 SmallVectorImpl<std::string> &Clobbers,
98 const MCInstrInfo *MII,
99 const MCInstPrinter *IP,
100 MCAsmParserSemaCallback &SI) = 0;
102 /// Warning - Emit a warning at the location \p L, with the message \p Msg.
104 /// \return The return value is true, if warnings are fatal.
105 virtual bool Warning(SMLoc L, const Twine &Msg,
106 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) = 0;
108 /// Error - Emit an error at the location \p L, with the message \p Msg.
110 /// \return The return value is always true, as an idiomatic convenience to
112 virtual bool Error(SMLoc L, const Twine &Msg,
113 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) = 0;
115 /// Lex - Get the next AsmToken in the stream, possibly handling file
117 virtual const AsmToken &Lex() = 0;
119 /// getTok - Get the current AsmToken from the stream.
120 const AsmToken &getTok();
122 /// \brief Report an error at the current lexer location.
123 bool TokError(const Twine &Msg,
124 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>());
126 /// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
127 /// and set \p Res to the identifier contents.
128 virtual bool ParseIdentifier(StringRef &Res) = 0;
130 /// \brief Parse up to the end of statement and return the contents from the
131 /// current token until the end of the statement; the current token on exit
132 /// will be either the EndOfStatement or EOF.
133 virtual StringRef ParseStringToEndOfStatement() = 0;
135 /// EatToEndOfStatement - Skip to the end of the current statement, for error
137 virtual void EatToEndOfStatement() = 0;
139 /// ParseExpression - Parse an arbitrary expression.
141 /// @param Res - The value of the expression. The result is undefined
143 /// @result - False on success.
144 virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
145 bool ParseExpression(const MCExpr *&Res);
147 /// ParseParenExpression - Parse an arbitrary expression, assuming that an
148 /// initial '(' has already been consumed.
150 /// @param Res - The value of the expression. The result is undefined
152 /// @result - False on success.
153 virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
155 /// ParseAbsoluteExpression - Parse an expression which must evaluate to an
158 /// @param Res - The value of the absolute expression. The result is undefined
160 /// @result - False on success.
161 virtual bool ParseAbsoluteExpression(int64_t &Res) = 0;
164 /// \brief Create an MCAsmParser instance.
165 MCAsmParser *createMCAsmParser(SourceMgr &, MCContext &,
166 MCStreamer &, const MCAsmInfo &);
168 } // End llvm namespace