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;
24 /// MCTargetAsmParser - Generic interface to target specific assembly parsers.
25 class MCTargetAsmParser : public MCAsmParserExtension {
32 FIRST_TARGET_MATCH_RESULT_TY
36 MCTargetAsmParser(const MCTargetAsmParser &) LLVM_DELETED_FUNCTION;
37 void operator=(const MCTargetAsmParser &) LLVM_DELETED_FUNCTION;
38 protected: // Can only create subclasses.
41 /// AvailableFeatures - The current set of available features.
42 unsigned AvailableFeatures;
44 /// ParsingInlineAsm - Are we parsing ms-style inline assembly?
45 bool ParsingInlineAsm;
47 /// SemaCallback - The Sema callback implementation. Must be set when parsing
48 /// ms-style inline assembly.
49 MCAsmParserSemaCallback *SemaCallback;
52 virtual ~MCTargetAsmParser();
54 unsigned getAvailableFeatures() const { return AvailableFeatures; }
55 void setAvailableFeatures(unsigned Value) { AvailableFeatures = Value; }
57 bool isParsingInlineAsm () { return ParsingInlineAsm; }
58 void setParsingInlineAsm (bool Value) { ParsingInlineAsm = Value; }
60 void setSemaCallback(MCAsmParserSemaCallback *Callback) {
61 SemaCallback = Callback;
64 virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
67 /// ParseInstruction - Parse one assembly instruction.
69 /// The parser is positioned following the instruction name. The target
70 /// specific instruction parser should parse the entire instruction and
71 /// construct the appropriate MCInst, or emit an error. On success, the entire
72 /// line should be parsed up to and including the end-of-statement token. On
73 /// failure, the parser is not required to read to the end of the line.
75 /// \param Name - The instruction name.
76 /// \param NameLoc - The source location of the name.
77 /// \param Operands [out] - The list of parsed operands, this returns
78 /// ownership of them to the caller.
79 /// \return True on failure.
80 virtual bool ParseInstruction(StringRef Name, SMLoc NameLoc,
81 SmallVectorImpl<MCParsedAsmOperand*> &Operands) = 0;
83 /// ParseDirective - Parse a target specific assembler directive
85 /// The parser is positioned following the directive name. The target
86 /// specific directive parser should parse the entire directive doing or
87 /// recording any target specific work, or return true and do nothing if the
88 /// directive is not target specific. If the directive is specific for
89 /// the target, the entire line is parsed up to and including the
90 /// end-of-statement token and false is returned.
92 /// \param DirectiveID - the identifier token of the directive.
93 virtual bool ParseDirective(AsmToken DirectiveID) = 0;
95 /// mnemonicIsValid - This returns true if this is a valid mnemonic and false
97 virtual bool mnemonicIsValid(StringRef Mnemonic) = 0;
99 /// MatchAndEmitInstruction - Recognize a series of operands of a parsed
100 /// instruction as an actual MCInst and emit it to the specified MCStreamer.
101 /// This returns false on success and returns true on failure to match.
103 /// On failure, the target parser is responsible for emitting a diagnostic
104 /// explaining the match failure.
106 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
107 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
108 MCStreamer &Out, unsigned &ErrorInfo,
109 bool MatchingInlineAsm) = 0;
111 /// checkTargetMatchPredicate - Validate the instruction match against
112 /// any complex target predicates not expressible via match classes.
113 virtual unsigned checkTargetMatchPredicate(MCInst &Inst) {
114 return Match_Success;
117 virtual void convertToMapAndConstraints(unsigned Kind,
118 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) = 0;
121 } // End llvm namespace