MCTargetAsmParser.h revision 47a24ab4d72dc0f78c2027327cb9a69d6de2bbcd
1//===-- llvm/MC/MCTargetAsmParser.h - Target Assembly Parser ----*- 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_TARGETPARSER_H 11#define LLVM_MC_TARGETPARSER_H 12 13#include "llvm/MC/MCParser/MCAsmParserExtension.h" 14 15namespace llvm { 16class MCStreamer; 17class StringRef; 18class SMLoc; 19class AsmToken; 20class MCParsedAsmOperand; 21template <typename T> class SmallVectorImpl; 22 23/// MCTargetAsmParser - Generic interface to target specific assembly parsers. 24class MCTargetAsmParser : public MCAsmParserExtension { 25public: 26 enum MatchResultTy { 27 Match_ConversionFail, 28 Match_InvalidOperand, 29 Match_MissingFeature, 30 Match_MnemonicFail, 31 Match_Success 32 }; 33 34private: 35 MCTargetAsmParser(const MCTargetAsmParser &); // DO NOT IMPLEMENT 36 void operator=(const MCTargetAsmParser &); // DO NOT IMPLEMENT 37protected: // Can only create subclasses. 38 MCTargetAsmParser(); 39 40 /// AvailableFeatures - The current set of available features. 41 unsigned AvailableFeatures; 42 43public: 44 virtual ~MCTargetAsmParser(); 45 46 unsigned getAvailableFeatures() const { return AvailableFeatures; } 47 void setAvailableFeatures(unsigned Value) { AvailableFeatures = Value; } 48 49 virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, 50 SMLoc &EndLoc) = 0; 51 52 /// ParseInstruction - Parse one assembly instruction. 53 /// 54 /// The parser is positioned following the instruction name. The target 55 /// specific instruction parser should parse the entire instruction and 56 /// construct the appropriate MCInst, or emit an error. On success, the entire 57 /// line should be parsed up to and including the end-of-statement token. On 58 /// failure, the parser is not required to read to the end of the line. 59 // 60 /// \param Name - The instruction name. 61 /// \param NameLoc - The source location of the name. 62 /// \param Operands [out] - The list of parsed operands, this returns 63 /// ownership of them to the caller. 64 /// \return True on failure. 65 virtual bool ParseInstruction(StringRef Name, SMLoc NameLoc, 66 SmallVectorImpl<MCParsedAsmOperand*> &Operands) = 0; 67 68 /// ParseDirective - Parse a target specific assembler directive 69 /// 70 /// The parser is positioned following the directive name. The target 71 /// specific directive parser should parse the entire directive doing or 72 /// recording any target specific work, or return true and do nothing if the 73 /// directive is not target specific. If the directive is specific for 74 /// the target, the entire line is parsed up to and including the 75 /// end-of-statement token and false is returned. 76 /// 77 /// \param DirectiveID - the identifier token of the directive. 78 virtual bool ParseDirective(AsmToken DirectiveID) = 0; 79 80 /// MatchAndEmitInstruction - Recognize a series of operands of a parsed 81 /// instruction as an actual MCInst and emit it to the specified MCStreamer. 82 /// This returns false on success and returns true on failure to match. 83 /// 84 /// On failure, the target parser is responsible for emitting a diagnostic 85 /// explaining the match failure. 86 virtual bool 87 MatchAndEmitInstruction(SMLoc IDLoc, 88 SmallVectorImpl<MCParsedAsmOperand*> &Operands, 89 MCStreamer &Out) = 0; 90 91}; 92 93} // End llvm namespace 94 95#endif 96