freebsd-dev/include/llvm/MC/MCInst.h

134 lines
3.4 KiB
C
Raw Normal View History

2009-06-22 08:08:12 +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-11-04 14:58:56 +00:00
#include "llvm/System/DataTypes.h"
2009-06-22 08:08:12 +00:00
namespace llvm {
2009-10-14 17:57:32 +00:00
class raw_ostream;
class MCAsmInfo;
class MCExpr;
2009-06-22 08:08:12 +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.
kImmediate, ///< Immediate operand.
2009-10-14 17:57:32 +00:00
kExpr ///< Relocatable immediate operand.
2009-06-22 08:08:12 +00:00
};
unsigned char Kind;
union {
unsigned RegVal;
int64_t ImmVal;
2009-10-14 17:57:32 +00:00
const MCExpr *ExprVal;
2009-06-22 08:08:12 +00:00
};
public:
MCOperand() : Kind(kInvalid) {}
2009-07-04 13:58:26 +00:00
bool isValid() const { return Kind != kInvalid; }
2009-06-22 08:08:12 +00:00
bool isReg() const { return Kind == kRegister; }
bool isImm() const { return Kind == kImmediate; }
2009-10-14 17:57:32 +00:00
bool isExpr() const { return Kind == kExpr; }
2009-06-22 08:08:12 +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;
}
int64_t getImm() const {
assert(isImm() && "This is not an immediate");
return ImmVal;
}
void setImm(int64_t Val) {
assert(isImm() && "This is not an immediate");
ImmVal = Val;
}
2009-10-14 17:57:32 +00:00
const MCExpr *getExpr() const {
assert(isExpr() && "This is not an expression");
return ExprVal;
2009-06-22 08:08:12 +00:00
}
2009-10-14 17:57:32 +00:00
void setExpr(const MCExpr *Val) {
assert(isExpr() && "This is not an expression");
ExprVal = Val;
2009-07-04 13:58:26 +00:00
}
2009-06-22 08:08:12 +00:00
2009-10-14 17:57:32 +00:00
static MCOperand CreateReg(unsigned Reg) {
MCOperand Op;
Op.Kind = kRegister;
Op.RegVal = Reg;
return Op;
2009-06-22 08:08:12 +00:00
}
2009-10-14 17:57:32 +00:00
static MCOperand CreateImm(int64_t Val) {
MCOperand Op;
Op.Kind = kImmediate;
Op.ImmVal = Val;
return Op;
2009-06-22 08:08:12 +00:00
}
2009-10-14 17:57:32 +00:00
static MCOperand CreateExpr(const MCExpr *Val) {
MCOperand Op;
Op.Kind = kExpr;
Op.ExprVal = Val;
return Op;
2009-07-04 13:58:26 +00:00
}
2009-10-14 17:57:32 +00:00
void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
void dump() const;
2009-06-22 08:08:12 +00:00
};
/// MCInst - Instances of this class represent a single low-level machine
/// instruction.
class MCInst {
unsigned Opcode;
SmallVector<MCOperand, 8> Operands;
public:
2009-10-14 17:57:32 +00:00
MCInst() : Opcode(0) {}
2009-06-22 08:08:12 +00:00
void setOpcode(unsigned Op) { Opcode = Op; }
unsigned getOpcode() const { return Opcode; }
2009-10-14 17:57:32 +00:00
2009-06-22 08:08:12 +00:00
const MCOperand &getOperand(unsigned i) const { return Operands[i]; }
MCOperand &getOperand(unsigned i) { return Operands[i]; }
unsigned getNumOperands() const { return Operands.size(); }
2009-06-22 08:08:12 +00:00
void addOperand(const MCOperand &Op) {
Operands.push_back(Op);
}
2009-10-14 17:57:32 +00:00
void print(raw_ostream &OS, const MCAsmInfo *MAI) const;
void dump() const;
2009-06-22 08:08:12 +00:00
};
} // end namespace llvm
#endif