Initial revision
[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/iBinary.h"
12 #include "llvm/iUnary.h"
13
14 Instruction::Instruction(const Type *ty, unsigned it, const string &Name) 
15   : User(ty, Value::InstructionVal, Name) {
16   Parent = 0;
17   iType = it;
18 }
19
20 Instruction::~Instruction() {
21   assert(getParent() == 0 && "Instruction still embeded in basic block!");
22 }
23
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);
29   Value::setName(name);
30   if (PP && hasName()) PP->getSymbolTableSure()->insert(this);
31 }
32
33 Instruction *Instruction::getBinaryOperator(unsigned Op, Value *S1, Value *S2) {
34   switch (Op) {
35   case Add:
36     return new AddInst(S1, S2);
37   case Sub:
38     return new SubInst(S1, S2);
39
40   case SetLT:
41   case SetGT:
42   case SetLE:
43   case SetGE:
44   case SetEQ:
45   case SetNE:
46     return new SetCondInst((BinaryOps)Op, S1, S2);
47
48   default:
49     cerr << "Don't know how to GetBinaryOperator " << Op << endl;
50     return 0;
51   }
52 }
53
54
55 Instruction *Instruction::getUnaryOperator(unsigned Op, Value *Source) {
56   switch (Op) {
57   default:
58     cerr << "Don't know how to GetUnaryOperator " << Op << endl;
59     return 0;
60   }
61 }