]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - opencl/llvm.git/blob - include/llvm/MC/MCTargetAsmParser.h
[cleanup] Re-sort all the #include lines in LLVM using
[opencl/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 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_MCTARGETASMPARSER_H
11 #define LLVM_MC_MCTARGETASMPARSER_H
13 #include "llvm/MC/MCExpr.h"
14 #include "llvm/MC/MCParser/MCAsmParserExtension.h"
15 #include "llvm/MC/MCTargetOptions.h"
16 #include <memory>
18 namespace llvm {
19 class AsmToken;
20 class MCInst;
21 class MCParsedAsmOperand;
22 class MCStreamer;
23 class SMLoc;
24 class StringRef;
25 template <typename T> class SmallVectorImpl;
27 typedef SmallVectorImpl<std::unique_ptr<MCParsedAsmOperand>> OperandVector;
29 enum AsmRewriteKind {
30   AOK_Delete = 0,     // Rewrite should be ignored.
31   AOK_Align,          // Rewrite align as .align.
32   AOK_DotOperator,    // Rewrite a dot operator expression as an immediate.
33                       // E.g., [eax].foo.bar -> [eax].8
34   AOK_Emit,           // Rewrite _emit as .byte.
35   AOK_Imm,            // Rewrite as $$N.
36   AOK_ImmPrefix,      // Add $$ before a parsed Imm.
37   AOK_Input,          // Rewrite in terms of $N.
38   AOK_Output,         // Rewrite in terms of $N.
39   AOK_SizeDirective,  // Add a sizing directive (e.g., dword ptr).
40   AOK_Label,          // Rewrite local labels.
41   AOK_Skip            // Skip emission (e.g., offset/type operators).
42 };
44 const char AsmRewritePrecedence [] = {
45   0, // AOK_Delete
46   2, // AOK_Align
47   2, // AOK_DotOperator
48   2, // AOK_Emit
49   4, // AOK_Imm
50   4, // AOK_ImmPrefix
51   3, // AOK_Input
52   3, // AOK_Output
53   5, // AOK_SizeDirective
54   1, // AOK_Label
55   2  // AOK_Skip
56 };
58 struct AsmRewrite {
59   AsmRewriteKind Kind;
60   SMLoc Loc;
61   unsigned Len;
62   unsigned Val;
63   StringRef Label;
64 public:
65   AsmRewrite(AsmRewriteKind kind, SMLoc loc, unsigned len = 0, unsigned val = 0)
66     : Kind(kind), Loc(loc), Len(len), Val(val) {}
67   AsmRewrite(AsmRewriteKind kind, SMLoc loc, unsigned len, StringRef label)
68     : Kind(kind), Loc(loc), Len(len), Val(0), Label(label) {}
69 };
71 struct ParseInstructionInfo {
73   SmallVectorImpl<AsmRewrite> *AsmRewrites;
75   ParseInstructionInfo() : AsmRewrites(nullptr) {}
76   ParseInstructionInfo(SmallVectorImpl<AsmRewrite> *rewrites)
77     : AsmRewrites(rewrites) {}
79   ~ParseInstructionInfo() {}
80 };
82 /// MCTargetAsmParser - Generic interface to target specific assembly parsers.
83 class MCTargetAsmParser : public MCAsmParserExtension {
84 public:
85   enum MatchResultTy {
86     Match_InvalidOperand,
87     Match_MissingFeature,
88     Match_MnemonicFail,
89     Match_Success,
90     FIRST_TARGET_MATCH_RESULT_TY
91   };
93 private:
94   MCTargetAsmParser(const MCTargetAsmParser &) LLVM_DELETED_FUNCTION;
95   void operator=(const MCTargetAsmParser &) LLVM_DELETED_FUNCTION;
96 protected: // Can only create subclasses.
97   MCTargetAsmParser();
99   /// AvailableFeatures - The current set of available features.
100   uint64_t AvailableFeatures;
102   /// ParsingInlineAsm - Are we parsing ms-style inline assembly?
103   bool ParsingInlineAsm;
105   /// SemaCallback - The Sema callback implementation.  Must be set when parsing
106   /// ms-style inline assembly.
107   MCAsmParserSemaCallback *SemaCallback;
109   /// Set of options which affects instrumentation of inline assembly.
110   MCTargetOptions MCOptions;
112 public:
113   virtual ~MCTargetAsmParser();
115   uint64_t getAvailableFeatures() const { return AvailableFeatures; }
116   void setAvailableFeatures(uint64_t Value) { AvailableFeatures = Value; }
118   bool isParsingInlineAsm () { return ParsingInlineAsm; }
119   void setParsingInlineAsm (bool Value) { ParsingInlineAsm = Value; }
121   MCTargetOptions getTargetOptions() const { return MCOptions; }
123   void setSemaCallback(MCAsmParserSemaCallback *Callback) {
124     SemaCallback = Callback;
125   }
127   virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
128                              SMLoc &EndLoc) = 0;
130   /// Sets frame register corresponding to the current MachineFunction.
131   virtual void SetFrameRegister(unsigned RegNo) {}
133   /// ParseInstruction - Parse one assembly instruction.
134   ///
135   /// The parser is positioned following the instruction name. The target
136   /// specific instruction parser should parse the entire instruction and
137   /// construct the appropriate MCInst, or emit an error. On success, the entire
138   /// line should be parsed up to and including the end-of-statement token. On
139   /// failure, the parser is not required to read to the end of the line.
140   //
141   /// \param Name - The instruction name.
142   /// \param NameLoc - The source location of the name.
143   /// \param Operands [out] - The list of parsed operands, this returns
144   ///        ownership of them to the caller.
145   /// \return True on failure.
146   virtual bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name,
147                                 SMLoc NameLoc, OperandVector &Operands) = 0;
149   /// ParseDirective - Parse a target specific assembler directive
150   ///
151   /// The parser is positioned following the directive name.  The target
152   /// specific directive parser should parse the entire directive doing or
153   /// recording any target specific work, or return true and do nothing if the
154   /// directive is not target specific. If the directive is specific for
155   /// the target, the entire line is parsed up to and including the
156   /// end-of-statement token and false is returned.
157   ///
158   /// \param DirectiveID - the identifier token of the directive.
159   virtual bool ParseDirective(AsmToken DirectiveID) = 0;
161   /// mnemonicIsValid - This returns true if this is a valid mnemonic and false
162   /// otherwise.
163   virtual bool mnemonicIsValid(StringRef Mnemonic, unsigned VariantID) = 0;
165   /// MatchAndEmitInstruction - Recognize a series of operands of a parsed
166   /// instruction as an actual MCInst and emit it to the specified MCStreamer.
167   /// This returns false on success and returns true on failure to match.
168   ///
169   /// On failure, the target parser is responsible for emitting a diagnostic
170   /// explaining the match failure.
171   virtual bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
172                                        OperandVector &Operands, MCStreamer &Out,
173                                        uint64_t &ErrorInfo,
174                                        bool MatchingInlineAsm) = 0;
176   /// Allows targets to let registers opt out of clobber lists.
177   virtual bool OmitRegisterFromClobberLists(unsigned RegNo) { return false; }
179   /// Allow a target to add special case operand matching for things that
180   /// tblgen doesn't/can't handle effectively. For example, literal
181   /// immediates on ARM. TableGen expects a token operand, but the parser
182   /// will recognize them as immediates.
183   virtual unsigned validateTargetOperandClass(MCParsedAsmOperand &Op,
184                                               unsigned Kind) {
185     return Match_InvalidOperand;
186   }
188   /// checkTargetMatchPredicate - Validate the instruction match against
189   /// any complex target predicates not expressible via match classes.
190   virtual unsigned checkTargetMatchPredicate(MCInst &Inst) {
191     return Match_Success;
192   }
194   virtual void convertToMapAndConstraints(unsigned Kind,
195                                           const OperandVector &Operands) = 0;
197   virtual const MCExpr *applyModifierToExpr(const MCExpr *E,
198                                             MCSymbolRefExpr::VariantKind,
199                                             MCContext &Ctx) {
200     return nullptr;
201   }
203   virtual void onLabelParsed(MCSymbol *Symbol) { };
204 };
206 } // End llvm namespace
208 #endif