LLVM  4.0.0
MCParsedAsmOperand.h
Go to the documentation of this file.
1 //===-- llvm/MC/MCParsedAsmOperand.h - Asm Parser Operand -------*- 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_MCPARSER_MCPARSEDASMOPERAND_H
11 #define LLVM_MC_MCPARSER_MCPARSEDASMOPERAND_H
12 
13 #include <string>
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/SMLoc.h"
16 
17 namespace llvm {
18 class raw_ostream;
19 
20 /// MCParsedAsmOperand - This abstract class represents a source-level assembly
21 /// instruction operand. It should be subclassed by target-specific code. This
22 /// base class is used by target-independent clients and is the interface
23 /// between parsing an asm instruction and recognizing it.
25  /// MCOperandNum - The corresponding MCInst operand number. Only valid when
26  /// parsing MS-style inline assembly.
27  unsigned MCOperandNum;
28 
29  /// Constraint - The constraint on this operand. Only valid when parsing
30  /// MS-style inline assembly.
31  std::string Constraint;
32 
33 protected:
34  // This only seems to need to be movable (by ARMOperand) but ARMOperand has
35  // lots of members and MSVC doesn't support defaulted move ops, so to avoid
36  // that verbosity, just rely on defaulted copy ops. It's only the Constraint
37  // string member that would benefit from movement anyway.
38  MCParsedAsmOperand(const MCParsedAsmOperand &RHS) = default;
40  MCParsedAsmOperand() = default;
41 
42 public:
43  virtual ~MCParsedAsmOperand() {}
44 
45  void setConstraint(StringRef C) { Constraint = C.str(); }
46  StringRef getConstraint() { return Constraint; }
47 
48  void setMCOperandNum (unsigned OpNum) { MCOperandNum = OpNum; }
49  unsigned getMCOperandNum() { return MCOperandNum; }
50 
51  virtual StringRef getSymName() { return StringRef(); }
52  virtual void *getOpDecl() { return nullptr; }
53 
54  /// isToken - Is this a token operand?
55  virtual bool isToken() const = 0;
56  /// isImm - Is this an immediate operand?
57  virtual bool isImm() const = 0;
58  /// isReg - Is this a register operand?
59  virtual bool isReg() const = 0;
60  virtual unsigned getReg() const = 0;
61 
62  /// isMem - Is this a memory operand?
63  virtual bool isMem() const = 0;
64 
65  /// getStartLoc - Get the location of the first token of this operand.
66  virtual SMLoc getStartLoc() const = 0;
67  /// getEndLoc - Get the location of the last token of this operand.
68  virtual SMLoc getEndLoc() const = 0;
69 
70  /// needAddressOf - Do we need to emit code to get the address of the
71  /// variable/label? Only valid when parsing MS-style inline assembly.
72  virtual bool needAddressOf() const { return false; }
73 
74  /// isOffsetOf - Do we need to emit code to get the offset of the variable,
75  /// rather then the value of the variable? Only valid when parsing MS-style
76  /// inline assembly.
77  virtual bool isOffsetOf() const { return false; }
78 
79  /// getOffsetOfLoc - Get the location of the offset operator.
80  virtual SMLoc getOffsetOfLoc() const { return SMLoc(); }
81 
82  /// print - Print a debug representation of the operand to the given stream.
83  virtual void print(raw_ostream &OS) const = 0;
84  /// dump - Print to the debug stream.
85  virtual void dump() const;
86 };
87 
88 //===----------------------------------------------------------------------===//
89 // Debugging Support
90 
92  MO.print(OS);
93  return OS;
94 }
95 
96 } // end namespace llvm.
97 
98 #endif
virtual bool isToken() const =0
isToken - Is this a token operand?
void setConstraint(StringRef C)
virtual void dump() const
dump - Print to the debug stream.
virtual bool isMem() const =0
isMem - Is this a memory operand?
virtual SMLoc getOffsetOfLoc() const
getOffsetOfLoc - Get the location of the offset operator.
virtual StringRef getSymName()
MCParsedAsmOperand - This abstract class represents a source-level assembly instruction operand...
void setMCOperandNum(unsigned OpNum)
virtual bool isOffsetOf() const
isOffsetOf - Do we need to emit code to get the offset of the variable, rather then the value of the ...
virtual unsigned getReg() const =0
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:225
virtual SMLoc getEndLoc() const =0
getEndLoc - Get the location of the last token of this operand.
virtual SMLoc getStartLoc() const =0
getStartLoc - Get the location of the first token of this operand.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
virtual void print(raw_ostream &OS) const =0
print - Print a debug representation of the operand to the given stream.
MCParsedAsmOperand & operator=(const MCParsedAsmOperand &)=default
virtual bool isImm() const =0
isImm - Is this an immediate operand?
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:1726
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
virtual bool needAddressOf() const
needAddressOf - Do we need to emit code to get the address of the variable/label? Only valid when par...
Represents a location in source code.
Definition: SMLoc.h:24
virtual bool isReg() const =0
isReg - Is this a register operand?