2c7f6eae91fa881939dc59edc3bf96bc1941a061
[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/Function.h"
8 #include "llvm/SymbolTable.h"
9 #include "llvm/Type.h"
10
11 Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name) 
12   : User(ty, Value::InstructionVal, Name) {
13   Parent = 0;
14   iType = it;
15 }
16
17 void Instruction::setParent(BasicBlock *P) {
18   Parent = P;
19 }
20
21 // Specialize setName to take care of symbol table majik
22 void Instruction::setName(const std::string &name, SymbolTable *ST) {
23   BasicBlock *P = 0; Function *PP = 0;
24   assert((ST == 0 || !getParent() || !getParent()->getParent() || 
25           ST == getParent()->getParent()->getSymbolTable()) &&
26          "Invalid symtab argument!");
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
34 const char *Instruction::getOpcodeName(unsigned OpCode) {
35   switch (OpCode) {
36   // Terminators
37   case Ret:    return "ret";
38   case Br:     return "br";
39   case Switch: return "switch";
40   case Invoke: return "invoke";
41     
42   // Standard binary operators...
43   case Add: return "add";
44   case Sub: return "sub";
45   case Mul: return "mul";
46   case Div: return "div";
47   case Rem: return "rem";
48
49   // Logical operators...
50   case And: return "and";
51   case Or : return "or";
52   case Xor: return "xor";
53
54   // SetCC operators...
55   case SetLE:  return "setle";
56   case SetGE:  return "setge";
57   case SetLT:  return "setlt";
58   case SetGT:  return "setgt";
59   case SetEQ:  return "seteq";
60   case SetNE:  return "setne";
61     
62   // Memory instructions...
63   case Malloc:        return "malloc";
64   case Free:          return "free";
65   case Alloca:        return "alloca";
66   case Load:          return "load";
67   case Store:         return "store";
68   case GetElementPtr: return "getelementptr";
69     
70   // Other instructions...
71   case PHINode: return "phi";
72   case Cast:    return "cast";
73   case Call:    return "call";
74   case Shl:     return "shl";
75   case Shr:     return "shr";
76     
77   default: return "<Invalid operator> ";
78   }
79   
80   return 0;
81 }