MCParsedAsmOperand.h revision b976e407dcd7794eb9e151b81cdc8fbbe05e6bd8
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
13namespace llvm {
14class SMLoc;
15class raw_ostream;
16
17/// MCParsedAsmOperand - This abstract class represents a source-level assembly
18/// instruction operand.  It should be subclassed by target-specific code.  This
19/// base class is used by target-independent clients and is the interface
20/// between parsing an asm instruction and recognizing it.
21class MCParsedAsmOperand {
22  /// MCOperandNum - The corresponding MCInst operand number.  Only valid when
23  /// parsing MS-style inline assembly.
24  unsigned MCOperandNum;
25
26  /// Constraint - The constraint on this operand.  Only valid when parsing
27  /// MS-style inline assembly.
28  std::string Constraint;
29
30public:
31  MCParsedAsmOperand() {}
32  virtual ~MCParsedAsmOperand() {}
33
34  void setConstraint(StringRef C) { Constraint = C.str(); }
35  StringRef getConstraint() { return Constraint; }
36
37  void setMCOperandNum (unsigned OpNum) { MCOperandNum = OpNum; }
38  unsigned getMCOperandNum() { return MCOperandNum; }
39
40  virtual StringRef getSymName() { return StringRef(); }
41
42  /// isToken - Is this a token operand?
43  virtual bool isToken() const = 0;
44  /// isImm - Is this an immediate operand?
45  virtual bool isImm() const = 0;
46  /// isReg - Is this a register operand?
47  virtual bool isReg() const = 0;
48  virtual unsigned getReg() const = 0;
49
50  /// isMem - Is this a memory operand?
51  virtual bool isMem() const = 0;
52
53  /// getStartLoc - Get the location of the first token of this operand.
54  virtual SMLoc getStartLoc() const = 0;
55  /// getEndLoc - Get the location of the last token of this operand.
56  virtual SMLoc getEndLoc() const = 0;
57
58  /// needAddressOf - Do we need to emit code to get the address of the
59  /// variable/label?   Only valid when parsing MS-style inline assembly.
60  virtual bool needAddressOf() const { return false; }
61
62  /// isOffsetOf - Do we need to emit code to get the offset of the variable,
63  /// rather then the value of the variable?   Only valid when parsing MS-style
64  /// inline assembly.
65  virtual bool isOffsetOf() const { return false; }
66
67  /// getOffsetOfLoc - Get the location of the offset operator.
68  virtual SMLoc getOffsetOfLoc() const { return SMLoc(); }
69
70  /// print - Print a debug representation of the operand to the given stream.
71  virtual void print(raw_ostream &OS) const = 0;
72  /// dump - Print to the debug stream.
73  virtual void dump() const;
74};
75
76//===----------------------------------------------------------------------===//
77// Debugging Support
78
79inline raw_ostream& operator<<(raw_ostream &OS, const MCParsedAsmOperand &MO) {
80  MO.print(OS);
81  return OS;
82}
83
84} // end namespace llvm.
85
86#endif
87