MCTargetAsmParser.h revision 2cc97def7434345e399e4f5f3f2001d6d7a93c6f
136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//===-- llvm/MC/MCTargetAsmParser.h - Target Assembly Parser ----*- C++ -*-===// 236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// 336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// The LLVM Compiler Infrastructure 436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// 536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// This file is distributed under the University of Illinois Open Source 636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// License. See LICENSE.TXT for details. 736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// 836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//===----------------------------------------------------------------------===// 936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 1036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#ifndef LLVM_MC_TARGETPARSER_H 1136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#define LLVM_MC_TARGETPARSER_H 1236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 1336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/MC/MCParser/MCAsmParserExtension.h" 14dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 15dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hinesnamespace llvm { 16dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hinesclass MCStreamer; 17dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hinesclass StringRef; 1836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesclass SMLoc; 19dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hinesclass AsmToken; 20dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hinesclass MCParsedAsmOperand; 21dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hinesclass MCInst; 22dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hinestemplate <typename T> class SmallVectorImpl; 23dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines 24dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines/// MCTargetAsmParser - Generic interface to target specific assembly parsers. 25dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hinesclass MCTargetAsmParser : public MCAsmParserExtension { 26dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hinespublic: 27dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines enum MatchResultTy { 28dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines Match_InvalidOperand, 2936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines Match_MissingFeature, 3036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines Match_MnemonicFail, 3136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines Match_Success, 3236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines FIRST_TARGET_MATCH_RESULT_TY 3336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines }; 3436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 3536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesprivate: 3636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines MCTargetAsmParser(const MCTargetAsmParser &) LLVM_DELETED_FUNCTION; 3736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines void operator=(const MCTargetAsmParser &) LLVM_DELETED_FUNCTION; 3836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesprotected: // Can only create subclasses. 39 MCTargetAsmParser(); 40 41 /// AvailableFeatures - The current set of available features. 42 unsigned AvailableFeatures; 43 44public: 45 virtual ~MCTargetAsmParser(); 46 47 unsigned getAvailableFeatures() const { return AvailableFeatures; } 48 void setAvailableFeatures(unsigned Value) { AvailableFeatures = Value; } 49 50 virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, 51 SMLoc &EndLoc) = 0; 52 53 /// ParseInstruction - Parse one assembly instruction. 54 /// 55 /// The parser is positioned following the instruction name. The target 56 /// specific instruction parser should parse the entire instruction and 57 /// construct the appropriate MCInst, or emit an error. On success, the entire 58 /// line should be parsed up to and including the end-of-statement token. On 59 /// failure, the parser is not required to read to the end of the line. 60 // 61 /// \param Name - The instruction name. 62 /// \param NameLoc - The source location of the name. 63 /// \param Operands [out] - The list of parsed operands, this returns 64 /// ownership of them to the caller. 65 /// \return True on failure. 66 virtual bool ParseInstruction(StringRef Name, SMLoc NameLoc, 67 SmallVectorImpl<MCParsedAsmOperand*> &Operands) = 0; 68 69 /// ParseDirective - Parse a target specific assembler directive 70 /// 71 /// The parser is positioned following the directive name. The target 72 /// specific directive parser should parse the entire directive doing or 73 /// recording any target specific work, or return true and do nothing if the 74 /// directive is not target specific. If the directive is specific for 75 /// the target, the entire line is parsed up to and including the 76 /// end-of-statement token and false is returned. 77 /// 78 /// \param DirectiveID - the identifier token of the directive. 79 virtual bool ParseDirective(AsmToken DirectiveID) = 0; 80 81 /// MatchInstruction - Recognize a series of operands of a parsed instruction 82 /// as an actual MCInst. This returns false on success and returns true on 83 /// failure to match. 84 /// 85 /// On failure, the target parser is responsible for emitting a diagnostic 86 /// explaining the match failure. 87 virtual bool 88 MatchInstruction(SMLoc IDLoc, unsigned &Kind, 89 SmallVectorImpl<MCParsedAsmOperand*> &Operands, 90 SmallVectorImpl<MCInst> &MCInsts, 91 unsigned &OrigErrorInfo, 92 bool matchingInlineAsm = false) { 93 OrigErrorInfo = ~0x0; 94 return true; 95 } 96 97 /// MatchAndEmitInstruction - Recognize a series of operands of a parsed 98 /// instruction as an actual MCInst and emit it to the specified MCStreamer. 99 /// This returns false on success and returns true on failure to match. 100 /// 101 /// On failure, the target parser is responsible for emitting a diagnostic 102 /// explaining the match failure. 103 virtual bool 104 MatchAndEmitInstruction(SMLoc IDLoc, 105 SmallVectorImpl<MCParsedAsmOperand*> &Operands, 106 MCStreamer &Out) = 0; 107 108 /// checkTargetMatchPredicate - Validate the instruction match against 109 /// any complex target predicates not expressible via match classes. 110 virtual unsigned checkTargetMatchPredicate(MCInst &Inst) { 111 return Match_Success; 112 } 113 114 virtual unsigned GetMCInstOperandNum(unsigned Kind, MCInst &Inst, 115 const SmallVectorImpl<MCParsedAsmOperand*> &Operands, 116 unsigned OperandNum, 117 unsigned &NumMCOperands) = 0; 118}; 119 120} // End llvm namespace 121 122#endif 123