Initial revision
[oota-llvm.git] / lib / VMCore / InstrTypes.cpp
1 //===-- InstrTypes.cpp - Implement Instruction subclasses --------*- C++ -*--=//
2 //
3 // This file implements 
4 //
5 //===----------------------------------------------------------------------===//
6
7 #include "llvm/iOther.h"
8 #include "llvm/BasicBlock.h"
9 #include "llvm/Method.h"
10 #include "llvm/SymbolTable.h"
11 #include "llvm/Type.h"
12 #include <algorithm>
13
14 //===----------------------------------------------------------------------===//
15 //                            TerminatorInst Class
16 //===----------------------------------------------------------------------===//
17
18 TerminatorInst::TerminatorInst(unsigned iType) 
19   : Instruction(Type::VoidTy, iType, "") {
20 }
21
22
23 //===----------------------------------------------------------------------===//
24 //                            MethodArgument Class
25 //===----------------------------------------------------------------------===//
26
27 // Specialize setName to take care of symbol table majik
28 void MethodArgument::setName(const string &name) {
29   Method *P;
30   if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this);
31   Value::setName(name);
32   if (P && hasName()) P->getSymbolTable()->insert(this);
33 }
34
35
36 //===----------------------------------------------------------------------===//
37 //                               PHINode Class
38 //===----------------------------------------------------------------------===//
39
40 PHINode::PHINode(const Type *Ty, const string &name) 
41   : Instruction(Ty, Instruction::PHINode, name) {
42 }
43
44 PHINode::PHINode(const PHINode &PN) 
45   : Instruction(PN.getType(), Instruction::PHINode) {
46   
47   for (unsigned i = 0; i < PN.IncomingValues.size(); i++)
48     IncomingValues.push_back(Use(PN.IncomingValues[i], this));
49 }
50
51 void PHINode::dropAllReferences() {
52   IncomingValues.clear();
53 }
54
55 bool PHINode::setOperand(unsigned i, Value *Val) {
56   assert(Val && "PHI node must only reference nonnull definitions!");
57   if (i >= IncomingValues.size()) return false;
58
59   IncomingValues[i] = Val;
60   return true;
61 }
62
63 void PHINode::addIncoming(Value *D) {
64   IncomingValues.push_back(Use(D, this));
65 }
66