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;
23 class MCParsedAsmOperand;
25 class MCTargetAsmParser;
32 /// MCAsmParser - Generic assembler parser interface, for use by target specific
36 typedef bool (*DirectiveHandler)(MCAsmParserExtension*, StringRef, SMLoc);
39 MCAsmParser(const MCAsmParser &) LLVM_DELETED_FUNCTION;
40 void operator=(const MCAsmParser &) LLVM_DELETED_FUNCTION;
42 MCTargetAsmParser *TargetParser;
44 unsigned ShowParsedOperands : 1;
46 protected: // Can only create subclasses.
50 virtual ~MCAsmParser();
52 virtual void AddDirectiveHandler(MCAsmParserExtension *Object,
54 DirectiveHandler Handler) = 0;
56 virtual SourceMgr &getSourceManager() = 0;
58 virtual MCAsmLexer &getLexer() = 0;
60 virtual MCContext &getContext() = 0;
62 /// getStreamer - Return the output streamer for the assembler.
63 virtual MCStreamer &getStreamer() = 0;
65 MCTargetAsmParser &getTargetParser() const { return *TargetParser; }
66 void setTargetParser(MCTargetAsmParser &P);
68 virtual unsigned getAssemblerDialect() { return 0;}
69 virtual void setAssemblerDialect(unsigned i) { }
71 bool getShowParsedOperands() const { return ShowParsedOperands; }
72 void setShowParsedOperands(bool Value) { ShowParsedOperands = Value; }
74 /// Run - Run the parser on the input source buffer.
75 virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false) = 0;
77 virtual void setParsingInlineAsm(bool V) = 0;
79 /// ParseStatement - Parse the next statement.
80 virtual bool ParseStatement() = 0;
82 /// getNumParsedOperands - Returns the number of MCAsmParsedOperands from the
83 /// previously parsed statement.
84 virtual unsigned getNumParsedOperands() = 0;
86 /// getParsedOperand - Get a MCAsmParsedOperand.
87 virtual MCParsedAsmOperand &getParsedOperand(unsigned OpNum) = 0;
89 /// freeParsedOperands - Free the MCAsmParsedOperands.
90 virtual void freeParsedOperands() = 0;
92 /// isInstruction - Was the previously parsed statement an instruction?
93 virtual bool isInstruction() = 0;
95 /// getOpcode - Get the opcode from the previously parsed instruction.
96 virtual unsigned getOpcode() = 0;
98 /// Warning - Emit a warning at the location \p L, with the message \p Msg.
100 /// \return The return value is true, if warnings are fatal.
101 virtual bool Warning(SMLoc L, const Twine &Msg,
102 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) = 0;
104 /// Error - Emit an error at the location \p L, with the message \p Msg.
106 /// \return The return value is always true, as an idiomatic convenience to
108 virtual bool Error(SMLoc L, const Twine &Msg,
109 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) = 0;
111 /// Lex - Get the next AsmToken in the stream, possibly handling file
113 virtual const AsmToken &Lex() = 0;
115 /// getTok - Get the current AsmToken from the stream.
116 const AsmToken &getTok();
118 /// \brief Report an error at the current lexer location.
119 bool TokError(const Twine &Msg,
120 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>());
122 /// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
123 /// and set \p Res to the identifier contents.
124 virtual bool ParseIdentifier(StringRef &Res) = 0;
126 /// \brief Parse up to the end of statement and return the contents from the
127 /// current token until the end of the statement; the current token on exit
128 /// will be either the EndOfStatement or EOF.
129 virtual StringRef ParseStringToEndOfStatement() = 0;
131 /// EatToEndOfStatement - Skip to the end of the current statement, for error
133 virtual void EatToEndOfStatement() = 0;
135 /// ParseExpression - Parse an arbitrary expression.
137 /// @param Res - The value of the expression. The result is undefined
139 /// @result - False on success.
140 virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
141 bool ParseExpression(const MCExpr *&Res);
143 /// ParseParenExpression - Parse an arbitrary expression, assuming that an
144 /// initial '(' has already been consumed.
146 /// @param Res - The value of the expression. The result is undefined
148 /// @result - False on success.
149 virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
151 /// ParseAbsoluteExpression - Parse an expression which must evaluate to an
154 /// @param Res - The value of the absolute expression. The result is undefined
156 /// @result - False on success.
157 virtual bool ParseAbsoluteExpression(int64_t &Res) = 0;
160 /// \brief Create an MCAsmParser instance.
161 MCAsmParser *createMCAsmParser(SourceMgr &, MCContext &,
162 MCStreamer &, const MCAsmInfo &);
164 } // End llvm namespace