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/System/DataTypes.h"
19 class MCAsmParserExtension;
27 class TargetAsmParser;
30 /// MCAsmParser - Generic assembler parser interface, for use by target specific
34 typedef bool (*DirectiveHandler)(MCAsmParserExtension*, StringRef, SMLoc);
37 MCAsmParser(const MCAsmParser &); // DO NOT IMPLEMENT
38 void operator=(const MCAsmParser &); // DO NOT IMPLEMENT
40 TargetAsmParser *TargetParser;
42 unsigned ShowParsedOperands : 1;
44 protected: // Can only create subclasses.
48 virtual ~MCAsmParser();
50 virtual void AddDirectiveHandler(MCAsmParserExtension *Object,
52 DirectiveHandler Handler) = 0;
54 virtual SourceMgr &getSourceManager() = 0;
56 virtual MCAsmLexer &getLexer() = 0;
58 virtual MCContext &getContext() = 0;
60 /// getStreamer - Return the output streamer for the assembler.
61 virtual MCStreamer &getStreamer() = 0;
63 TargetAsmParser &getTargetParser() const { return *TargetParser; }
64 void setTargetParser(TargetAsmParser &P);
66 bool getShowParsedOperands() const { return ShowParsedOperands; }
67 void setShowParsedOperands(bool Value) { ShowParsedOperands = Value; }
69 /// Run - Run the parser on the input source buffer.
70 virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false) = 0;
72 /// Warning - Emit a warning at the location \arg L, with the message \arg
74 virtual void Warning(SMLoc L, const Twine &Msg) = 0;
76 /// Error - Emit an error at the location \arg L, with the message \arg
79 /// \return The return value is always true, as an idiomatic convenience to
81 virtual bool Error(SMLoc L, const Twine &Msg) = 0;
83 /// Lex - Get the next AsmToken in the stream, possibly handling file
85 virtual const AsmToken &Lex() = 0;
87 /// getTok - Get the current AsmToken from the stream.
88 const AsmToken &getTok();
90 /// \brief Report an error at the current lexer location.
91 bool TokError(const Twine &Msg);
93 /// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
94 /// and set \arg Res to the identifier contents.
95 virtual bool ParseIdentifier(StringRef &Res) = 0;
97 /// \brief Parse up to the end of statement and return the contents from the
98 /// current token until the end of the statement; the current token on exit
99 /// will be either the EndOfStatement or EOF.
100 virtual StringRef ParseStringToEndOfStatement() = 0;
102 /// EatToEndOfStatement - Skip to the end of the current statement, for error
104 virtual void EatToEndOfStatement() = 0;
106 /// ParseExpression - Parse an arbitrary expression.
108 /// @param Res - The value of the expression. The result is undefined
110 /// @result - False on success.
111 virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
112 bool ParseExpression(const MCExpr *&Res);
114 /// ParseParenExpression - Parse an arbitrary expression, assuming that an
115 /// initial '(' has already been consumed.
117 /// @param Res - The value of the expression. The result is undefined
119 /// @result - False on success.
120 virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
122 /// ParseAbsoluteExpression - Parse an expression which must evaluate to an
125 /// @param Res - The value of the absolute expression. The result is undefined
127 /// @result - False on success.
128 virtual bool ParseAbsoluteExpression(int64_t &Res) = 0;
131 /// \brief Create an MCAsmParser instance.
132 MCAsmParser *createMCAsmParser(const Target &, SourceMgr &, MCContext &,
133 MCStreamer &, const MCAsmInfo &);
135 } // End llvm namespace