Rather then have a wrapper function, have tblgen instantiate the implementation.
[oota-llvm.git] / include / llvm / MC / MCTargetAsmParser.h
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
15 namespace llvm {
16 class MCStreamer;
17 class StringRef;
18 class SMLoc;
19 class AsmToken;
20 class MCParsedAsmOperand;
21 class MCInst;
22 template <typename T> class SmallVectorImpl;
23
24 /// MCTargetAsmParser - Generic interface to target specific assembly parsers.
25 class MCTargetAsmParser : public MCAsmParserExtension {
26 public:
27   enum MatchResultTy {
28     Match_InvalidOperand,
29     Match_MissingFeature,
30     Match_MnemonicFail,
31     Match_Success,
32     FIRST_TARGET_MATCH_RESULT_TY
33   };
34
35 private:
36   MCTargetAsmParser(const MCTargetAsmParser &) LLVM_DELETED_FUNCTION;
37   void operator=(const MCTargetAsmParser &) LLVM_DELETED_FUNCTION;
38 protected: // Can only create subclasses.
39   MCTargetAsmParser();
40
41   /// AvailableFeatures - The current set of available features.
42   unsigned AvailableFeatures;
43
44 public:
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   /// mnemonicIsValid - This returns true if this is a valid mnemonic and false
82   /// otherwise.
83   virtual bool mnemonicIsValid(StringRef Mnemonic) = 0;
84
85   /// MatchInstruction - Recognize a series of operands of a parsed instruction
86   /// as an actual MCInst.  This returns false on success and returns true on
87   /// failure to match.
88   ///
89   /// On failure, the target parser is responsible for emitting a diagnostic
90   /// explaining the match failure.
91   virtual bool
92   MatchInstruction(SMLoc IDLoc, unsigned &Kind,
93                    SmallVectorImpl<MCParsedAsmOperand*> &Operands,
94                    SmallVectorImpl<MCInst> &MCInsts,
95                    unsigned &OrigErrorInfo,
96                    bool matchingInlineAsm = false) {
97     OrigErrorInfo = ~0x0;
98     return true;
99   }
100
101   /// MatchAndEmitInstruction - Recognize a series of operands of a parsed
102   /// instruction as an actual MCInst and emit it to the specified MCStreamer.
103   /// This returns false on success and returns true on failure to match.
104   ///
105   /// On failure, the target parser is responsible for emitting a diagnostic
106   /// explaining the match failure.
107   virtual bool
108   MatchAndEmitInstruction(SMLoc IDLoc,
109                           SmallVectorImpl<MCParsedAsmOperand*> &Operands,
110                           MCStreamer &Out) = 0;
111
112   /// checkTargetMatchPredicate - Validate the instruction match against
113   /// any complex target predicates not expressible via match classes.
114   virtual unsigned checkTargetMatchPredicate(MCInst &Inst) {
115     return Match_Success;
116   }
117
118   virtual unsigned getMCInstOperandNum(unsigned Kind,
119                            const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
120                                        unsigned OperandNum,
121                                        unsigned &NumMCOperands) = 0;
122 };
123
124 } // End llvm namespace
125
126 #endif