Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 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" |
Vikram S. Adve | 3e2394c | 2001-07-20 21:05:02 +0000 | [diff] [blame] | 11 | #include "llvm/Codegen/MachineInstr.h" |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 12 | |
| 13 | Instruction::Instruction(const Type *ty, unsigned it, const string &Name) |
Vikram S. Adve | 3e2394c | 2001-07-20 21:05:02 +0000 | [diff] [blame] | 14 | : User(ty, Value::InstructionVal, Name), |
| 15 | machineInstrVec(new MachineCodeForVMInstr) |
| 16 | { |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 17 | Parent = 0; |
| 18 | iType = it; |
| 19 | } |
| 20 | |
| 21 | Instruction::~Instruction() { |
Vikram S. Adve | 3e2394c | 2001-07-20 21:05:02 +0000 | [diff] [blame] | 22 | assert(getParent() == 0 && "Instruction still embedded in basic block!"); |
| 23 | delete machineInstrVec; |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | // Specialize setName to take care of symbol table majik |
| 27 | void Instruction::setName(const string &name) { |
| 28 | BasicBlock *P = 0; Method *PP = 0; |
| 29 | if ((P = getParent()) && (PP = P->getParent()) && hasName()) |
| 30 | PP->getSymbolTable()->remove(this); |
| 31 | Value::setName(name); |
| 32 | if (PP && hasName()) PP->getSymbolTableSure()->insert(this); |
| 33 | } |
Vikram S. Adve | 3e2394c | 2001-07-20 21:05:02 +0000 | [diff] [blame] | 34 | |
| 35 | void |
| 36 | Instruction::addMachineInstruction(MachineInstr* minstr) |
| 37 | { |
| 38 | machineInstrVec->push_back(minstr); |
| 39 | } |
| 40 | |
Chris Lattner | 93547c3 | 2001-07-21 20:04:10 +0000 | [diff] [blame] | 41 | #if 0 |
Vikram S. Adve | 3e2394c | 2001-07-20 21:05:02 +0000 | [diff] [blame] | 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*>& |
| 48 | Instruction::getTempValuesForMachineCode() const |
| 49 | { |
| 50 | return machineInstrVec->getTempValues(); |
| 51 | } |
Chris Lattner | 93547c3 | 2001-07-21 20:04:10 +0000 | [diff] [blame] | 52 | #endif |
Vikram S. Adve | 3e2394c | 2001-07-20 21:05:02 +0000 | [diff] [blame] | 53 | |
| 54 | void |
| 55 | Instruction::dropAllReferences() { |
| 56 | machineInstrVec->dropAllReferences(); |
| 57 | User::dropAllReferences(); |
| 58 | } |