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/Method.h"
9 #include "llvm/SymbolTable.h"
10 #include "llvm/CodeGen/MachineInstr.h"
12 Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name)
13 : User(ty, Value::InstructionVal, Name),
14 machineInstrVec(new MachineCodeForVMInstr) {
19 Instruction::~Instruction() {
20 assert(getParent() == 0 && "Instruction still embedded in basic block!");
21 delete machineInstrVec;
24 // Specialize setName to take care of symbol table majik
25 void Instruction::setName(const std::string &name, SymbolTable *ST) {
26 BasicBlock *P = 0; Method *PP = 0;
27 assert((ST == 0 || !getParent() || !getParent()->getParent() ||
28 ST == getParent()->getParent()->getSymbolTable()) &&
29 "Invalid symtab argument!");
30 if ((P = getParent()) && (PP = P->getParent()) && hasName())
31 PP->getSymbolTable()->remove(this);
33 if (PP && hasName()) PP->getSymbolTableSure()->insert(this);
36 void Instruction::addMachineInstruction(MachineInstr* minstr) {
37 machineInstrVec->push_back(minstr);
41 // Dont make this inline because you would need to include
42 // MachineInstr.h in Instruction.h, which creates a circular
43 // sequence of forward declarations. Trying to fix that will
44 // cause a serious circularity in link order.
46 const std::vector<Value*> &Instruction::getTempValuesForMachineCode() const {
47 return machineInstrVec->getTempValues();
51 void Instruction::dropAllReferences() {
52 machineInstrVec->dropAllReferences();
53 User::dropAllReferences();