MCAsmParser.h revision f9f40bd158942f8cd1c3ed62106280f36a022cde
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_MCPARSER_MCASMPARSER_H 11#define LLVM_MC_MCPARSER_MCASMPARSER_H 12 13#include "llvm/ADT/ArrayRef.h" 14#include "llvm/ADT/StringRef.h" 15#include "llvm/MC/MCParser/AsmLexer.h" 16#include "llvm/Support/DataTypes.h" 17#include <vector> 18 19namespace llvm { 20class MCAsmInfo; 21class MCAsmLexer; 22class MCAsmParserExtension; 23class MCContext; 24class MCExpr; 25class MCInstPrinter; 26class MCInstrInfo; 27class MCParsedAsmOperand; 28class MCStreamer; 29class MCTargetAsmParser; 30class SMLoc; 31class SMRange; 32class SourceMgr; 33class StringRef; 34class Twine; 35 36/// MCAsmParserSemaCallback - Generic Sema callback for assembly parser. 37class MCAsmParserSemaCallback { 38public: 39 virtual ~MCAsmParserSemaCallback(); 40 virtual void *LookupInlineAsmIdentifier(StringRef Name, void *Loc, 41 unsigned &Size, bool &IsVarDecl) = 0; 42 virtual bool LookupInlineAsmField(StringRef Base, StringRef Member, 43 unsigned &Offset) = 0; 44}; 45 46 47/// MCAsmParser - Generic assembler parser interface, for use by target specific 48/// assembly parsers. 49class MCAsmParser { 50public: 51 typedef bool (*DirectiveHandler)(MCAsmParserExtension*, StringRef, SMLoc); 52 typedef std::pair<MCAsmParserExtension*, DirectiveHandler> 53 ExtensionDirectiveHandler; 54 55private: 56 MCAsmParser(const MCAsmParser &) LLVM_DELETED_FUNCTION; 57 void operator=(const MCAsmParser &) LLVM_DELETED_FUNCTION; 58 59 MCTargetAsmParser *TargetParser; 60 61 unsigned ShowParsedOperands : 1; 62 63protected: // Can only create subclasses. 64 MCAsmParser(); 65 66public: 67 virtual ~MCAsmParser(); 68 69 virtual void AddDirectiveHandler(StringRef Directive, 70 ExtensionDirectiveHandler Handler) = 0; 71 72 virtual SourceMgr &getSourceManager() = 0; 73 74 virtual MCAsmLexer &getLexer() = 0; 75 76 virtual MCContext &getContext() = 0; 77 78 /// getStreamer - Return the output streamer for the assembler. 79 virtual MCStreamer &getStreamer() = 0; 80 81 MCTargetAsmParser &getTargetParser() const { return *TargetParser; } 82 void setTargetParser(MCTargetAsmParser &P); 83 84 virtual unsigned getAssemblerDialect() { return 0;} 85 virtual void setAssemblerDialect(unsigned i) { } 86 87 bool getShowParsedOperands() const { return ShowParsedOperands; } 88 void setShowParsedOperands(bool Value) { ShowParsedOperands = Value; } 89 90 /// Run - Run the parser on the input source buffer. 91 virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false) = 0; 92 93 virtual void setParsingInlineAsm(bool V) = 0; 94 virtual bool isParsingInlineAsm() = 0; 95 96 /// ParseMSInlineAsm - Parse ms-style inline assembly. 97 virtual bool ParseMSInlineAsm(void *AsmLoc, std::string &AsmString, 98 unsigned &NumOutputs, unsigned &NumInputs, 99 SmallVectorImpl<std::pair<void *, bool> > &OpDecls, 100 SmallVectorImpl<std::string> &Constraints, 101 SmallVectorImpl<std::string> &Clobbers, 102 const MCInstrInfo *MII, 103 const MCInstPrinter *IP, 104 MCAsmParserSemaCallback &SI) = 0; 105 106 /// Warning - Emit a warning at the location \p L, with the message \p Msg. 107 /// 108 /// \return The return value is true, if warnings are fatal. 109 virtual bool Warning(SMLoc L, const Twine &Msg, 110 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) = 0; 111 112 /// Error - Emit an error at the location \p L, with the message \p Msg. 113 /// 114 /// \return The return value is always true, as an idiomatic convenience to 115 /// clients. 116 virtual bool Error(SMLoc L, const Twine &Msg, 117 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()) = 0; 118 119 /// Lex - Get the next AsmToken in the stream, possibly handling file 120 /// inclusion first. 121 virtual const AsmToken &Lex() = 0; 122 123 /// getTok - Get the current AsmToken from the stream. 124 const AsmToken &getTok(); 125 126 /// \brief Report an error at the current lexer location. 127 bool TokError(const Twine &Msg, 128 ArrayRef<SMRange> Ranges = ArrayRef<SMRange>()); 129 130 /// ParseIdentifier - Parse an identifier or string (as a quoted identifier) 131 /// and set \p Res to the identifier contents. 132 virtual bool ParseIdentifier(StringRef &Res) = 0; 133 134 /// \brief Parse up to the end of statement and return the contents from the 135 /// current token until the end of the statement; the current token on exit 136 /// will be either the EndOfStatement or EOF. 137 virtual StringRef ParseStringToEndOfStatement() = 0; 138 139 /// EatToEndOfStatement - Skip to the end of the current statement, for error 140 /// recovery. 141 virtual void EatToEndOfStatement() = 0; 142 143 /// ParseExpression - Parse an arbitrary expression. 144 /// 145 /// @param Res - The value of the expression. The result is undefined 146 /// on error. 147 /// @result - False on success. 148 virtual bool ParseExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0; 149 bool ParseExpression(const MCExpr *&Res); 150 151 /// ParseParenExpression - Parse an arbitrary expression, assuming that an 152 /// initial '(' has already been consumed. 153 /// 154 /// @param Res - The value of the expression. The result is undefined 155 /// on error. 156 /// @result - False on success. 157 virtual bool ParseParenExpression(const MCExpr *&Res, SMLoc &EndLoc) = 0; 158 159 /// ParseAbsoluteExpression - Parse an expression which must evaluate to an 160 /// absolute value. 161 /// 162 /// @param Res - The value of the absolute expression. The result is undefined 163 /// on error. 164 /// @result - False on success. 165 virtual bool ParseAbsoluteExpression(int64_t &Res) = 0; 166 167 /// CheckForValidSection - Ensure that we have a valid section set in the 168 /// streamer. Otherwise, report and error and switch to .text. 169 virtual void CheckForValidSection() = 0; 170}; 171 172/// \brief Create an MCAsmParser instance. 173MCAsmParser *createMCAsmParser(SourceMgr &, MCContext &, 174 MCStreamer &, const MCAsmInfo &); 175 176} // End llvm namespace 177 178#endif 179