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 // Specialize setName to take care of symbol table majik
18 void Instruction::setName(const std::string &name, SymbolTable *ST) {
19 BasicBlock *P = 0; Function *PP = 0;
20 assert((ST == 0 || !getParent() || !getParent()->getParent() ||
21 ST == getParent()->getParent()->getSymbolTable()) &&
22 "Invalid symtab argument!");
23 if ((P = getParent()) && (PP = P->getParent()) && hasName())
24 PP->getSymbolTable()->remove(this);
26 if (PP && hasName()) PP->getSymbolTableSure()->insert(this);
30 const char *Instruction::getOpcodeName(unsigned OpCode) {
33 case Ret: return "ret";
35 case Switch: return "switch";
36 case Invoke: return "invoke";
38 // Standard binary operators...
39 case Add: return "add";
40 case Sub: return "sub";
41 case Mul: return "mul";
42 case Div: return "div";
43 case Rem: return "rem";
45 // Logical operators...
46 case And: return "and";
47 case Or : return "or";
48 case Xor: return "xor";
51 case SetLE: return "setle";
52 case SetGE: return "setge";
53 case SetLT: return "setlt";
54 case SetGT: return "setgt";
55 case SetEQ: return "seteq";
56 case SetNE: return "setne";
58 // Memory instructions...
59 case Malloc: return "malloc";
60 case Free: return "free";
61 case Alloca: return "alloca";
62 case Load: return "load";
63 case Store: return "store";
64 case GetElementPtr: return "getelementptr";
66 // Other instructions...
67 case PHINode: return "phi";
68 case Cast: return "cast";
69 case Call: return "call";
70 case Shl: return "shl";
71 case Shr: return "shr";
73 default: return "<Invalid operator> ";