2009-06-19 00:47:33 +00:00
|
|
|
//===-- llvm/MC/MCInst.h - MCInst class -------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the declaration of the MCInst and MCOperand classes, which
|
|
|
|
// is the basic representation used to represent low-level machine code
|
|
|
|
// instructions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_MC_MCINST_H
|
|
|
|
#define LLVM_MC_MCINST_H
|
|
|
|
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2009-06-19 01:56:53 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2009-06-19 00:47:33 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2009-08-27 07:57:12 +00:00
|
|
|
class raw_ostream;
|
2009-09-03 05:46:51 +00:00
|
|
|
class MCAsmInfo;
|
2009-08-31 08:08:38 +00:00
|
|
|
class MCExpr;
|
2009-06-19 00:47:33 +00:00
|
|
|
|
|
|
|
/// MCOperand - Instances of this class represent operands of the MCInst class.
|
|
|
|
/// This is a simple discriminated union.
|
|
|
|
class MCOperand {
|
|
|
|
enum MachineOperandType {
|
|
|
|
kInvalid, ///< Uninitialized.
|
|
|
|
kRegister, ///< Register operand.
|
2009-06-20 07:03:18 +00:00
|
|
|
kImmediate, ///< Immediate operand.
|
2009-08-31 08:08:38 +00:00
|
|
|
kExpr ///< Relocatable immediate operand.
|
2009-06-19 00:47:33 +00:00
|
|
|
};
|
|
|
|
unsigned char Kind;
|
|
|
|
|
|
|
|
union {
|
|
|
|
unsigned RegVal;
|
2009-06-20 00:47:37 +00:00
|
|
|
int64_t ImmVal;
|
2009-08-31 08:08:38 +00:00
|
|
|
const MCExpr *ExprVal;
|
2009-06-19 00:47:33 +00:00
|
|
|
};
|
|
|
|
public:
|
|
|
|
|
|
|
|
MCOperand() : Kind(kInvalid) {}
|
|
|
|
MCOperand(const MCOperand &RHS) { *this = RHS; }
|
|
|
|
|
2009-06-30 23:37:44 +00:00
|
|
|
bool isValid() const { return Kind != kInvalid; }
|
2009-06-19 00:47:33 +00:00
|
|
|
bool isReg() const { return Kind == kRegister; }
|
|
|
|
bool isImm() const { return Kind == kImmediate; }
|
2009-08-31 08:08:38 +00:00
|
|
|
bool isExpr() const { return Kind == kExpr; }
|
2009-06-19 00:47:33 +00:00
|
|
|
|
|
|
|
/// getReg - Returns the register number.
|
|
|
|
unsigned getReg() const {
|
|
|
|
assert(isReg() && "This is not a register operand!");
|
|
|
|
return RegVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// setReg - Set the register number.
|
|
|
|
void setReg(unsigned Reg) {
|
|
|
|
assert(isReg() && "This is not a register operand!");
|
|
|
|
RegVal = Reg;
|
|
|
|
}
|
|
|
|
|
2009-06-20 00:47:37 +00:00
|
|
|
int64_t getImm() const {
|
2009-06-19 00:47:33 +00:00
|
|
|
assert(isImm() && "This is not an immediate");
|
|
|
|
return ImmVal;
|
|
|
|
}
|
2009-06-20 00:47:37 +00:00
|
|
|
void setImm(int64_t Val) {
|
2009-06-19 00:47:33 +00:00
|
|
|
assert(isImm() && "This is not an immediate");
|
|
|
|
ImmVal = Val;
|
|
|
|
}
|
|
|
|
|
2009-08-31 08:08:38 +00:00
|
|
|
const MCExpr *getExpr() const {
|
|
|
|
assert(isExpr() && "This is not an expression");
|
|
|
|
return ExprVal;
|
2009-06-30 23:37:44 +00:00
|
|
|
}
|
2009-08-31 08:08:38 +00:00
|
|
|
void setExpr(const MCExpr *Val) {
|
|
|
|
assert(isExpr() && "This is not an expression");
|
|
|
|
ExprVal = Val;
|
2009-06-30 23:37:44 +00:00
|
|
|
}
|
2009-06-20 07:03:18 +00:00
|
|
|
|
2009-08-02 00:09:22 +00:00
|
|
|
static MCOperand CreateReg(unsigned Reg) {
|
|
|
|
MCOperand Op;
|
|
|
|
Op.Kind = kRegister;
|
|
|
|
Op.RegVal = Reg;
|
|
|
|
return Op;
|
2009-06-19 00:47:33 +00:00
|
|
|
}
|
2009-08-02 00:09:22 +00:00
|
|
|
static MCOperand CreateImm(int64_t Val) {
|
|
|
|
MCOperand Op;
|
|
|
|
Op.Kind = kImmediate;
|
|
|
|
Op.ImmVal = Val;
|
|
|
|
return Op;
|
2009-06-19 00:47:33 +00:00
|
|
|
}
|
2009-08-31 08:08:38 +00:00
|
|
|
static MCOperand CreateExpr(const MCExpr *Val) {
|
2009-08-02 00:09:22 +00:00
|
|
|
MCOperand Op;
|
2009-08-31 08:08:38 +00:00
|
|
|
Op.Kind = kExpr;
|
|
|
|
Op.ExprVal = Val;
|
2009-08-02 00:09:22 +00:00
|
|
|
return Op;
|
2009-06-30 23:37:44 +00:00
|
|
|
}
|
2009-08-27 07:57:12 +00:00
|
|
|
|
2009-09-03 05:46:51 +00:00
|
|
|
void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
|
2009-08-27 07:57:12 +00:00
|
|
|
void dump() const;
|
2009-06-19 00:47:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// MCInst - Instances of this class represent a single low-level machine
|
|
|
|
/// instruction.
|
|
|
|
class MCInst {
|
|
|
|
unsigned Opcode;
|
|
|
|
SmallVector<MCOperand, 8> Operands;
|
|
|
|
public:
|
2009-09-11 16:33:58 +00:00
|
|
|
MCInst() : Opcode(0) {}
|
2009-06-19 00:47:33 +00:00
|
|
|
|
2009-06-20 00:47:37 +00:00
|
|
|
void setOpcode(unsigned Op) { Opcode = Op; }
|
|
|
|
|
2009-06-19 23:59:57 +00:00
|
|
|
unsigned getOpcode() const { return Opcode; }
|
2009-09-09 20:45:42 +00:00
|
|
|
|
2009-06-19 23:59:57 +00:00
|
|
|
const MCOperand &getOperand(unsigned i) const { return Operands[i]; }
|
2009-06-20 07:03:18 +00:00
|
|
|
MCOperand &getOperand(unsigned i) { return Operands[i]; }
|
2009-06-23 17:50:34 +00:00
|
|
|
unsigned getNumOperands() const { return Operands.size(); }
|
2009-06-19 00:47:33 +00:00
|
|
|
|
2009-06-20 00:47:37 +00:00
|
|
|
void addOperand(const MCOperand &Op) {
|
|
|
|
Operands.push_back(Op);
|
|
|
|
}
|
2009-08-27 07:57:12 +00:00
|
|
|
|
2009-09-03 05:46:51 +00:00
|
|
|
void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
|
2009-08-27 07:57:12 +00:00
|
|
|
void dump() const;
|
2009-06-19 00:47:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|