1 //===-- llvm/MC/MCTargetAsmParser.h - Target Assembly Parser ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_TARGETPARSER_H
11 #define LLVM_MC_TARGETPARSER_H
13 #include "llvm/MC/MCParser/MCAsmParserExtension.h"
20 class MCParsedAsmOperand;
22 template <typename T> class SmallVectorImpl;
40 AsmRewrite(AsmRewriteKind kind, SMLoc loc, unsigned len, unsigned val = 0)
41 : Kind(kind), Loc(loc), Len(len), Val(val) {}
44 struct ParseInstructionInfo {
46 SmallVectorImpl<AsmRewrite> *AsmRewrites;
48 ParseInstructionInfo() : AsmRewrites(0) {}
49 ParseInstructionInfo(SmallVectorImpl<AsmRewrite> *rewrites)
50 : AsmRewrites(rewrites) {}
52 ~ParseInstructionInfo() {}
55 /// MCTargetAsmParser - Generic interface to target specific assembly parsers.
56 class MCTargetAsmParser : public MCAsmParserExtension {
63 FIRST_TARGET_MATCH_RESULT_TY
67 MCTargetAsmParser(const MCTargetAsmParser &) LLVM_DELETED_FUNCTION;
68 void operator=(const MCTargetAsmParser &) LLVM_DELETED_FUNCTION;
69 protected: // Can only create subclasses.
72 /// AvailableFeatures - The current set of available features.
73 unsigned AvailableFeatures;
75 /// ParsingInlineAsm - Are we parsing ms-style inline assembly?
76 bool ParsingInlineAsm;
78 /// SemaCallback - The Sema callback implementation. Must be set when parsing
79 /// ms-style inline assembly.
80 MCAsmParserSemaCallback *SemaCallback;
83 virtual ~MCTargetAsmParser();
85 unsigned getAvailableFeatures() const { return AvailableFeatures; }
86 void setAvailableFeatures(unsigned Value) { AvailableFeatures = Value; }
88 bool isParsingInlineAsm () { return ParsingInlineAsm; }
89 void setParsingInlineAsm (bool Value) { ParsingInlineAsm = Value; }
91 void setSemaCallback(MCAsmParserSemaCallback *Callback) {
92 SemaCallback = Callback;
95 virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
98 /// ParseInstruction - Parse one assembly instruction.
100 /// The parser is positioned following the instruction name. The target
101 /// specific instruction parser should parse the entire instruction and
102 /// construct the appropriate MCInst, or emit an error. On success, the entire
103 /// line should be parsed up to and including the end-of-statement token. On
104 /// failure, the parser is not required to read to the end of the line.
106 /// \param Name - The instruction name.
107 /// \param NameLoc - The source location of the name.
108 /// \param Operands [out] - The list of parsed operands, this returns
109 /// ownership of them to the caller.
110 /// \return True on failure.
111 virtual bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
113 SmallVectorImpl<MCParsedAsmOperand*> &Operands) = 0;
115 /// ParseDirective - Parse a target specific assembler directive
117 /// The parser is positioned following the directive name. The target
118 /// specific directive parser should parse the entire directive doing or
119 /// recording any target specific work, or return true and do nothing if the
120 /// directive is not target specific. If the directive is specific for
121 /// the target, the entire line is parsed up to and including the
122 /// end-of-statement token and false is returned.
124 /// \param DirectiveID - the identifier token of the directive.
125 virtual bool ParseDirective(AsmToken DirectiveID) = 0;
127 /// mnemonicIsValid - This returns true if this is a valid mnemonic and false
129 virtual bool mnemonicIsValid(StringRef Mnemonic) = 0;
131 /// MatchAndEmitInstruction - Recognize a series of operands of a parsed
132 /// instruction as an actual MCInst and emit it to the specified MCStreamer.
133 /// This returns false on success and returns true on failure to match.
135 /// On failure, the target parser is responsible for emitting a diagnostic
136 /// explaining the match failure.
138 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
139 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
140 MCStreamer &Out, unsigned &ErrorInfo,
141 bool MatchingInlineAsm) = 0;
143 /// checkTargetMatchPredicate - Validate the instruction match against
144 /// any complex target predicates not expressible via match classes.
145 virtual unsigned checkTargetMatchPredicate(MCInst &Inst) {
146 return Match_Success;
149 virtual void convertToMapAndConstraints(unsigned Kind,
150 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) = 0;
153 } // End llvm namespace