Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1 | //===-- Instruction.cpp - Implement the Instruction class --------*- C++ -*--=// |
| 2 | // |
| 3 | // This file implements the Instruction class for the VMCore library. |
| 4 | // |
| 5 | //===----------------------------------------------------------------------===// |
| 6 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 7 | #include "llvm/Function.h" |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 8 | #include "llvm/SymbolTable.h" |
Chris Lattner | 7e70829 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 9 | #include "llvm/Type.h" |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 10 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 11 | Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name) |
Chris Lattner | 71947fd | 2002-02-03 07:52:58 +0000 | [diff] [blame] | 12 | : User(ty, Value::InstructionVal, Name) { |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 13 | Parent = 0; |
| 14 | iType = it; |
| 15 | } |
| 16 | |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 17 | // Specialize setName to take care of symbol table majik |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 18 | void Instruction::setName(const std::string &name, SymbolTable *ST) { |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 19 | BasicBlock *P = 0; Function *PP = 0; |
Chris Lattner | e05bf2f | 2001-09-07 16:47:03 +0000 | [diff] [blame] | 20 | assert((ST == 0 || !getParent() || !getParent()->getParent() || |
| 21 | ST == getParent()->getParent()->getSymbolTable()) && |
| 22 | "Invalid symtab argument!"); |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 23 | 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. Adve | c105645 | 2002-07-14 23:09:40 +0000 | [diff] [blame] | 28 | |
| 29 | |
| 30 | const char *Instruction::getOpcodeName(unsigned OpCode) { |
| 31 | switch (OpCode) { |
| 32 | // Terminators |
Chris Lattner | 0513e9f | 2002-08-14 18:18:02 +0000 | [diff] [blame] | 33 | case Ret: return "ret"; |
| 34 | case Br: return "br"; |
Vikram S. Adve | c105645 | 2002-07-14 23:09:40 +0000 | [diff] [blame] | 35 | case Switch: return "switch"; |
| 36 | case Invoke: return "invoke"; |
| 37 | |
Vikram S. Adve | c105645 | 2002-07-14 23:09:40 +0000 | [diff] [blame] | 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"; |
| 44 | |
| 45 | // Logical operators... |
| 46 | case And: return "and"; |
| 47 | case Or : return "or"; |
| 48 | case Xor: return "xor"; |
| 49 | |
| 50 | // SetCC operators... |
| 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"; |
| 57 | |
| 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"; |
| 65 | |
| 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"; |
| 72 | |
| 73 | default: return "<Invalid operator> "; |
| 74 | } |
| 75 | |
| 76 | return 0; |
| 77 | } |