a25108a0effb01c040eabdfb485e4b6b51a1b053
[oota-llvm.git] / include / llvm / MC / MCParser / MCParsedAsmOperand.h
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.
24 class MCParsedAsmOperand {
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 public:
34   MCParsedAsmOperand() {}
35   virtual ~MCParsedAsmOperand() {}
36
37   void setConstraint(StringRef C) { Constraint = C.str(); }
38   StringRef getConstraint() { return Constraint; }
39
40   void setMCOperandNum (unsigned OpNum) { MCOperandNum = OpNum; }
41   unsigned getMCOperandNum() { return MCOperandNum; }
42
43   virtual StringRef getSymName() { return StringRef(); }
44   virtual void *getOpDecl() { return nullptr; }
45
46   /// isToken - Is this a token operand?
47   virtual bool isToken() const = 0;
48   /// isImm - Is this an immediate operand?
49   virtual bool isImm() const = 0;
50   /// isReg - Is this a register operand?
51   virtual bool isReg() const = 0;
52   virtual unsigned getReg() const = 0;
53
54   /// isMem - Is this a memory operand?
55   virtual bool isMem() const = 0;
56
57   /// getStartLoc - Get the location of the first token of this operand.
58   virtual SMLoc getStartLoc() const = 0;
59   /// getEndLoc - Get the location of the last token of this operand.
60   virtual SMLoc getEndLoc() const = 0;
61
62   /// needAddressOf - Do we need to emit code to get the address of the
63   /// variable/label?   Only valid when parsing MS-style inline assembly.
64   virtual bool needAddressOf() const { return false; }
65
66   /// isOffsetOf - Do we need to emit code to get the offset of the variable,
67   /// rather then the value of the variable?   Only valid when parsing MS-style
68   /// inline assembly.
69   virtual bool isOffsetOf() const { return false; }
70
71   /// getOffsetOfLoc - Get the location of the offset operator.
72   virtual SMLoc getOffsetOfLoc() const { return SMLoc(); }
73
74   /// print - Print a debug representation of the operand to the given stream.
75   virtual void print(raw_ostream &OS) const = 0;
76   /// dump - Print to the debug stream.
77   virtual void dump() const;
78 };
79
80 //===----------------------------------------------------------------------===//
81 // Debugging Support
82
83 inline raw_ostream& operator<<(raw_ostream &OS, const MCParsedAsmOperand &MO) {
84   MO.print(OS);
85   return OS;
86 }
87
88 } // end namespace llvm.
89
90 #endif