summaryrefslogtreecommitdiff
path: root/lib/VMCore/Instruction.cpp
blob: 4b528f0d94ab2294bca410ff237ac7e6d461d255 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//===-- Instruction.cpp - Implement the Instruction class --------*- C++ -*--=//
//
// This file implements the Instruction class for the VMCore library.
//
//===----------------------------------------------------------------------===//

#include "llvm/Instruction.h"
#include "llvm/BasicBlock.h"
#include "llvm/Method.h"
#include "llvm/SymbolTable.h"
#include "llvm/iBinary.h"
#include "llvm/iUnary.h"

Instruction::Instruction(const Type *ty, unsigned it, const string &Name) 
  : User(ty, Value::InstructionVal, Name) {
  Parent = 0;
  iType = it;
}

Instruction::~Instruction() {
  assert(getParent() == 0 && "Instruction still embeded in basic block!");
}

// Specialize setName to take care of symbol table majik
void Instruction::setName(const string &name) {
  BasicBlock *P = 0; Method *PP = 0;
  if ((P = getParent()) && (PP = P->getParent()) && hasName())
    PP->getSymbolTable()->remove(this);
  Value::setName(name);
  if (PP && hasName()) PP->getSymbolTableSure()->insert(this);
}

Instruction *Instruction::getBinaryOperator(unsigned Op, Value *S1, Value *S2) {
  switch (Op) {
  case Add:
    return new AddInst(S1, S2);
  case Sub:
    return new SubInst(S1, S2);

  case SetLT:
  case SetGT:
  case SetLE:
  case SetGE:
  case SetEQ:
  case SetNE:
    return new SetCondInst((BinaryOps)Op, S1, S2);

  default:
    cerr << "Don't know how to GetBinaryOperator " << Op << endl;
    return 0;
  }
}


Instruction *Instruction::getUnaryOperator(unsigned Op, Value *Source) {
  switch (Op) {
  default:
    cerr << "Don't know how to GetUnaryOperator " << Op << endl;
    return 0;
  }
}