MCAsmParser.h revision c5252da873d547a19069eaf9030fec203f128f66
1//===-- llvm/MC/MCAsmParser.h - Abstract Asm Parser Interface ---*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef LLVM_MC_MCASMPARSER_H 11#define LLVM_MC_MCASMPARSER_H 12 13#include "llvm/Support/DataTypes.h" 14#include "llvm/ADT/ArrayRef.h" 15 16namespace llvm { 17class AsmToken; 18class MCAsmInfo; 19class MCAsmLexer; 20class MCAsmParserExtension; 21class MCContext; 22class MCExpr; 23class MCStreamer; 24class MCTargetAsmParser; 25class SMLoc; 26class SMRange; 27class SourceMgr; 28class StringRef; 29class Twine; 30 31/// MCAsmParser - Generic assembler parser interface, for use by target specific 32/// assembly parsers. 33class MCAsmParser { 34public: 35 typedef bool (*DirectiveHandler)(MCAsmParserExtension*, StringRef, SMLoc); 36 37private: 38 MCAsmParser(const MCAsmParser &) LLVM_DELETED_FUNCTION; 39 void operator=(const MCAsmParser &) LLVM_DELETED_FUNCTION; 40 41 MCTargetAsmParser *TargetParser; 42 43 unsigned ShowParsedOperands : 1; 44 45protected: // Can only create subclasses. 46 MCAsmParser(); 47 48public: 49 virtual ~MCAsmParser(); 50 51 virtual void AddDirectiveHandler(MCAsmParserExtension *Object, 52 StringRef Directive, 53 DirectiveHandler Handler) = 0; 54 55 virtual SourceMgr &getSourceManager() = 0; 56 57 virtual MCAsmLexer &getLexer() = 0; 58 59 virtual MCContext &getContext() = 0; 60 61 /// getStreamer - Return the output streamer for the assembler. 62 virtual MCStreamer &getStreamer() = 0; 63 64 MCTargetAsmParser &getTargetParser() const { return *TargetParser; } 65 void setTargetParser(MCTargetAsmParser &P); 66 67 virtual unsigned getAssemblerDialect() { return 0;} 68 virtual void setAssemblerDialect(unsigned i) { } 69 70 bool getShowParsedOperands() const { return ShowParsedOperands; } 71 void setShowParsedOperands(bool Value) { ShowParsedOperands = Value; } 72 73 /// Run - Run the parser on the input source buffer. 74 virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false) = 0; 75 76 /// Warning - Emit a warning at the location \p L, with the message \p Msg. 77 /// 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; 81 82 /// Error - Emit an error at the location \p L, with the message \p Msg. 83 /// 84 /// \return The return value is always true, as an idiomatic convenience to 85 /// clients. 86 virtual bool Error(SMLoc L, const Twine &Msg, 87 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) = 0; 88 89 /// Lex - Get the next AsmToken in the stream, possibly handling file 90 /// inclusion first. 91 virtual const AsmToken &Lex() = 0; 92 93 /// getTok - Get the current AsmToken from the stream. 94 const AsmToken &getTok(); 95 96 /// \brief Report an error at the current lexer location. 97 bool TokError(const Twine &Msg, 98 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()); 99 100 /// ParseIdentifier - Parse an identifier or string (as a quoted identifier) 101 /// and set \p Res to the identifier contents. 102 virtual bool ParseIdentifier(StringRef &Res) = 0; 103 104 /// \brief Parse up to the end of statement and return the contents from the 105 /// current token until the end of the statement; the current token on exit 106 /// will be either the EndOfStatement or EOF. 107 virtual StringRef ParseStringToEndOfStatement() = 0; 108 109 /// EatToEndOfStatement - Skip to the end of the current statement, for error 110 /// recovery. 111 virtual void EatToEndOfStatement() = 0; 112 113 /// ParseExpression - Parse an arbitrary expression. 114 /// 115 /// @param Res - The value of the expression. The result is undefined 116 /// on error. 117 /// @result - False on success. 118 virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0; 119 bool ParseExpression(const MCExpr *&Res); 120 121 /// ParseParenExpression - Parse an arbitrary expression, assuming that an 122 /// initial '(' has already been consumed. 123 /// 124 /// @param Res - The value of the expression. The result is undefined 125 /// on error. 126 /// @result - False on success. 127 virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0; 128 129 /// ParseAbsoluteExpression - Parse an expression which must evaluate to an 130 /// absolute value. 131 /// 132 /// @param Res - The value of the absolute expression. The result is undefined 133 /// on error. 134 /// @result - False on success. 135 virtual bool ParseAbsoluteExpression(int64_t &Res) = 0; 136}; 137 138/// \brief Create an MCAsmParser instance. 139MCAsmParser *createMCAsmParser(SourceMgr &, MCContext &, 140 MCStreamer &, const MCAsmInfo &); 141 142} // End llvm namespace 143 144#endif 145