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/iBinary.h"
12 #include "llvm/iUnary.h"
14 Instruction::Instruction(const Type *ty, unsigned it, const string &Name)
15 : User(ty, Value::InstructionVal, Name) {
20 Instruction::~Instruction() {
21 assert(getParent() == 0 && "Instruction still embeded in basic block!");
24 // Specialize setName to take care of symbol table majik
25 void Instruction::setName(const string &name) {
26 BasicBlock *P = 0; Method *PP = 0;
27 if ((P = getParent()) && (PP = P->getParent()) && hasName())
28 PP->getSymbolTable()->remove(this);
30 if (PP && hasName()) PP->getSymbolTableSure()->insert(this);
33 Instruction *Instruction::getBinaryOperator(unsigned Op, Value *S1, Value *S2) {
36 return new AddInst(S1, S2);
38 return new SubInst(S1, S2);
46 return new SetCondInst((BinaryOps)Op, S1, S2);
49 cerr << "Don't know how to GetBinaryOperator " << Op << endl;
55 Instruction *Instruction::getUnaryOperator(unsigned Op, Value *Source) {
58 cerr << "Don't know how to GetUnaryOperator " << Op << endl;