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;
78 virtual bool isParsingInlineAsm() = 0;
80 /// ParseStatement - Parse the next statement.
81 virtual bool ParseStatement() = 0;
83 /// getNumParsedOperands - Returns the number of MCAsmParsedOperands from the
84 /// previously parsed statement.
85 virtual unsigned getNumParsedOperands() = 0;
87 /// getParsedOperand - Get a MCAsmParsedOperand.
88 virtual MCParsedAsmOperand &getParsedOperand(unsigned OpNum) = 0;
90 /// freeParsedOperands - Free the MCAsmParsedOperands.
91 virtual void freeParsedOperands() = 0;
93 /// isInstruction - Was the previously parsed statement an instruction?
94 virtual bool isInstruction() = 0;
96 /// getOpcode - Get the opcode from the previously parsed instruction.
97 virtual unsigned getOpcode() = 0;
99 /// Warning - Emit a warning at the location \p L, with the message \p Msg.
101 /// \return The return value is true, if warnings are fatal.
102 virtual bool Warning(SMLoc L, const Twine &Msg,
103 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) = 0;
105 /// Error - Emit an error at the location \p L, with the message \p Msg.
107 /// \return The return value is always true, as an idiomatic convenience to
109 virtual bool Error(SMLoc L, const Twine &Msg,
110 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) = 0;
112 /// Lex - Get the next AsmToken in the stream, possibly handling file
114 virtual const AsmToken &Lex() = 0;
116 /// getTok - Get the current AsmToken from the stream.
117 const AsmToken &getTok();
119 /// \brief Report an error at the current lexer location.
120 bool TokError(const Twine &Msg,
121 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>());
123 /// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
124 /// and set \p Res to the identifier contents.
125 virtual bool ParseIdentifier(StringRef &Res) = 0;
127 /// \brief Parse up to the end of statement and return the contents from the
128 /// current token until the end of the statement; the current token on exit
129 /// will be either the EndOfStatement or EOF.
130 virtual StringRef ParseStringToEndOfStatement() = 0;
132 /// EatToEndOfStatement - Skip to the end of the current statement, for error
134 virtual void EatToEndOfStatement() = 0;
136 /// ParseExpression - Parse an arbitrary expression.
138 /// @param Res - The value of the expression. The result is undefined
140 /// @result - False on success.
141 virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
142 bool ParseExpression(const MCExpr *&Res);
144 /// ParseParenExpression - Parse an arbitrary expression, assuming that an
145 /// initial '(' has already been consumed.
147 /// @param Res - The value of the expression. The result is undefined
149 /// @result - False on success.
150 virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
152 /// ParseAbsoluteExpression - Parse an expression which must evaluate to an
155 /// @param Res - The value of the absolute expression. The result is undefined
157 /// @result - False on success.
158 virtual bool ParseAbsoluteExpression(int64_t &Res) = 0;
161 /// \brief Create an MCAsmParser instance.
162 MCAsmParser *createMCAsmParser(SourceMgr &, MCContext &,
163 MCStreamer &, const MCAsmInfo &);
165 } // End llvm namespace