Chris Lattner | 0095054 | 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" |
Chris Lattner | 7e583cf | 2001-07-21 20:58:30 +0000 | [diff] [blame] | 11 | #include "llvm/CodeGen/MachineInstr.h" |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 12 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame^] | 13 | Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name) |
Chris Lattner | f9be9a9 | 2001-07-21 20:09:07 +0000 | [diff] [blame] | 14 | : User(ty, Value::InstructionVal, Name), |
| 15 | machineInstrVec(new MachineCodeForVMInstr) { |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 16 | Parent = 0; |
| 17 | iType = it; |
| 18 | } |
| 19 | |
| 20 | Instruction::~Instruction() { |
Vikram S. Adve | 3344615 | 2001-07-20 21:05:02 +0000 | [diff] [blame] | 21 | assert(getParent() == 0 && "Instruction still embedded in basic block!"); |
| 22 | delete machineInstrVec; |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | // Specialize setName to take care of symbol table majik |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame^] | 26 | void Instruction::setName(const std::string &name, SymbolTable *ST) { |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 27 | BasicBlock *P = 0; Method *PP = 0; |
Chris Lattner | e05bf2f | 2001-09-07 16:47:03 +0000 | [diff] [blame] | 28 | assert((ST == 0 || !getParent() || !getParent()->getParent() || |
| 29 | ST == getParent()->getParent()->getSymbolTable()) && |
| 30 | "Invalid symtab argument!"); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 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 | } |
Vikram S. Adve | 3344615 | 2001-07-20 21:05:02 +0000 | [diff] [blame] | 36 | |
Chris Lattner | f9be9a9 | 2001-07-21 20:09:07 +0000 | [diff] [blame] | 37 | void Instruction::addMachineInstruction(MachineInstr* minstr) { |
Vikram S. Adve | 3344615 | 2001-07-20 21:05:02 +0000 | [diff] [blame] | 38 | machineInstrVec->push_back(minstr); |
| 39 | } |
| 40 | |
Chris Lattner | cfad5df | 2001-07-21 20:04:10 +0000 | [diff] [blame] | 41 | #if 0 |
Vikram S. Adve | 3344615 | 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 | // |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame^] | 47 | const std::vector<Value*> &Instruction::getTempValuesForMachineCode() const { |
Vikram S. Adve | 3344615 | 2001-07-20 21:05:02 +0000 | [diff] [blame] | 48 | return machineInstrVec->getTempValues(); |
| 49 | } |
Chris Lattner | cfad5df | 2001-07-21 20:04:10 +0000 | [diff] [blame] | 50 | #endif |
Vikram S. Adve | 3344615 | 2001-07-20 21:05:02 +0000 | [diff] [blame] | 51 | |
Chris Lattner | f9be9a9 | 2001-07-21 20:09:07 +0000 | [diff] [blame] | 52 | void Instruction::dropAllReferences() { |
Vikram S. Adve | 3344615 | 2001-07-20 21:05:02 +0000 | [diff] [blame] | 53 | machineInstrVec->dropAllReferences(); |
| 54 | User::dropAllReferences(); |
| 55 | } |