blob: 3bc642b6376d01d32755c5e016a9721355c3f180 [file] [log] [blame]
Chris Lattner00950542001-06-06 20:29:01 +00001//===-- Instruction.cpp - Implement the Instruction class --------*- C++ -*--=//
2//
3// This file implements the Instruction class for the VMCore library.
4//
5//===----------------------------------------------------------------------===//
6
Chris Lattner2fbfdcf2002-04-07 20:49:59 +00007#include "llvm/Function.h"
Chris Lattner00950542001-06-06 20:29:01 +00008#include "llvm/SymbolTable.h"
Chris Lattner7e708292002-06-25 16:13:24 +00009#include "llvm/Type.h"
Chris Lattner00950542001-06-06 20:29:01 +000010
Chris Lattner697954c2002-01-20 22:54:45 +000011Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name)
Chris Lattner71947fd2002-02-03 07:52:58 +000012 : User(ty, Value::InstructionVal, Name) {
Chris Lattner00950542001-06-06 20:29:01 +000013 Parent = 0;
14 iType = it;
15}
16
Chris Lattner00950542001-06-06 20:29:01 +000017// Specialize setName to take care of symbol table majik
Chris Lattner697954c2002-01-20 22:54:45 +000018void Instruction::setName(const std::string &name, SymbolTable *ST) {
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000019 BasicBlock *P = 0; Function *PP = 0;
Chris Lattnere05bf2f2001-09-07 16:47:03 +000020 assert((ST == 0 || !getParent() || !getParent()->getParent() ||
21 ST == getParent()->getParent()->getSymbolTable()) &&
22 "Invalid symtab argument!");
Chris Lattner00950542001-06-06 20:29:01 +000023 if ((P = getParent()) && (PP = P->getParent()) && hasName())
24 PP->getSymbolTable()->remove(this);
25 Value::setName(name);
26 if (PP && hasName()) PP->getSymbolTableSure()->insert(this);
27}
Vikram S. Advec1056452002-07-14 23:09:40 +000028
29
30const char *Instruction::getOpcodeName(unsigned OpCode) {
31 switch (OpCode) {
32 // Terminators
33 case Ret: return "ret";
34 case Br: return "br";
35 case Switch: return "switch";
36 case Invoke: return "invoke";
37
38 // Standard unary operators...
39 case Not: return "not";
40
41 // Standard binary operators...
42 case Add: return "add";
43 case Sub: return "sub";
44 case Mul: return "mul";
45 case Div: return "div";
46 case Rem: return "rem";
47
48 // Logical operators...
49 case And: return "and";
50 case Or : return "or";
51 case Xor: return "xor";
52
53 // SetCC operators...
54 case SetLE: return "setle";
55 case SetGE: return "setge";
56 case SetLT: return "setlt";
57 case SetGT: return "setgt";
58 case SetEQ: return "seteq";
59 case SetNE: return "setne";
60
61 // Memory instructions...
62 case Malloc: return "malloc";
63 case Free: return "free";
64 case Alloca: return "alloca";
65 case Load: return "load";
66 case Store: return "store";
67 case GetElementPtr: return "getelementptr";
68
69 // Other instructions...
70 case PHINode: return "phi";
71 case Cast: return "cast";
72 case Call: return "call";
73 case Shl: return "shl";
74 case Shr: return "shr";
75
76 default: return "<Invalid operator> ";
77 }
78
79 return 0;
80}