[ms-inline asm] Add a comment describing the MapAndConstraints.
[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   /// MapAndConstraints - Map inline assembly operands to MCInst operands
54   /// and an associated constraint.
55   typedef std::pair< unsigned, std::string > MapAndConstraint;
56   typedef SmallVector<MapAndConstraint, 4> MatchInstMapAndConstraints;
57   typedef SmallVectorImpl<MapAndConstraint> MatchInstMapAndConstraintsImpl;
58
59   /// ParseInstruction - Parse one assembly instruction.
60   ///
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.
66   //
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;
74
75   /// ParseDirective - Parse a target specific assembler directive
76   ///
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.
83   ///
84   /// \param DirectiveID - the identifier token of the directive.
85   virtual bool ParseDirective(AsmToken DirectiveID) = 0;
86
87   /// mnemonicIsValid - This returns true if this is a valid mnemonic and false
88   /// otherwise.
89   virtual bool mnemonicIsValid(StringRef Mnemonic) = 0;
90
91   /// MatchInstruction - Recognize a series of operands of a parsed instruction
92   /// as an actual MCInst.  This returns false on success and returns true on
93   /// failure to match.
94   ///
95   /// On failure, the target parser is responsible for emitting a diagnostic
96   /// explaining the match failure.
97   virtual bool
98   MatchInstruction(SMLoc IDLoc, 
99                    SmallVectorImpl<MCParsedAsmOperand*> &Operands,
100                    MCStreamer &Out, unsigned &Kind, unsigned &Opcode,
101                    MatchInstMapAndConstraintsImpl &MapAndConstraints,
102                    unsigned &OrigErrorInfo, bool matchingInlineAsm = false) {
103     OrigErrorInfo = ~0x0;
104     return true;
105   }
106
107   /// MatchAndEmitInstruction - Recognize a series of operands of a parsed
108   /// instruction as an actual MCInst and emit it to the specified MCStreamer.
109   /// This returns false on success and returns true on failure to match.
110   ///
111   /// On failure, the target parser is responsible for emitting a diagnostic
112   /// explaining the match failure.
113   virtual bool
114   MatchAndEmitInstruction(SMLoc IDLoc,
115                           SmallVectorImpl<MCParsedAsmOperand*> &Operands,
116                           MCStreamer &Out) = 0;
117
118   /// checkTargetMatchPredicate - Validate the instruction match against
119   /// any complex target predicates not expressible via match classes.
120   virtual unsigned checkTargetMatchPredicate(MCInst &Inst) {
121     return Match_Success;
122   }
123
124   virtual void convertToMapAndConstraints(unsigned Kind,
125                            const SmallVectorImpl<MCParsedAsmOperand*> &Operands,
126                          MatchInstMapAndConstraintsImpl &MapAndConstraints) = 0;
127 };
128
129 } // End llvm namespace
130
131 #endif