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;
24 class MCTargetAsmParser;
31 /// MCAsmParser - Generic assembler parser interface, for use by target specific
35 typedef bool (*DirectiveHandler)(MCAsmParserExtension*, StringRef, SMLoc);
38 MCAsmParser(const MCAsmParser &); // DO NOT IMPLEMENT
39 void operator=(const MCAsmParser &); // DO NOT IMPLEMENT
41 MCTargetAsmParser *TargetParser;
43 unsigned ShowParsedOperands : 1;
45 protected: // Can only create subclasses.
49 virtual ~MCAsmParser();
51 virtual void AddDirectiveHandler(MCAsmParserExtension *Object,
53 DirectiveHandler Handler) = 0;
55 virtual SourceMgr &getSourceManager() = 0;
57 virtual MCAsmLexer &getLexer() = 0;
59 virtual MCContext &getContext() = 0;
61 /// getStreamer - Return the output streamer for the assembler.
62 virtual MCStreamer &getStreamer() = 0;
64 MCTargetAsmParser &getTargetParser() const { return *TargetParser; }
65 void setTargetParser(MCTargetAsmParser &P);
67 virtual unsigned getAssemblerDialect() { return 0;}
69 bool getShowParsedOperands() const { return ShowParsedOperands; }
70 void setShowParsedOperands(bool Value) { ShowParsedOperands = Value; }
72 /// Run - Run the parser on the input source buffer.
73 virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false) = 0;
75 /// Warning - Emit a warning at the location \arg L, with the message \arg
78 /// \return The return value is true, if warnings are fatal.
79 virtual bool Warning(SMLoc L, const Twine &Msg,
80 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) = 0;
82 /// Error - Emit an error at the location \arg L, with the message \arg
85 /// \return The return value is always true, as an idiomatic convenience to
87 virtual bool Error(SMLoc L, const Twine &Msg,
88 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) = 0;
90 /// Lex - Get the next AsmToken in the stream, possibly handling file
92 virtual const AsmToken &Lex() = 0;
94 /// getTok - Get the current AsmToken from the stream.
95 const AsmToken &getTok();
97 /// \brief Report an error at the current lexer location.
98 bool TokError(const Twine &Msg,
99 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>());
101 /// ParseIdentifier - Parse an identifier or string (as a quoted identifier)
102 /// and set \arg Res to the identifier contents.
103 virtual bool ParseIdentifier(StringRef &Res) = 0;
105 /// \brief Parse up to the end of statement and return the contents from the
106 /// current token until the end of the statement; the current token on exit
107 /// will be either the EndOfStatement or EOF.
108 virtual StringRef ParseStringToEndOfStatement() = 0;
110 /// EatToEndOfStatement - Skip to the end of the current statement, for error
112 virtual void EatToEndOfStatement() = 0;
114 /// ParseExpression - Parse an arbitrary expression.
116 /// @param Res - The value of the expression. The result is undefined
118 /// @result - False on success.
119 virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
120 bool ParseExpression(const MCExpr *&Res);
122 /// ParseParenExpression - Parse an arbitrary expression, assuming that an
123 /// initial '(' has already been consumed.
125 /// @param Res - The value of the expression. The result is undefined
127 /// @result - False on success.
128 virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0;
130 /// ParseAbsoluteExpression - Parse an expression which must evaluate to an
133 /// @param Res - The value of the absolute expression. The result is undefined
135 /// @result - False on success.
136 virtual bool ParseAbsoluteExpression(int64_t &Res) = 0;
139 /// \brief Create an MCAsmParser instance.
140 MCAsmParser *createMCAsmParser(SourceMgr &, MCContext &,
141 MCStreamer &, const MCAsmInfo &);
143 } // End llvm namespace