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"
19 class MCAsmParserExtension;
23 class MCTargetAsmParser;
29 /// MCAsmParser - Generic assembler parser interface, for use by target specific
33 typedef bool (*DirectiveHandler)(MCAsmParserExtension*, StringRef, SMLoc);
36 MCAsmParser(const MCAsmParser &); // DO NOT IMPLEMENT
37 void operator=(const MCAsmParser &); // DO NOT IMPLEMENT
39 MCTargetAsmParser *TargetParser;
41 unsigned ShowParsedOperands : 1;
43 protected: // Can only create subclasses.
47 virtual ~MCAsmParser();
49 virtual void AddDirectiveHandler(MCAsmParserExtension *Object,
51 DirectiveHandler Handler) = 0;
53 virtual SourceMgr &getSourceManager() = 0;
55 virtual MCAsmLexer &getLexer() = 0;
57 virtual MCContext &getContext() = 0;
59 /// getStreamer - Return the output streamer for the assembler.
60 virtual MCStreamer &getStreamer() = 0;
62 MCTargetAsmParser &getTargetParser() const { return *TargetParser; }
63 void setTargetParser(MCTargetAsmParser &P);
65 bool getShowParsedOperands() const { return ShowParsedOperands; }
66 void setShowParsedOperands(bool Value) { ShowParsedOperands = Value; }
68 /// Run - Run the parser on the input source buffer.
69 virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false) = 0;
71 /// Warning - Emit a warning at the location \arg L, with the message \arg
74 /// \return The return value is true, if warnings are fatal.
75 virtual bool Warning(SMLoc L, const Twine &Msg) = 0;
77 /// Error - Emit an error at the location \arg L, with the message \arg
80 /// \return The return value is always true, as an idiomatic convenience to
82 virtual bool Error(SMLoc L, const Twine &Msg) = 0;
84 /// Lex - Get the next AsmToken in the stream, possibly handling file
86 virtual const AsmToken &Lex() = 0;
88 /// getTok - Get the current AsmToken from the stream.
89 const AsmToken &getTok();
91 /// \brief Report an error at the current lexer location.
92 bool TokError(const Twine &Msg);
94 /// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
95 /// and set \arg Res to the identifier contents.
96 virtual bool ParseIdentifier(StringRef &Res) = 0;
98 /// \brief Parse up to the end of statement and return the contents from the
99 /// current token until the end of the statement; the current token on exit
100 /// will be either the EndOfStatement or EOF.
101 virtual StringRef ParseStringToEndOfStatement() = 0;
103 /// EatToEndOfStatement - Skip to the end of the current statement, for error
105 virtual void EatToEndOfStatement() = 0;
107 /// ParseExpression - Parse an arbitrary expression.
109 /// @param Res - The value of the expression. The result is undefined
111 /// @result - False on success.
112 virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
113 bool ParseExpression(const MCExpr *&Res);
115 /// ParseParenExpression - Parse an arbitrary expression, assuming that an
116 /// initial '(' has already been consumed.
118 /// @param Res - The value of the expression. The result is undefined
120 /// @result - False on success.
121 virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
123 /// ParseAbsoluteExpression - Parse an expression which must evaluate to an
126 /// @param Res - The value of the absolute expression. The result is undefined
128 /// @result - False on success.
129 virtual bool ParseAbsoluteExpression(int64_t &Res) = 0;
132 /// \brief Create an MCAsmParser instance.
133 MCAsmParser *createMCAsmParser(SourceMgr &, MCContext &,
134 MCStreamer &, const MCAsmInfo &);
136 } // End llvm namespace