1 //===-- llvm/MC/MCInst.h - MCInst class -------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the declaration of the MCInst and MCOperand classes, which
11 // is the basic representation used to represent low-level machine code
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_MC_MCINST_H
17 #define LLVM_MC_MCINST_H
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/Support/DataTypes.h"
21 #include "llvm/Support/DebugLoc.h"
27 /// MCOperand - Instances of this class represent operands of the MCInst class.
28 /// This is a simple discriminated union.
30 enum MachineOperandType {
31 kInvalid, ///< Uninitialized.
32 kRegister, ///< Register operand.
33 kImmediate, ///< Immediate operand.
34 kMBBLabel, ///< Basic block label.
35 kExpr ///< Relocatable immediate operand.
42 const MCExpr *ExprVal;
50 MCOperand() : Kind(kInvalid) {}
51 MCOperand(const MCOperand &RHS) { *this = RHS; }
53 bool isValid() const { return Kind != kInvalid; }
54 bool isReg() const { return Kind == kRegister; }
55 bool isImm() const { return Kind == kImmediate; }
56 bool isMBBLabel() const { return Kind == kMBBLabel; }
57 bool isExpr() const { return Kind == kExpr; }
59 /// getReg - Returns the register number.
60 unsigned getReg() const {
61 assert(isReg() && "This is not a register operand!");
65 /// setReg - Set the register number.
66 void setReg(unsigned Reg) {
67 assert(isReg() && "This is not a register operand!");
71 int64_t getImm() const {
72 assert(isImm() && "This is not an immediate");
75 void setImm(int64_t Val) {
76 assert(isImm() && "This is not an immediate");
80 unsigned getMBBLabelFunction() const {
81 assert(isMBBLabel() && "This is not a machine basic block");
82 return MBBLabel.FunctionNo;
84 unsigned getMBBLabelBlock() const {
85 assert(isMBBLabel() && "This is not a machine basic block");
86 return MBBLabel.BlockNo;
89 const MCExpr *getExpr() const {
90 assert(isExpr() && "This is not an expression");
93 void setExpr(const MCExpr *Val) {
94 assert(isExpr() && "This is not an expression");
98 static MCOperand CreateReg(unsigned Reg) {
104 static MCOperand CreateImm(int64_t Val) {
106 Op.Kind = kImmediate;
110 static MCOperand CreateMBBLabel(unsigned Fn, unsigned MBB) {
113 Op.MBBLabel.FunctionNo = Fn;
114 Op.MBBLabel.BlockNo = MBB;
117 static MCOperand CreateExpr(const MCExpr *Val) {
124 void print(raw_ostream &OS) const;
129 /// MCInst - Instances of this class represent a single low-level machine
133 SmallVector<MCOperand, 8> Operands;
135 MCInst() : Opcode(~0U) {}
137 void setOpcode(unsigned Op) { Opcode = Op; }
139 unsigned getOpcode() const { return Opcode; }
140 DebugLoc getDebugLoc() const { return DebugLoc(); }
142 const MCOperand &getOperand(unsigned i) const { return Operands[i]; }
143 MCOperand &getOperand(unsigned i) { return Operands[i]; }
144 unsigned getNumOperands() const { return Operands.size(); }
146 void addOperand(const MCOperand &Op) {
147 Operands.push_back(Op);
150 void print(raw_ostream &OS) const;
155 } // end namespace llvm