1 //===-- Instruction.cpp - Implement the Instruction class --------*- C++ -*--=//
3 // This file implements the Instruction class for the VMCore library.
5 //===----------------------------------------------------------------------===//
7 #include "llvm/Instruction.h"
8 #include "llvm/BasicBlock.h"
9 #include "llvm/Method.h"
10 #include "llvm/SymbolTable.h"
11 #include "llvm/Codegen/MachineInstr.h"
13 Instruction::Instruction(const Type *ty, unsigned it, const string &Name)
14 : User(ty, Value::InstructionVal, Name),
15 machineInstrVec(new MachineCodeForVMInstr) {
20 Instruction::~Instruction() {
21 assert(getParent() == 0 && "Instruction still embedded in basic block!");
22 delete machineInstrVec;
25 // Specialize setName to take care of symbol table majik
26 void Instruction::setName(const string &name) {
27 BasicBlock *P = 0; Method *PP = 0;
28 if ((P = getParent()) && (PP = P->getParent()) && hasName())
29 PP->getSymbolTable()->remove(this);
31 if (PP && hasName()) PP->getSymbolTableSure()->insert(this);
34 void Instruction::addMachineInstruction(MachineInstr* minstr) {
35 machineInstrVec->push_back(minstr);
39 // Dont make this inline because you would need to include
40 // MachineInstr.h in Instruction.h, which creates a circular
41 // sequence of forward declarations. Trying to fix that will
42 // cause a serious circularity in link order.
44 const vector<Value*> &Instruction::getTempValuesForMachineCode() const {
45 return machineInstrVec->getTempValues();
49 void Instruction::dropAllReferences() {
50 machineInstrVec->dropAllReferences();
51 User::dropAllReferences();