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"
11 Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name)
12 : User(ty, Value::InstructionVal, Name) {
17 void Instruction::setParent(BasicBlock *P) {
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);
30 if (PP && hasName()) PP->getSymbolTableSure()->insert(this);
34 const char *Instruction::getOpcodeName(unsigned OpCode) {
37 case Ret: return "ret";
39 case Switch: return "switch";
40 case Invoke: return "invoke";
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";
49 // Logical operators...
50 case And: return "and";
51 case Or : return "or";
52 case Xor: return "xor";
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";
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";
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";
77 default: return "<Invalid operator> ";