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;
48 virtual ~MCTargetAsmParser();
50 unsigned getAvailableFeatures() const { return AvailableFeatures; }
51 void setAvailableFeatures(unsigned Value) { AvailableFeatures = Value; }
53 bool isParsingInlineAsm () { return ParsingInlineAsm; }
54 void setParsingInlineAsm (bool Value) { ParsingInlineAsm = Value; }
56 virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
59 /// ParseInstruction - Parse one assembly instruction.
61 /// The parser is positioned following the instruction name. The target
62 /// specific instruction parser should parse the entire instruction and
63 /// construct the appropriate MCInst, or emit an error. On success, the entire
64 /// line should be parsed up to and including the end-of-statement token. On
65 /// failure, the parser is not required to read to the end of the line.
67 /// \param Name - The instruction name.
68 /// \param NameLoc - The source location of the name.
69 /// \param Operands [out] - The list of parsed operands, this returns
70 /// ownership of them to the caller.
71 /// \return True on failure.
72 virtual bool ParseInstruction(StringRef Name, SMLoc NameLoc,
73 SmallVectorImpl<MCParsedAsmOperand*> &Operands) = 0;
75 /// ParseDirective - Parse a target specific assembler directive
77 /// The parser is positioned following the directive name. The target
78 /// specific directive parser should parse the entire directive doing or
79 /// recording any target specific work, or return true and do nothing if the
80 /// directive is not target specific. If the directive is specific for
81 /// the target, the entire line is parsed up to and including the
82 /// end-of-statement token and false is returned.
84 /// \param DirectiveID - the identifier token of the directive.
85 virtual bool ParseDirective(AsmToken DirectiveID) = 0;
87 /// mnemonicIsValid - This returns true if this is a valid mnemonic and false
89 virtual bool mnemonicIsValid(StringRef Mnemonic) = 0;
91 /// MatchAndEmitInstruction - Recognize a series of operands of a parsed
92 /// instruction as an actual MCInst and emit it to the specified MCStreamer.
93 /// This returns false on success and returns true on failure to match.
95 /// On failure, the target parser is responsible for emitting a diagnostic
96 /// explaining the match failure.
98 MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
99 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
100 MCStreamer &Out, unsigned &ErrorInfo,
101 bool MatchingInlineAsm) = 0;
103 /// checkTargetMatchPredicate - Validate the instruction match against
104 /// any complex target predicates not expressible via match classes.
105 virtual unsigned checkTargetMatchPredicate(MCInst &Inst) {
106 return Match_Success;
109 virtual void convertToMapAndConstraints(unsigned Kind,
110 const SmallVectorImpl<MCParsedAsmOperand*> &Operands) = 0;
113 } // End llvm namespace