LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCTargetAsmParser.h
Go to the documentation of this file.
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 
14 #include "llvm/MC/MCExpr.h"
15 
16 namespace llvm {
17 class MCStreamer;
18 class StringRef;
19 class SMLoc;
20 class AsmToken;
21 class MCParsedAsmOperand;
22 class MCInst;
23 template <typename T> class SmallVectorImpl;
24 
26  AOK_Delete = 0, // Rewrite should be ignored.
27  AOK_Align, // Rewrite align as .align.
28  AOK_DotOperator, // Rewrite a dot operator expression as an immediate.
29  // E.g., [eax].foo.bar -> [eax].8
30  AOK_Emit, // Rewrite _emit as .byte.
31  AOK_Imm, // Rewrite as $$N.
32  AOK_ImmPrefix, // Add $$ before a parsed Imm.
33  AOK_Input, // Rewrite in terms of $N.
34  AOK_Output, // Rewrite in terms of $N.
35  AOK_SizeDirective, // Add a sizing directive (e.g., dword ptr).
36  AOK_Skip // Skip emission (e.g., offset/type operators).
37 };
38 
39 const char AsmRewritePrecedence [] = {
40  0, // AOK_Delete
41  1, // AOK_Align
42  1, // AOK_DotOperator
43  1, // AOK_Emit
44  3, // AOK_Imm
45  3, // AOK_ImmPrefix
46  2, // AOK_Input
47  2, // AOK_Output
48  4, // AOK_SizeDirective
49  1 // AOK_Skip
50 };
51 
52 struct AsmRewrite {
55  unsigned Len;
56  unsigned Val;
57 public:
58  AsmRewrite(AsmRewriteKind kind, SMLoc loc, unsigned len = 0, unsigned val = 0)
59  : Kind(kind), Loc(loc), Len(len), Val(val) {}
60 };
61 
63 
65 
68  : AsmRewrites(rewrites) {}
69 
71 };
72 
73 /// MCTargetAsmParser - Generic interface to target specific assembly parsers.
75 public:
82  };
83 
84 private:
86  void operator=(const MCTargetAsmParser &) LLVM_DELETED_FUNCTION;
87 protected: // Can only create subclasses.
89 
90  /// AvailableFeatures - The current set of available features.
92 
93  /// ParsingInlineAsm - Are we parsing ms-style inline assembly?
95 
96  /// SemaCallback - The Sema callback implementation. Must be set when parsing
97  /// ms-style inline assembly.
99 
100 public:
101  virtual ~MCTargetAsmParser();
102 
103  unsigned getAvailableFeatures() const { return AvailableFeatures; }
104  void setAvailableFeatures(unsigned Value) { AvailableFeatures = Value; }
105 
107  void setParsingInlineAsm (bool Value) { ParsingInlineAsm = Value; }
108 
110  SemaCallback = Callback;
111  }
112 
113  virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc,
114  SMLoc &EndLoc) = 0;
115 
116  /// ParseInstruction - Parse one assembly instruction.
117  ///
118  /// The parser is positioned following the instruction name. The target
119  /// specific instruction parser should parse the entire instruction and
120  /// construct the appropriate MCInst, or emit an error. On success, the entire
121  /// line should be parsed up to and including the end-of-statement token. On
122  /// failure, the parser is not required to read to the end of the line.
123  //
124  /// \param Name - The instruction name.
125  /// \param NameLoc - The source location of the name.
126  /// \param Operands [out] - The list of parsed operands, this returns
127  /// ownership of them to the caller.
128  /// \return True on failure.
130  SMLoc NameLoc,
132 
133  /// ParseDirective - Parse a target specific assembler directive
134  ///
135  /// The parser is positioned following the directive name. The target
136  /// specific directive parser should parse the entire directive doing or
137  /// recording any target specific work, or return true and do nothing if the
138  /// directive is not target specific. If the directive is specific for
139  /// the target, the entire line is parsed up to and including the
140  /// end-of-statement token and false is returned.
141  ///
142  /// \param DirectiveID - the identifier token of the directive.
143  virtual bool ParseDirective(AsmToken DirectiveID) = 0;
144 
145  /// mnemonicIsValid - This returns true if this is a valid mnemonic and false
146  /// otherwise.
147  virtual bool mnemonicIsValid(StringRef Mnemonic, unsigned VariantID) = 0;
148 
149  /// MatchAndEmitInstruction - Recognize a series of operands of a parsed
150  /// instruction as an actual MCInst and emit it to the specified MCStreamer.
151  /// This returns false on success and returns true on failure to match.
152  ///
153  /// On failure, the target parser is responsible for emitting a diagnostic
154  /// explaining the match failure.
155  virtual bool
156  MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
158  MCStreamer &Out, unsigned &ErrorInfo,
159  bool MatchingInlineAsm) = 0;
160 
161  /// Allow a target to add special case operand matching for things that
162  /// tblgen doesn't/can't handle effectively. For example, literal
163  /// immediates on ARM. TableGen expects a token operand, but the parser
164  /// will recognize them as immediates.
166  unsigned Kind) {
167  return Match_InvalidOperand;
168  }
169 
170  /// checkTargetMatchPredicate - Validate the instruction match against
171  /// any complex target predicates not expressible via match classes.
172  virtual unsigned checkTargetMatchPredicate(MCInst &Inst) {
173  return Match_Success;
174  }
175 
176  virtual void convertToMapAndConstraints(unsigned Kind,
177  const SmallVectorImpl<MCParsedAsmOperand*> &Operands) = 0;
178 
179  virtual const MCExpr *applyModifierToExpr(const MCExpr *E,
181  MCContext &Ctx) {
182  return 0;
183  }
184 
185  virtual void onLabelParsed(MCSymbol *Symbol) { };
186 };
187 
188 } // End llvm namespace
189 
190 #endif
virtual void convertToMapAndConstraints(unsigned Kind, const SmallVectorImpl< MCParsedAsmOperand * > &Operands)=0
MCAsmParserSemaCallback * SemaCallback
SmallVectorImpl< AsmRewrite > * AsmRewrites
MCTargetAsmParser - Generic interface to target specific assembly parsers.
virtual bool MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode, SmallVectorImpl< MCParsedAsmOperand * > &Operands, MCStreamer &Out, unsigned &ErrorInfo, bool MatchingInlineAsm)=0
ParseInstructionInfo(SmallVectorImpl< AsmRewrite > *rewrites)
virtual void onLabelParsed(MCSymbol *Symbol)
unsigned AvailableFeatures
AvailableFeatures - The current set of available features.
virtual bool ParseRegister(unsigned &RegNo, SMLoc &StartLoc, SMLoc &EndLoc)=0
AsmToken - Target independent representation for an assembler token.
Definition: MCAsmLexer.h:21
void setAvailableFeatures(unsigned Value)
void setSemaCallback(MCAsmParserSemaCallback *Callback)
virtual bool ParseInstruction(ParseInstructionInfo &Info, StringRef Name, SMLoc NameLoc, SmallVectorImpl< MCParsedAsmOperand * > &Operands)=0
virtual unsigned checkTargetMatchPredicate(MCInst &Inst)
virtual bool mnemonicIsValid(StringRef Mnemonic, unsigned VariantID)=0
void setParsingInlineAsm(bool Value)
MCAsmParserSemaCallback - Generic Sema callback for assembly parser.
Definition: MCAsmParser.h:34
unsigned getAvailableFeatures() const
#define LLVM_DELETED_FUNCTION
Definition: Compiler.h:137
AsmRewrite(AsmRewriteKind kind, SMLoc loc, unsigned len=0, unsigned val=0)
bool ParsingInlineAsm
ParsingInlineAsm - Are we parsing ms-style inline assembly?
virtual bool ParseDirective(AsmToken DirectiveID)=0
virtual unsigned validateTargetOperandClass(MCParsedAsmOperand *Op, unsigned Kind)
virtual const MCExpr * applyModifierToExpr(const MCExpr *E, MCSymbolRefExpr::VariantKind, MCContext &Ctx)
Generic interface for extending the MCAsmParser, which is implemented by target and object file assem...
const char AsmRewritePrecedence[]
LLVM Value Representation.
Definition: Value.h:66
AsmRewriteKind Kind
Represents a location in source code.
Definition: SMLoc.h:23