1 //===-- Instruction.cpp - Implement the Instruction class --------*- C++ -*--=//
3 // This file implements the Instruction class for the VMCore library.
5 //===----------------------------------------------------------------------===//
7 #include "llvm/Function.h"
8 #include "llvm/SymbolTable.h"
10 #include "Support/LeakDetector.h"
12 Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name)
13 : User(ty, Value::InstructionVal, Name) {
17 // Make sure that we get added to a basicblock
18 LeakDetector::addGarbageObject(this);
21 void Instruction::setParent(BasicBlock *P) {
23 LeakDetector::addGarbageObject(this);
28 LeakDetector::removeGarbageObject(this);
31 // Specialize setName to take care of symbol table majik
32 void Instruction::setName(const std::string &name, SymbolTable *ST) {
33 BasicBlock *P = 0; Function *PP = 0;
34 assert((ST == 0 || !getParent() || !getParent()->getParent() ||
35 ST == getParent()->getParent()->getSymbolTable()) &&
36 "Invalid symtab argument!");
37 if ((P = getParent()) && (PP = P->getParent()) && hasName())
38 PP->getSymbolTable()->remove(this);
40 if (PP && hasName()) PP->getSymbolTableSure()->insert(this);
44 const char *Instruction::getOpcodeName(unsigned OpCode) {
47 case Ret: return "ret";
49 case Switch: return "switch";
50 case Invoke: return "invoke";
52 // Standard binary operators...
53 case Add: return "add";
54 case Sub: return "sub";
55 case Mul: return "mul";
56 case Div: return "div";
57 case Rem: return "rem";
59 // Logical operators...
60 case And: return "and";
61 case Or : return "or";
62 case Xor: return "xor";
65 case SetLE: return "setle";
66 case SetGE: return "setge";
67 case SetLT: return "setlt";
68 case SetGT: return "setgt";
69 case SetEQ: return "seteq";
70 case SetNE: return "setne";
72 // Memory instructions...
73 case Malloc: return "malloc";
74 case Free: return "free";
75 case Alloca: return "alloca";
76 case Load: return "load";
77 case Store: return "store";
78 case GetElementPtr: return "getelementptr";
80 // Other instructions...
81 case PHINode: return "phi";
82 case Cast: return "cast";
83 case Call: return "call";
84 case Shl: return "shl";
85 case Shr: return "shr";
87 default: return "<Invalid operator> ";