* Support new setname interface
[oota-llvm.git] / lib / VMCore / Instruction.cpp
1 //===-- Instruction.cpp - Implement the Instruction class --------*- C++ -*--=//
2 //
3 // This file implements the Instruction class for the VMCore library.
4 //
5 //===----------------------------------------------------------------------===//
6
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"
12
13 Instruction::Instruction(const Type *ty, unsigned it, const string &Name) 
14   : User(ty, Value::InstructionVal, Name), 
15     machineInstrVec(new MachineCodeForVMInstr) {
16   Parent = 0;
17   iType = it;
18 }
19
20 Instruction::~Instruction() {
21   assert(getParent() == 0 && "Instruction still embedded in basic block!");
22   delete machineInstrVec;
23 }
24
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);
33   Value::setName(name);
34   if (PP && hasName()) PP->getSymbolTableSure()->insert(this);
35 }
36
37 void Instruction::addMachineInstruction(MachineInstr* minstr) {
38   machineInstrVec->push_back(minstr);
39 }
40
41 #if 0
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.
46 // 
47 const vector<Value*> &Instruction::getTempValuesForMachineCode() const {
48   return machineInstrVec->getTempValues();
49 }
50 #endif
51
52 void Instruction::dropAllReferences() {
53   machineInstrVec->dropAllReferences();
54   User::dropAllReferences();
55 }