LLVM API Documentation
00001 //===-- llvm/MC/MCAsmParser.h - Abstract Asm Parser Interface ---*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #ifndef LLVM_MC_MCPARSER_MCASMPARSER_H 00011 #define LLVM_MC_MCPARSER_MCASMPARSER_H 00012 00013 #include "llvm/ADT/ArrayRef.h" 00014 #include "llvm/ADT/StringRef.h" 00015 #include "llvm/MC/MCParser/AsmLexer.h" 00016 #include "llvm/Support/DataTypes.h" 00017 00018 namespace llvm { 00019 class MCAsmInfo; 00020 class MCAsmLexer; 00021 class MCAsmParserExtension; 00022 class MCContext; 00023 class MCExpr; 00024 class MCInstPrinter; 00025 class MCInstrInfo; 00026 class MCStreamer; 00027 class MCTargetAsmParser; 00028 class SMLoc; 00029 class SMRange; 00030 class SourceMgr; 00031 class Twine; 00032 00033 class InlineAsmIdentifierInfo { 00034 public: 00035 void *OpDecl; 00036 bool IsVarDecl; 00037 unsigned Length, Size, Type; 00038 00039 void clear() { 00040 OpDecl = nullptr; 00041 IsVarDecl = false; 00042 Length = 1; 00043 Size = 0; 00044 Type = 0; 00045 } 00046 }; 00047 00048 /// MCAsmParserSemaCallback - Generic Sema callback for assembly parser. 00049 class MCAsmParserSemaCallback { 00050 public: 00051 virtual ~MCAsmParserSemaCallback(); 00052 virtual void *LookupInlineAsmIdentifier(StringRef &LineBuf, 00053 InlineAsmIdentifierInfo &Info, 00054 bool IsUnevaluatedContext) = 0; 00055 00056 virtual bool LookupInlineAsmField(StringRef Base, StringRef Member, 00057 unsigned &Offset) = 0; 00058 }; 00059 00060 /// MCAsmParser - Generic assembler parser interface, for use by target specific 00061 /// assembly parsers. 00062 class MCAsmParser { 00063 public: 00064 typedef bool (*DirectiveHandler)(MCAsmParserExtension*, StringRef, SMLoc); 00065 typedef std::pair<MCAsmParserExtension*, DirectiveHandler> 00066 ExtensionDirectiveHandler; 00067 00068 private: 00069 MCAsmParser(const MCAsmParser &) LLVM_DELETED_FUNCTION; 00070 void operator=(const MCAsmParser &) LLVM_DELETED_FUNCTION; 00071 00072 MCTargetAsmParser *TargetParser; 00073 00074 unsigned ShowParsedOperands : 1; 00075 00076 protected: // Can only create subclasses. 00077 MCAsmParser(); 00078 00079 public: 00080 virtual ~MCAsmParser(); 00081 00082 virtual void addDirectiveHandler(StringRef Directive, 00083 ExtensionDirectiveHandler Handler) = 0; 00084 00085 virtual SourceMgr &getSourceManager() = 0; 00086 00087 virtual MCAsmLexer &getLexer() = 0; 00088 00089 virtual MCContext &getContext() = 0; 00090 00091 /// getStreamer - Return the output streamer for the assembler. 00092 virtual MCStreamer &getStreamer() = 0; 00093 00094 MCTargetAsmParser &getTargetParser() const { return *TargetParser; } 00095 void setTargetParser(MCTargetAsmParser &P); 00096 00097 virtual unsigned getAssemblerDialect() { return 0;} 00098 virtual void setAssemblerDialect(unsigned i) { } 00099 00100 bool getShowParsedOperands() const { return ShowParsedOperands; } 00101 void setShowParsedOperands(bool Value) { ShowParsedOperands = Value; } 00102 00103 /// Run - Run the parser on the input source buffer. 00104 virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false) = 0; 00105 00106 virtual void setParsingInlineAsm(bool V) = 0; 00107 virtual bool isParsingInlineAsm() = 0; 00108 00109 /// parseMSInlineAsm - Parse ms-style inline assembly. 00110 virtual bool parseMSInlineAsm(void *AsmLoc, std::string &AsmString, 00111 unsigned &NumOutputs, unsigned &NumInputs, 00112 SmallVectorImpl<std::pair<void *, bool> > &OpDecls, 00113 SmallVectorImpl<std::string> &Constraints, 00114 SmallVectorImpl<std::string> &Clobbers, 00115 const MCInstrInfo *MII, 00116 const MCInstPrinter *IP, 00117 MCAsmParserSemaCallback &SI) = 0; 00118 00119 /// Note - Emit a note at the location \p L, with the message \p Msg. 00120 virtual void Note(SMLoc L, const Twine &Msg, 00121 ArrayRef<SMRange> Ranges = None) = 0; 00122 00123 /// Warning - Emit a warning at the location \p L, with the message \p Msg. 00124 /// 00125 /// \return The return value is true, if warnings are fatal. 00126 virtual bool Warning(SMLoc L, const Twine &Msg, 00127 ArrayRef<SMRange> Ranges = None) = 0; 00128 00129 /// Error - Emit an error at the location \p L, with the message \p Msg. 00130 /// 00131 /// \return The return value is always true, as an idiomatic convenience to 00132 /// clients. 00133 virtual bool Error(SMLoc L, const Twine &Msg, 00134 ArrayRef<SMRange> Ranges = None) = 0; 00135 00136 /// Lex - Get the next AsmToken in the stream, possibly handling file 00137 /// inclusion first. 00138 virtual const AsmToken &Lex() = 0; 00139 00140 /// getTok - Get the current AsmToken from the stream. 00141 const AsmToken &getTok(); 00142 00143 /// \brief Report an error at the current lexer location. 00144 bool TokError(const Twine &Msg, ArrayRef<SMRange> Ranges = None); 00145 00146 /// parseIdentifier - Parse an identifier or string (as a quoted identifier) 00147 /// and set \p Res to the identifier contents. 00148 virtual bool parseIdentifier(StringRef &Res) = 0; 00149 00150 /// \brief Parse up to the end of statement and return the contents from the 00151 /// current token until the end of the statement; the current token on exit 00152 /// will be either the EndOfStatement or EOF. 00153 virtual StringRef parseStringToEndOfStatement() = 0; 00154 00155 /// parseEscapedString - Parse the current token as a string which may include 00156 /// escaped characters and return the string contents. 00157 virtual bool parseEscapedString(std::string &Data) = 0; 00158 00159 /// eatToEndOfStatement - Skip to the end of the current statement, for error 00160 /// recovery. 00161 virtual void eatToEndOfStatement() = 0; 00162 00163 /// parseExpression - Parse an arbitrary expression. 00164 /// 00165 /// @param Res - The value of the expression. The result is undefined 00166 /// on error. 00167 /// @result - False on success. 00168 virtual bool parseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0; 00169 bool parseExpression(const MCExpr *&Res); 00170 00171 /// parsePrimaryExpr - Parse a primary expression. 00172 /// 00173 /// @param Res - The value of the expression. The result is undefined 00174 /// on error. 00175 /// @result - False on success. 00176 virtual bool parsePrimaryExpr(const MCExpr *&Res, SMLoc &EndLoc) = 0; 00177 00178 /// parseParenExpression - Parse an arbitrary expression, assuming that an 00179 /// initial '(' has already been consumed. 00180 /// 00181 /// @param Res - The value of the expression. The result is undefined 00182 /// on error. 00183 /// @result - False on success. 00184 virtual bool parseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0; 00185 00186 /// parseAbsoluteExpression - Parse an expression which must evaluate to an 00187 /// absolute value. 00188 /// 00189 /// @param Res - The value of the absolute expression. The result is undefined 00190 /// on error. 00191 /// @result - False on success. 00192 virtual bool parseAbsoluteExpression(int64_t &Res) = 0; 00193 00194 /// checkForValidSection - Ensure that we have a valid section set in the 00195 /// streamer. Otherwise, report an error and switch to .text. 00196 virtual void checkForValidSection() = 0; 00197 }; 00198 00199 /// \brief Create an MCAsmParser instance. 00200 MCAsmParser *createMCAsmParser(SourceMgr &, MCContext &, 00201 MCStreamer &, const MCAsmInfo &); 00202 00203 } // End llvm namespace 00204 00205 #endif