Fix anonymous namespace issue introduced by r166714:
[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 enum AsmRewriteKind {
25    AOK_Imm,
26    AOK_Input,
27    AOK_Output,
28    AOK_SizeDirective,
29    AOK_Emit,
30    AOK_Skip,
31    AOK_DotOperator
32 };
33
34 struct AsmRewrite {
35   AsmRewriteKind Kind;
36   SMLoc Loc;
37   unsigned Len;
38   unsigned Val;
39 public:
40   AsmRewrite(AsmRewriteKind kind, SMLoc loc, unsigned len, unsigned val = 0)
41     : Kind(kind), Loc(loc), Len(len), Val(val) {}
42 };
43
44 struct ParseInstructionInfo {
45
46   SmallVectorImpl<AsmRewrite> *AsmRewrites;
47
48   ParseInstructionInfo() : AsmRewrites(0) {}
49   ParseInstructionInfo(SmallVectorImpl<AsmRewrite> *rewrites)
50     : AsmRewrites(rewrites) {}
51
52   ~ParseInstructionInfo() {}
53 };
54
55 /// MCTargetAsmParser - Generic interface to target specific assembly parsers.
56 class MCTargetAsmParser : public MCAsmParserExtension {
57 public:
58   enum MatchResultTy {
59     Match_InvalidOperand,
60     Match_MissingFeature,
61     Match_MnemonicFail,
62     Match_Success,
63     FIRST_TARGET_MATCH_RESULT_TY
64   };
65
66 private:
67   MCTargetAsmParser(const MCTargetAsmParser &) LLVM_DELETED_FUNCTION;
68   void operator=(const MCTargetAsmParser &) LLVM_DELETED_FUNCTION;
69 protected: // Can only create subclasses.
70   MCTargetAsmParser();
71
72   /// AvailableFeatures - The current set of available features.
73   unsigned AvailableFeatures;
74
75   /// ParsingInlineAsm - Are we parsing ms-style inline assembly?
76   bool ParsingInlineAsm;
77
78   /// SemaCallback - The Sema callback implementation.  Must be set when parsing
79   /// ms-style inline assembly.
80   MCAsmParserSemaCallback *SemaCallback;
81
82 public:
83   virtual ~MCTargetAsmParser();
84
85   unsigned getAvailableFeatures() const { return AvailableFeatures; }
86   void setAvailableFeatures(unsigned Value) { AvailableFeatures = Value; }
87
88   bool isParsingInlineAsm () { return ParsingInlineAsm; }
89   void setParsingInlineAsm (bool Value) { ParsingInlineAsm = Value; }
90
91   void setSemaCallback(MCAsmParserSemaCallback *Callback) {
92     SemaCallback = Callback;
93   }
94
95   virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
96                              SMLoc &EndLoc) = 0;
97
98   /// ParseInstruction - Parse one assembly instruction.
99   ///
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.
105   //
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,
112                                 SMLoc NameLoc,
113                             SmallVectorImpl<MCParsedAsmOperand*> &Operands) = 0;
114
115   /// ParseDirective - Parse a target specific assembler directive
116   ///
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.
123   ///
124   /// \param DirectiveID - the identifier token of the directive.
125   virtual bool ParseDirective(AsmToken DirectiveID) = 0;
126
127   /// mnemonicIsValid - This returns true if this is a valid mnemonic and false
128   /// otherwise.
129   virtual bool mnemonicIsValid(StringRef Mnemonic) = 0;
130
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.
134   ///
135   /// On failure, the target parser is responsible for emitting a diagnostic
136   /// explaining the match failure.
137   virtual bool
138   MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
139                           SmallVectorImpl<MCParsedAsmOperand*> &Operands,
140                           MCStreamer &Out, unsigned &ErrorInfo,
141                           bool MatchingInlineAsm) = 0;
142
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;
147   }
148
149   virtual void convertToMapAndConstraints(unsigned Kind,
150                       const SmallVectorImpl<MCParsedAsmOperand*> &Operands) = 0;
151 };
152
153 } // End llvm namespace
154
155 #endif