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 16 namespace llvm { 17 class AsmToken; 18 class MCAsmInfo; 19 class MCAsmLexer; 20 class MCAsmParserExtension; 21 class MCContext; 22 class MCExpr; 23 class MCStreamer; 24 class MCTargetAsmParser; 25 class SMLoc; 26 class SMRange; 27 class SourceMgr; 28 class StringRef; 29 class Twine; 30 31 /// MCAsmParser - Generic assembler parser interface, for use by target specific 32 /// assembly parsers. 33 class MCAsmParser { 34 public: 35 typedef bool (*DirectiveHandler)(MCAsmParserExtension*, StringRef, SMLoc); 36 37 private: 38 MCAsmParser(const MCAsmParser &); // DO NOT IMPLEMENT 39 void operator=(const MCAsmParser &); // DO NOT IMPLEMENT 40 41 MCTargetAsmParser *TargetParser; 42 43 unsigned ShowParsedOperands : 1; 44 45 protected: // Can only create subclasses. 46 MCAsmParser(); 47 48 public: 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 getTargetParser()64 MCTargetAsmParser &getTargetParser() const { return *TargetParser; } 65 void setTargetParser(MCTargetAsmParser &P); 66 getAssemblerDialect()67 virtual unsigned getAssemblerDialect() { return 0;} setAssemblerDialect(unsigned i)68 virtual void setAssemblerDialect(unsigned i) { } 69 getShowParsedOperands()70 bool getShowParsedOperands() const { return ShowParsedOperands; } setShowParsedOperands(bool Value)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 \arg L, with the message \arg 77 /// Msg. 78 /// 79 /// \return The return value is true, if warnings are fatal. 80 virtual bool Warning(SMLoc L, const Twine &Msg, 81 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) = 0; 82 83 /// Error - Emit an error at the location \arg L, with the message \arg 84 /// Msg. 85 /// 86 /// \return The return value is always true, as an idiomatic convenience to 87 /// clients. 88 virtual bool Error(SMLoc L, const Twine &Msg, 89 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) = 0; 90 91 /// Lex - Get the next AsmToken in the stream, possibly handling file 92 /// inclusion first. 93 virtual const AsmToken &Lex() = 0; 94 95 /// getTok - Get the current AsmToken from the stream. 96 const AsmToken &getTok(); 97 98 /// \brief Report an error at the current lexer location. 99 bool TokError(const Twine &Msg, 100 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()); 101 102 /// ParseIdentifier - Parse an identifier or string (as a quoted identifier) 103 /// and set \arg Res to the identifier contents. 104 virtual bool ParseIdentifier(StringRef &Res) = 0; 105 106 /// \brief Parse up to the end of statement and return the contents from the 107 /// current token until the end of the statement; the current token on exit 108 /// will be either the EndOfStatement or EOF. 109 virtual StringRef ParseStringToEndOfStatement() = 0; 110 111 /// EatToEndOfStatement - Skip to the end of the current statement, for error 112 /// recovery. 113 virtual void EatToEndOfStatement() = 0; 114 115 /// ParseExpression - Parse an arbitrary expression. 116 /// 117 /// @param Res - The value of the expression. The result is undefined 118 /// on error. 119 /// @result - False on success. 120 virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0; 121 bool ParseExpression(const MCExpr *&Res); 122 123 /// ParseParenExpression - Parse an arbitrary expression, assuming that an 124 /// initial '(' has already been consumed. 125 /// 126 /// @param Res - The value of the expression. The result is undefined 127 /// on error. 128 /// @result - False on success. 129 virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0; 130 131 /// ParseAbsoluteExpression - Parse an expression which must evaluate to an 132 /// absolute value. 133 /// 134 /// @param Res - The value of the absolute expression. The result is undefined 135 /// on error. 136 /// @result - False on success. 137 virtual bool ParseAbsoluteExpression(int64_t &Res) = 0; 138 }; 139 140 /// \brief Create an MCAsmParser instance. 141 MCAsmParser *createMCAsmParser(SourceMgr &, MCContext &, 142 MCStreamer &, const MCAsmInfo &); 143 144 } // End llvm namespace 145 146 #endif 147