6cb62ea374aac864994b97460f8196f564f375b6
[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 BinaryOperator *BinaryOperator::getBinaryOperator(unsigned Op, 
34                                                   Value *S1, Value *S2) {
35   switch (Op) {
36   case Add:
37     return new AddInst(S1, S2);
38   case Sub:
39     return new SubInst(S1, S2);
40
41   case SetLT:
42   case SetGT:
43   case SetLE:
44   case SetGE:
45   case SetEQ:
46   case SetNE:
47     return new SetCondInst((BinaryOps)Op, S1, S2);
48
49   default:
50     cerr << "Don't know how to GetBinaryOperator " << Op << endl;
51     return 0;
52   }
53 }
54
55
56 UnaryOperator *UnaryOperator::getUnaryOperator(unsigned Op, Value *Source) {
57   switch (Op) {
58   default:
59     cerr << "Don't know how to GetUnaryOperator " << Op << endl;
60     return 0;
61   }
62 }