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 15 namespace llvm { 16 class AsmToken; 17 class MCAsmInfo; 18 class MCAsmLexer; 19 class MCAsmParserExtension; 20 class MCContext; 21 class MCExpr; 22 class MCStreamer; 23 class MCTargetAsmParser; 24 class SMLoc; 25 class SourceMgr; 26 class StringRef; 27 class Twine; 28 29 /// MCAsmParser - Generic assembler parser interface, for use by target specific 30 /// assembly parsers. 31 class MCAsmParser { 32 public: 33 typedef bool (*DirectiveHandler)(MCAsmParserExtension*, StringRef, SMLoc); 34 35 private: 36 MCAsmParser(const MCAsmParser &); // DO NOT IMPLEMENT 37 void operator=(const MCAsmParser &); // DO NOT IMPLEMENT 38 39 MCTargetAsmParser *TargetParser; 40 41 unsigned ShowParsedOperands : 1; 42 43 protected: // Can only create subclasses. 44 MCAsmParser(); 45 46 public: 47 virtual ~MCAsmParser(); 48 49 virtual void AddDirectiveHandler(MCAsmParserExtension *Object, 50 StringRef Directive, 51 DirectiveHandler Handler) = 0; 52 53 virtual SourceMgr &getSourceManager() = 0; 54 55 virtual MCAsmLexer &getLexer() = 0; 56 57 virtual MCContext &getContext() = 0; 58 59 /// getStreamer - Return the output streamer for the assembler. 60 virtual MCStreamer &getStreamer() = 0; 61 getTargetParser()62 MCTargetAsmParser &getTargetParser() const { return *TargetParser; } 63 void setTargetParser(MCTargetAsmParser &P); 64 getShowParsedOperands()65 bool getShowParsedOperands() const { return ShowParsedOperands; } setShowParsedOperands(bool Value)66 void setShowParsedOperands(bool Value) { ShowParsedOperands = Value; } 67 68 /// Run - Run the parser on the input source buffer. 69 virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false) = 0; 70 71 /// Warning - Emit a warning at the location \arg L, with the message \arg 72 /// Msg. 73 /// 74 /// \return The return value is true, if warnings are fatal. 75 virtual bool Warning(SMLoc L, const Twine &Msg) = 0; 76 77 /// Error - Emit an error at the location \arg L, with the message \arg 78 /// Msg. 79 /// 80 /// \return The return value is always true, as an idiomatic convenience to 81 /// clients. 82 virtual bool Error(SMLoc L, const Twine &Msg) = 0; 83 84 /// Lex - Get the next AsmToken in the stream, possibly handling file 85 /// inclusion first. 86 virtual const AsmToken &Lex() = 0; 87 88 /// getTok - Get the current AsmToken from the stream. 89 const AsmToken &getTok(); 90 91 /// \brief Report an error at the current lexer location. 92 bool TokError(const Twine &Msg); 93 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; 97 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; 102 103 /// EatToEndOfStatement - Skip to the end of the current statement, for error 104 /// recovery. 105 virtual void EatToEndOfStatement() = 0; 106 107 /// ParseExpression - Parse an arbitrary expression. 108 /// 109 /// @param Res - The value of the expression. The result is undefined 110 /// on error. 111 /// @result - False on success. 112 virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0; 113 bool ParseExpression(const MCExpr *&Res); 114 115 /// ParseParenExpression - Parse an arbitrary expression, assuming that an 116 /// initial '(' has already been consumed. 117 /// 118 /// @param Res - The value of the expression. The result is undefined 119 /// on error. 120 /// @result - False on success. 121 virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0; 122 123 /// ParseAbsoluteExpression - Parse an expression which must evaluate to an 124 /// absolute value. 125 /// 126 /// @param Res - The value of the absolute expression. The result is undefined 127 /// on error. 128 /// @result - False on success. 129 virtual bool ParseAbsoluteExpression(int64_t &Res) = 0; 130 }; 131 132 /// \brief Create an MCAsmParser instance. 133 MCAsmParser *createMCAsmParser(SourceMgr &, MCContext &, 134 MCStreamer &, const MCAsmInfo &); 135 136 } // End llvm namespace 137 138 #endif 139