MC: Allow modifiers in MCSymbolRefExpr, and eliminate X86MCTargetExpr.
[oota-llvm.git] / include / llvm / MC / MCInst.h
index 8b638d4c743ee7f3fbdd1a06fc32657cea78613e..29b38dd15d119b224e957c30c7511aca7ea9ad5d 100644 (file)
 #ifndef LLVM_MC_MCINST_H
 #define LLVM_MC_MCINST_H
 
-#include "llvm/MC/MCValue.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/DataTypes.h"
-#include "llvm/Support/DebugLoc.h"
+#include "llvm/System/DataTypes.h"
 
 namespace llvm {
+class raw_ostream;
+class MCAsmInfo;
+class MCExpr;
 
 /// MCOperand - Instances of this class represent operands of the MCInst class.
 /// This is a simple discriminated union.
@@ -30,30 +31,23 @@ class MCOperand {
     kInvalid,                 ///< Uninitialized.
     kRegister,                ///< Register operand.
     kImmediate,               ///< Immediate operand.
-    kMBBLabel,                ///< Basic block label.
-    kMCValue                  ///< Relocatable immediate operand.
+    kExpr                     ///< Relocatable immediate operand.
   };
   unsigned char Kind;
   
   union {
     unsigned RegVal;
     int64_t ImmVal;
-    MCValue MCValueVal;
-    struct {
-      unsigned FunctionNo;
-      unsigned BlockNo;
-    } MBBLabel;
+    const MCExpr *ExprVal;
   };
 public:
   
   MCOperand() : Kind(kInvalid) {}
-  MCOperand(const MCOperand &RHS) { *this = RHS; }
 
   bool isValid() const { return Kind != kInvalid; }
   bool isReg() const { return Kind == kRegister; }
   bool isImm() const { return Kind == kImmediate; }
-  bool isMBBLabel() const { return Kind == kMBBLabel; }
-  bool isMCValue() const { return Kind == kMCValue; }
+  bool isExpr() const { return Kind == kExpr; }
   
   /// getReg - Returns the register number.
   unsigned getReg() const {
@@ -76,41 +70,36 @@ public:
     ImmVal = Val;
   }
   
-  unsigned getMBBLabelFunction() const {
-    assert(isMBBLabel() && "Wrong accessor");
-    return MBBLabel.FunctionNo; 
+  const MCExpr *getExpr() const {
+    assert(isExpr() && "This is not an expression");
+    return ExprVal;
   }
-  unsigned getMBBLabelBlock() const {
-    assert(isMBBLabel() && "Wrong accessor");
-    return MBBLabel.BlockNo; 
-  }
-
-  const MCValue &getMCValue() const {
-    assert(isMCValue() && "This is not an MCValue");
-    return MCValueVal;
-  }
-  void setMCValue(const MCValue &Val) {
-    assert(isMCValue() && "This is not an MCValue");
-    MCValueVal = Val;
+  void setExpr(const MCExpr *Val) {
+    assert(isExpr() && "This is not an expression");
+    ExprVal = Val;
   }
   
-  void MakeReg(unsigned Reg) {
-    Kind = kRegister;
-    RegVal = Reg;
-  }
-  void MakeImm(int64_t Val) {
-    Kind = kImmediate;
-    ImmVal = Val;
+  static MCOperand CreateReg(unsigned Reg) {
+    MCOperand Op;
+    Op.Kind = kRegister;
+    Op.RegVal = Reg;
+    return Op;
   }
-  void MakeMBBLabel(unsigned Fn, unsigned MBB) {
-    Kind = kMBBLabel;
-    MBBLabel.FunctionNo = Fn;
-    MBBLabel.BlockNo = MBB;
+  static MCOperand CreateImm(int64_t Val) {
+    MCOperand Op;
+    Op.Kind = kImmediate;
+    Op.ImmVal = Val;
+    return Op;
   }
-  void MakeMCValue(const MCValue &Val) {
-    Kind = kMCValue;
-    MCValueVal = Val;
+  static MCOperand CreateExpr(const MCExpr *Val) {
+    MCOperand Op;
+    Op.Kind = kExpr;
+    Op.ExprVal = Val;
+    return Op;
   }
+
+  void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
+  void dump() const;
 };
 
   
@@ -120,13 +109,12 @@ class MCInst {
   unsigned Opcode;
   SmallVector<MCOperand, 8> Operands;
 public:
-  MCInst() : Opcode(~0U) {}
+  MCInst() : Opcode(0) {}
   
   void setOpcode(unsigned Op) { Opcode = Op; }
   
   unsigned getOpcode() const { return Opcode; }
-  DebugLoc getDebugLoc() const { return DebugLoc(); }
-  
+
   const MCOperand &getOperand(unsigned i) const { return Operands[i]; }
   MCOperand &getOperand(unsigned i) { return Operands[i]; }
   unsigned getNumOperands() const { return Operands.size(); }
@@ -134,6 +122,9 @@ public:
   void addOperand(const MCOperand &Op) {
     Operands.push_back(Op);
   }
+
+  void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
+  void dump() const;
 };