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, SymbolTable *ST) {
27 BasicBlock *P = 0; Method *PP = 0;
28 assert((ST == 0 || !getParent() || !getParent()->getParent() ||
29 ST == getParent()->getParent()->getSymbolTable()) &&
30 "Invalid symtab argument!");
31 if ((P = getParent()) && (PP = P->getParent()) && hasName())
32 PP->getSymbolTable()->remove(this);
34 if (PP && hasName()) PP->getSymbolTableSure()->insert(this);
37 void Instruction::addMachineInstruction(MachineInstr* minstr) {
38 machineInstrVec->push_back(minstr);
42 // Dont make this inline because you would need to include
43 // MachineInstr.h in Instruction.h, which creates a circular
44 // sequence of forward declarations. Trying to fix that will
45 // cause a serious circularity in link order.
47 const vector<Value*> &Instruction::getTempValuesForMachineCode() const {
48 return machineInstrVec->getTempValues();
52 void Instruction::dropAllReferences() {
53 machineInstrVec->dropAllReferences();
54 User::dropAllReferences();