Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1 | //===-- Execution.cpp - Implement code to simulate the program ------------===// |
| 2 | // |
| 3 | // This file contains the actual instruction interpreter. |
| 4 | // |
| 5 | //===----------------------------------------------------------------------===// |
| 6 | |
| 7 | #include "Interpreter.h" |
| 8 | #include "ExecutionAnnotations.h" |
Chris Lattner | 7061dc5 | 2001-12-03 18:02:31 +0000 | [diff] [blame] | 9 | #include "llvm/iPHINode.h" |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 10 | #include "llvm/iOther.h" |
| 11 | #include "llvm/iTerminators.h" |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 12 | #include "llvm/iMemory.h" |
Chris Lattner | e2cbbce | 2002-04-29 18:56:45 +0000 | [diff] [blame] | 13 | #include "llvm/DerivedTypes.h" |
Chris Lattner | 31bcdb8 | 2002-04-28 19:55:58 +0000 | [diff] [blame] | 14 | #include "llvm/Constants.h" |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 15 | #include "llvm/Assembly/Writer.h" |
Chris Lattner | 41c2e5c | 2001-09-28 22:56:43 +0000 | [diff] [blame] | 16 | #include "llvm/Target/TargetData.h" |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 17 | #include "llvm/GlobalVariable.h" |
Chris Lattner | f23eb85 | 2001-12-14 16:49:29 +0000 | [diff] [blame] | 18 | #include "Support/CommandLine.h" |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 19 | #include <math.h> // For fmod |
Chris Lattner | 5af0c48 | 2001-11-07 04:23:00 +0000 | [diff] [blame] | 20 | #include <signal.h> |
| 21 | #include <setjmp.h> |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 22 | #include <iostream> |
| 23 | using std::vector; |
| 24 | using std::cout; |
| 25 | using std::cerr; |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 26 | |
Chris Lattner | 5ff62e9 | 2002-07-22 02:10:13 +0000 | [diff] [blame] | 27 | static cl::opt<bool> |
| 28 | QuietMode("quiet", cl::desc("Do not emit any non-program output")); |
| 29 | |
| 30 | static cl::alias |
| 31 | QuietModeA("q", cl::desc("Alias for -quiet"), cl::aliasopt(QuietMode)); |
| 32 | |
| 33 | static cl::opt<bool> |
| 34 | ArrayChecksEnabled("array-checks", cl::desc("Enable array bound checks")); |
| 35 | |
| 36 | static cl::opt<bool> |
| 37 | AbortOnExceptions("abort-on-exception", |
| 38 | cl::desc("Halt execution on a machine exception")); |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 39 | |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 40 | // Create a TargetData structure to handle memory addressing and size/alignment |
| 41 | // computations |
| 42 | // |
| 43 | static TargetData TD("lli Interpreter"); |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 44 | CachedWriter CW; // Object to accelerate printing of LLVM |
Chris Lattner | 5af0c48 | 2001-11-07 04:23:00 +0000 | [diff] [blame] | 45 | |
| 46 | |
Chris Lattner | e240906 | 2001-11-12 16:19:45 +0000 | [diff] [blame] | 47 | #ifdef PROFILE_STRUCTURE_FIELDS |
Chris Lattner | 5ff62e9 | 2002-07-22 02:10:13 +0000 | [diff] [blame] | 48 | static cl::opt<bool> |
| 49 | ProfileStructureFields("profilestructfields", |
| 50 | cl::desc("Profile Structure Field Accesses")); |
Chris Lattner | e240906 | 2001-11-12 16:19:45 +0000 | [diff] [blame] | 51 | #include <map> |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 52 | static std::map<const StructType *, vector<unsigned> > FieldAccessCounts; |
Chris Lattner | e240906 | 2001-11-12 16:19:45 +0000 | [diff] [blame] | 53 | #endif |
| 54 | |
Chris Lattner | 5af0c48 | 2001-11-07 04:23:00 +0000 | [diff] [blame] | 55 | sigjmp_buf SignalRecoverBuffer; |
Chris Lattner | 461f02f | 2001-11-07 05:31:27 +0000 | [diff] [blame] | 56 | static bool InInstruction = false; |
Chris Lattner | 5af0c48 | 2001-11-07 04:23:00 +0000 | [diff] [blame] | 57 | |
| 58 | extern "C" { |
| 59 | static void SigHandler(int Signal) { |
Chris Lattner | 461f02f | 2001-11-07 05:31:27 +0000 | [diff] [blame] | 60 | if (InInstruction) |
| 61 | siglongjmp(SignalRecoverBuffer, Signal); |
Chris Lattner | 5af0c48 | 2001-11-07 04:23:00 +0000 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | |
| 65 | static void initializeSignalHandlers() { |
| 66 | struct sigaction Action; |
| 67 | Action.sa_handler = SigHandler; |
| 68 | Action.sa_flags = SA_SIGINFO; |
| 69 | sigemptyset(&Action.sa_mask); |
| 70 | sigaction(SIGSEGV, &Action, 0); |
| 71 | sigaction(SIGBUS, &Action, 0); |
Chris Lattner | 461f02f | 2001-11-07 05:31:27 +0000 | [diff] [blame] | 72 | sigaction(SIGINT, &Action, 0); |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 73 | sigaction(SIGFPE, &Action, 0); |
Chris Lattner | 5af0c48 | 2001-11-07 04:23:00 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 76 | |
| 77 | //===----------------------------------------------------------------------===// |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 78 | // Value Manipulation code |
| 79 | //===----------------------------------------------------------------------===// |
| 80 | |
| 81 | static unsigned getOperandSlot(Value *V) { |
| 82 | SlotNumber *SN = (SlotNumber*)V->getAnnotation(SlotNumberAID); |
| 83 | assert(SN && "Operand does not have a slot number annotation!"); |
| 84 | return SN->SlotNum; |
| 85 | } |
| 86 | |
| 87 | #define GET_CONST_VAL(TY, CLASS) \ |
| 88 | case Type::TY##TyID: Result.TY##Val = cast<CLASS>(CPV)->getValue(); break |
| 89 | |
| 90 | static GenericValue getOperandValue(Value *V, ExecutionContext &SF) { |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 91 | if (Constant *CPV = dyn_cast<Constant>(V)) { |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 92 | GenericValue Result; |
| 93 | switch (CPV->getType()->getPrimitiveID()) { |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 94 | GET_CONST_VAL(Bool , ConstantBool); |
| 95 | GET_CONST_VAL(UByte , ConstantUInt); |
| 96 | GET_CONST_VAL(SByte , ConstantSInt); |
| 97 | GET_CONST_VAL(UShort , ConstantUInt); |
| 98 | GET_CONST_VAL(Short , ConstantSInt); |
| 99 | GET_CONST_VAL(UInt , ConstantUInt); |
| 100 | GET_CONST_VAL(Int , ConstantSInt); |
| 101 | GET_CONST_VAL(ULong , ConstantUInt); |
| 102 | GET_CONST_VAL(Long , ConstantSInt); |
| 103 | GET_CONST_VAL(Float , ConstantFP); |
| 104 | GET_CONST_VAL(Double , ConstantFP); |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 105 | case Type::PointerTyID: |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 106 | if (isa<ConstantPointerNull>(CPV)) { |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 107 | Result.PointerVal = 0; |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 108 | } else if (isa<ConstantPointerRef>(CPV)) { |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 109 | assert(0 && "Not implemented!"); |
| 110 | } else { |
| 111 | assert(0 && "Unknown constant pointer type!"); |
| 112 | } |
| 113 | break; |
| 114 | default: |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 115 | cout << "ERROR: Constant unimp for type: " << CPV->getType() << "\n"; |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 116 | } |
| 117 | return Result; |
| 118 | } else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) { |
| 119 | GlobalAddress *Address = |
| 120 | (GlobalAddress*)GV->getOrCreateAnnotation(GlobalAddressAID); |
| 121 | GenericValue Result; |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 122 | Result.PointerVal = (PointerTy)(GenericValue*)Address->Ptr; |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 123 | return Result; |
| 124 | } else { |
| 125 | unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 126 | unsigned OpSlot = getOperandSlot(V); |
| 127 | assert(TyP < SF.Values.size() && |
| 128 | OpSlot < SF.Values[TyP].size() && "Value out of range!"); |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 129 | return SF.Values[TyP][getOperandSlot(V)]; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | static void printOperandInfo(Value *V, ExecutionContext &SF) { |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 134 | if (isa<Constant>(V)) { |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 135 | cout << "Constant Pool Value\n"; |
| 136 | } else if (isa<GlobalValue>(V)) { |
| 137 | cout << "Global Value\n"; |
| 138 | } else { |
| 139 | unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value |
| 140 | unsigned Slot = getOperandSlot(V); |
| 141 | cout << "Value=" << (void*)V << " TypeID=" << TyP << " Slot=" << Slot |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 142 | << " Addr=" << &SF.Values[TyP][Slot] << " SF=" << &SF |
| 143 | << " Contents=0x"; |
| 144 | |
| 145 | const unsigned char *Buf = (const unsigned char*)&SF.Values[TyP][Slot]; |
| 146 | for (unsigned i = 0; i < sizeof(GenericValue); ++i) { |
| 147 | unsigned char Cur = Buf[i]; |
| 148 | cout << ( Cur >= 160? char((Cur>>4)+'A'-10) : char((Cur>>4) + '0')) |
| 149 | << ((Cur&15) >= 10? char((Cur&15)+'A'-10) : char((Cur&15) + '0')); |
| 150 | } |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 151 | cout << "\n"; |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 152 | } |
| 153 | } |
| 154 | |
| 155 | |
| 156 | |
| 157 | static void SetValue(Value *V, GenericValue Val, ExecutionContext &SF) { |
| 158 | unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value |
| 159 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 160 | //cout << "Setting value: " << &SF.Values[TyP][getOperandSlot(V)] << "\n"; |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 161 | SF.Values[TyP][getOperandSlot(V)] = Val; |
| 162 | } |
| 163 | |
| 164 | |
| 165 | //===----------------------------------------------------------------------===// |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 166 | // Annotation Wrangling code |
| 167 | //===----------------------------------------------------------------------===// |
| 168 | |
| 169 | void Interpreter::initializeExecutionEngine() { |
| 170 | AnnotationManager::registerAnnotationFactory(MethodInfoAID, |
| 171 | &MethodInfo::Create); |
| 172 | AnnotationManager::registerAnnotationFactory(GlobalAddressAID, |
| 173 | &GlobalAddress::Create); |
Chris Lattner | 5af0c48 | 2001-11-07 04:23:00 +0000 | [diff] [blame] | 174 | initializeSignalHandlers(); |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 177 | // InitializeMemory - Recursive function to apply a Constant value into the |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 178 | // specified memory location... |
| 179 | // |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 180 | static void InitializeMemory(const Constant *Init, char *Addr) { |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 181 | #define INITIALIZE_MEMORY(TYID, CLASS, TY) \ |
| 182 | case Type::TYID##TyID: { \ |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 183 | TY Tmp = cast<CLASS>(Init)->getValue(); \ |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 184 | memcpy(Addr, &Tmp, sizeof(TY)); \ |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 185 | } return |
| 186 | |
| 187 | switch (Init->getType()->getPrimitiveID()) { |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 188 | INITIALIZE_MEMORY(Bool , ConstantBool, bool); |
| 189 | INITIALIZE_MEMORY(UByte , ConstantUInt, unsigned char); |
| 190 | INITIALIZE_MEMORY(SByte , ConstantSInt, signed char); |
| 191 | INITIALIZE_MEMORY(UShort , ConstantUInt, unsigned short); |
| 192 | INITIALIZE_MEMORY(Short , ConstantSInt, signed short); |
| 193 | INITIALIZE_MEMORY(UInt , ConstantUInt, unsigned int); |
| 194 | INITIALIZE_MEMORY(Int , ConstantSInt, signed int); |
| 195 | INITIALIZE_MEMORY(ULong , ConstantUInt, uint64_t); |
| 196 | INITIALIZE_MEMORY(Long , ConstantSInt, int64_t); |
| 197 | INITIALIZE_MEMORY(Float , ConstantFP , float); |
| 198 | INITIALIZE_MEMORY(Double , ConstantFP , double); |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 199 | #undef INITIALIZE_MEMORY |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 200 | |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 201 | case Type::ArrayTyID: { |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 202 | const ConstantArray *CPA = cast<ConstantArray>(Init); |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 203 | const vector<Use> &Val = CPA->getValues(); |
| 204 | unsigned ElementSize = |
| 205 | TD.getTypeSize(cast<ArrayType>(CPA->getType())->getElementType()); |
| 206 | for (unsigned i = 0; i < Val.size(); ++i) |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 207 | InitializeMemory(cast<Constant>(Val[i].get()), Addr+i*ElementSize); |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 208 | return; |
| 209 | } |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 210 | |
| 211 | case Type::StructTyID: { |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 212 | const ConstantStruct *CPS = cast<ConstantStruct>(Init); |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 213 | const StructLayout *SL=TD.getStructLayout(cast<StructType>(CPS->getType())); |
| 214 | const vector<Use> &Val = CPS->getValues(); |
| 215 | for (unsigned i = 0; i < Val.size(); ++i) |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 216 | InitializeMemory(cast<Constant>(Val[i].get()), |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 217 | Addr+SL->MemberOffsets[i]); |
| 218 | return; |
| 219 | } |
| 220 | |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 221 | case Type::PointerTyID: |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 222 | if (isa<ConstantPointerNull>(Init)) { |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 223 | *(void**)Addr = 0; |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 224 | } else if (const ConstantPointerRef *CPR = |
| 225 | dyn_cast<ConstantPointerRef>(Init)) { |
Chris Lattner | 39bb5b4 | 2001-10-15 13:25:40 +0000 | [diff] [blame] | 226 | GlobalAddress *Address = |
| 227 | (GlobalAddress*)CPR->getValue()->getOrCreateAnnotation(GlobalAddressAID); |
| 228 | *(void**)Addr = (GenericValue*)Address->Ptr; |
| 229 | } else { |
| 230 | assert(0 && "Unknown Constant pointer type!"); |
| 231 | } |
| 232 | return; |
| 233 | |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 234 | default: |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 235 | CW << "Bad Type: " << Init->getType() << "\n"; |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 236 | assert(0 && "Unknown constant type to initialize memory with!"); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | Annotation *GlobalAddress::Create(AnnotationID AID, const Annotable *O, void *){ |
| 241 | assert(AID == GlobalAddressAID); |
| 242 | |
| 243 | // This annotation will only be created on GlobalValue objects... |
| 244 | GlobalValue *GVal = cast<GlobalValue>((Value*)O); |
| 245 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 246 | if (isa<Function>(GVal)) { |
| 247 | // The GlobalAddress object for a function is just a pointer to function |
| 248 | // itself. Don't delete it when the annotation is gone though! |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 249 | return new GlobalAddress(GVal, false); |
| 250 | } |
| 251 | |
| 252 | // Handle the case of a global variable... |
| 253 | assert(isa<GlobalVariable>(GVal) && |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 254 | "Global value found that isn't a function or global variable!"); |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 255 | GlobalVariable *GV = cast<GlobalVariable>(GVal); |
| 256 | |
| 257 | // First off, we must allocate space for the global variable to point at... |
Chris Lattner | 7a17675 | 2001-12-04 00:03:30 +0000 | [diff] [blame] | 258 | const Type *Ty = GV->getType()->getElementType(); // Type to be allocated |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 259 | |
| 260 | // Allocate enough memory to hold the type... |
Chris Lattner | f23eb85 | 2001-12-14 16:49:29 +0000 | [diff] [blame] | 261 | void *Addr = calloc(1, TD.getTypeSize(Ty)); |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 262 | assert(Addr != 0 && "Null pointer returned by malloc!"); |
| 263 | |
| 264 | // Initialize the memory if there is an initializer... |
| 265 | if (GV->hasInitializer()) |
| 266 | InitializeMemory(GV->getInitializer(), (char*)Addr); |
| 267 | |
| 268 | return new GlobalAddress(Addr, true); // Simply invoke the ctor |
| 269 | } |
| 270 | |
Chris Lattner | 2adcd83 | 2002-05-03 19:52:30 +0000 | [diff] [blame] | 271 | //===----------------------------------------------------------------------===// |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 272 | // Binary Instruction Implementations |
| 273 | //===----------------------------------------------------------------------===// |
| 274 | |
| 275 | #define IMPLEMENT_BINARY_OPERATOR(OP, TY) \ |
| 276 | case Type::TY##TyID: Dest.TY##Val = Src1.TY##Val OP Src2.TY##Val; break |
| 277 | |
| 278 | static GenericValue executeAddInst(GenericValue Src1, GenericValue Src2, |
| 279 | const Type *Ty, ExecutionContext &SF) { |
| 280 | GenericValue Dest; |
| 281 | switch (Ty->getPrimitiveID()) { |
| 282 | IMPLEMENT_BINARY_OPERATOR(+, UByte); |
| 283 | IMPLEMENT_BINARY_OPERATOR(+, SByte); |
| 284 | IMPLEMENT_BINARY_OPERATOR(+, UShort); |
| 285 | IMPLEMENT_BINARY_OPERATOR(+, Short); |
| 286 | IMPLEMENT_BINARY_OPERATOR(+, UInt); |
| 287 | IMPLEMENT_BINARY_OPERATOR(+, Int); |
Chris Lattner | 7b851ab | 2001-10-15 19:18:26 +0000 | [diff] [blame] | 288 | IMPLEMENT_BINARY_OPERATOR(+, ULong); |
| 289 | IMPLEMENT_BINARY_OPERATOR(+, Long); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 290 | IMPLEMENT_BINARY_OPERATOR(+, Float); |
| 291 | IMPLEMENT_BINARY_OPERATOR(+, Double); |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 292 | IMPLEMENT_BINARY_OPERATOR(+, Pointer); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 293 | default: |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 294 | cout << "Unhandled type for Add instruction: " << Ty << "\n"; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 295 | } |
| 296 | return Dest; |
| 297 | } |
| 298 | |
| 299 | static GenericValue executeSubInst(GenericValue Src1, GenericValue Src2, |
| 300 | const Type *Ty, ExecutionContext &SF) { |
| 301 | GenericValue Dest; |
| 302 | switch (Ty->getPrimitiveID()) { |
| 303 | IMPLEMENT_BINARY_OPERATOR(-, UByte); |
| 304 | IMPLEMENT_BINARY_OPERATOR(-, SByte); |
| 305 | IMPLEMENT_BINARY_OPERATOR(-, UShort); |
| 306 | IMPLEMENT_BINARY_OPERATOR(-, Short); |
| 307 | IMPLEMENT_BINARY_OPERATOR(-, UInt); |
| 308 | IMPLEMENT_BINARY_OPERATOR(-, Int); |
Chris Lattner | 7b851ab | 2001-10-15 19:18:26 +0000 | [diff] [blame] | 309 | IMPLEMENT_BINARY_OPERATOR(-, ULong); |
| 310 | IMPLEMENT_BINARY_OPERATOR(-, Long); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 311 | IMPLEMENT_BINARY_OPERATOR(-, Float); |
| 312 | IMPLEMENT_BINARY_OPERATOR(-, Double); |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 313 | IMPLEMENT_BINARY_OPERATOR(-, Pointer); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 314 | default: |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 315 | cout << "Unhandled type for Sub instruction: " << Ty << "\n"; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 316 | } |
| 317 | return Dest; |
| 318 | } |
| 319 | |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 320 | static GenericValue executeMulInst(GenericValue Src1, GenericValue Src2, |
| 321 | const Type *Ty, ExecutionContext &SF) { |
| 322 | GenericValue Dest; |
| 323 | switch (Ty->getPrimitiveID()) { |
| 324 | IMPLEMENT_BINARY_OPERATOR(*, UByte); |
| 325 | IMPLEMENT_BINARY_OPERATOR(*, SByte); |
| 326 | IMPLEMENT_BINARY_OPERATOR(*, UShort); |
| 327 | IMPLEMENT_BINARY_OPERATOR(*, Short); |
| 328 | IMPLEMENT_BINARY_OPERATOR(*, UInt); |
| 329 | IMPLEMENT_BINARY_OPERATOR(*, Int); |
| 330 | IMPLEMENT_BINARY_OPERATOR(*, ULong); |
| 331 | IMPLEMENT_BINARY_OPERATOR(*, Long); |
| 332 | IMPLEMENT_BINARY_OPERATOR(*, Float); |
| 333 | IMPLEMENT_BINARY_OPERATOR(*, Double); |
| 334 | IMPLEMENT_BINARY_OPERATOR(*, Pointer); |
| 335 | default: |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 336 | cout << "Unhandled type for Mul instruction: " << Ty << "\n"; |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 337 | } |
| 338 | return Dest; |
| 339 | } |
| 340 | |
| 341 | static GenericValue executeDivInst(GenericValue Src1, GenericValue Src2, |
| 342 | const Type *Ty, ExecutionContext &SF) { |
| 343 | GenericValue Dest; |
| 344 | switch (Ty->getPrimitiveID()) { |
| 345 | IMPLEMENT_BINARY_OPERATOR(/, UByte); |
| 346 | IMPLEMENT_BINARY_OPERATOR(/, SByte); |
| 347 | IMPLEMENT_BINARY_OPERATOR(/, UShort); |
| 348 | IMPLEMENT_BINARY_OPERATOR(/, Short); |
| 349 | IMPLEMENT_BINARY_OPERATOR(/, UInt); |
| 350 | IMPLEMENT_BINARY_OPERATOR(/, Int); |
| 351 | IMPLEMENT_BINARY_OPERATOR(/, ULong); |
| 352 | IMPLEMENT_BINARY_OPERATOR(/, Long); |
| 353 | IMPLEMENT_BINARY_OPERATOR(/, Float); |
| 354 | IMPLEMENT_BINARY_OPERATOR(/, Double); |
| 355 | IMPLEMENT_BINARY_OPERATOR(/, Pointer); |
| 356 | default: |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 357 | cout << "Unhandled type for Div instruction: " << Ty << "\n"; |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 358 | } |
| 359 | return Dest; |
| 360 | } |
| 361 | |
| 362 | static GenericValue executeRemInst(GenericValue Src1, GenericValue Src2, |
| 363 | const Type *Ty, ExecutionContext &SF) { |
| 364 | GenericValue Dest; |
| 365 | switch (Ty->getPrimitiveID()) { |
| 366 | IMPLEMENT_BINARY_OPERATOR(%, UByte); |
| 367 | IMPLEMENT_BINARY_OPERATOR(%, SByte); |
| 368 | IMPLEMENT_BINARY_OPERATOR(%, UShort); |
| 369 | IMPLEMENT_BINARY_OPERATOR(%, Short); |
| 370 | IMPLEMENT_BINARY_OPERATOR(%, UInt); |
| 371 | IMPLEMENT_BINARY_OPERATOR(%, Int); |
| 372 | IMPLEMENT_BINARY_OPERATOR(%, ULong); |
| 373 | IMPLEMENT_BINARY_OPERATOR(%, Long); |
| 374 | IMPLEMENT_BINARY_OPERATOR(%, Pointer); |
| 375 | case Type::FloatTyID: |
| 376 | Dest.FloatVal = fmod(Src1.FloatVal, Src2.FloatVal); |
| 377 | break; |
| 378 | case Type::DoubleTyID: |
| 379 | Dest.DoubleVal = fmod(Src1.DoubleVal, Src2.DoubleVal); |
| 380 | break; |
| 381 | default: |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 382 | cout << "Unhandled type for Rem instruction: " << Ty << "\n"; |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 383 | } |
| 384 | return Dest; |
| 385 | } |
| 386 | |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 387 | static GenericValue executeAndInst(GenericValue Src1, GenericValue Src2, |
Chris Lattner | 4d0e1f9 | 2001-10-30 20:54:36 +0000 | [diff] [blame] | 388 | const Type *Ty, ExecutionContext &SF) { |
| 389 | GenericValue Dest; |
| 390 | switch (Ty->getPrimitiveID()) { |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 391 | IMPLEMENT_BINARY_OPERATOR(&, UByte); |
| 392 | IMPLEMENT_BINARY_OPERATOR(&, SByte); |
| 393 | IMPLEMENT_BINARY_OPERATOR(&, UShort); |
| 394 | IMPLEMENT_BINARY_OPERATOR(&, Short); |
| 395 | IMPLEMENT_BINARY_OPERATOR(&, UInt); |
| 396 | IMPLEMENT_BINARY_OPERATOR(&, Int); |
| 397 | IMPLEMENT_BINARY_OPERATOR(&, ULong); |
| 398 | IMPLEMENT_BINARY_OPERATOR(&, Long); |
| 399 | IMPLEMENT_BINARY_OPERATOR(&, Pointer); |
| 400 | default: |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 401 | cout << "Unhandled type for And instruction: " << Ty << "\n"; |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 402 | } |
| 403 | return Dest; |
| 404 | } |
| 405 | |
| 406 | |
| 407 | static GenericValue executeOrInst(GenericValue Src1, GenericValue Src2, |
| 408 | const Type *Ty, ExecutionContext &SF) { |
| 409 | GenericValue Dest; |
| 410 | switch (Ty->getPrimitiveID()) { |
| 411 | IMPLEMENT_BINARY_OPERATOR(|, UByte); |
| 412 | IMPLEMENT_BINARY_OPERATOR(|, SByte); |
| 413 | IMPLEMENT_BINARY_OPERATOR(|, UShort); |
| 414 | IMPLEMENT_BINARY_OPERATOR(|, Short); |
| 415 | IMPLEMENT_BINARY_OPERATOR(|, UInt); |
| 416 | IMPLEMENT_BINARY_OPERATOR(|, Int); |
| 417 | IMPLEMENT_BINARY_OPERATOR(|, ULong); |
| 418 | IMPLEMENT_BINARY_OPERATOR(|, Long); |
| 419 | IMPLEMENT_BINARY_OPERATOR(|, Pointer); |
| 420 | default: |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 421 | cout << "Unhandled type for Or instruction: " << Ty << "\n"; |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 422 | } |
| 423 | return Dest; |
| 424 | } |
| 425 | |
| 426 | |
| 427 | static GenericValue executeXorInst(GenericValue Src1, GenericValue Src2, |
| 428 | const Type *Ty, ExecutionContext &SF) { |
| 429 | GenericValue Dest; |
| 430 | switch (Ty->getPrimitiveID()) { |
Chris Lattner | 4d0e1f9 | 2001-10-30 20:54:36 +0000 | [diff] [blame] | 431 | IMPLEMENT_BINARY_OPERATOR(^, UByte); |
| 432 | IMPLEMENT_BINARY_OPERATOR(^, SByte); |
| 433 | IMPLEMENT_BINARY_OPERATOR(^, UShort); |
| 434 | IMPLEMENT_BINARY_OPERATOR(^, Short); |
| 435 | IMPLEMENT_BINARY_OPERATOR(^, UInt); |
| 436 | IMPLEMENT_BINARY_OPERATOR(^, Int); |
| 437 | IMPLEMENT_BINARY_OPERATOR(^, ULong); |
| 438 | IMPLEMENT_BINARY_OPERATOR(^, Long); |
| 439 | IMPLEMENT_BINARY_OPERATOR(^, Pointer); |
| 440 | default: |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 441 | cout << "Unhandled type for Xor instruction: " << Ty << "\n"; |
Chris Lattner | 4d0e1f9 | 2001-10-30 20:54:36 +0000 | [diff] [blame] | 442 | } |
| 443 | return Dest; |
| 444 | } |
| 445 | |
| 446 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 447 | #define IMPLEMENT_SETCC(OP, TY) \ |
| 448 | case Type::TY##TyID: Dest.BoolVal = Src1.TY##Val OP Src2.TY##Val; break |
| 449 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 450 | static GenericValue executeSetEQInst(GenericValue Src1, GenericValue Src2, |
| 451 | const Type *Ty, ExecutionContext &SF) { |
| 452 | GenericValue Dest; |
| 453 | switch (Ty->getPrimitiveID()) { |
| 454 | IMPLEMENT_SETCC(==, UByte); |
| 455 | IMPLEMENT_SETCC(==, SByte); |
| 456 | IMPLEMENT_SETCC(==, UShort); |
| 457 | IMPLEMENT_SETCC(==, Short); |
| 458 | IMPLEMENT_SETCC(==, UInt); |
| 459 | IMPLEMENT_SETCC(==, Int); |
Chris Lattner | 7b851ab | 2001-10-15 19:18:26 +0000 | [diff] [blame] | 460 | IMPLEMENT_SETCC(==, ULong); |
| 461 | IMPLEMENT_SETCC(==, Long); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 462 | IMPLEMENT_SETCC(==, Float); |
| 463 | IMPLEMENT_SETCC(==, Double); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 464 | IMPLEMENT_SETCC(==, Pointer); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 465 | default: |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 466 | cout << "Unhandled type for SetEQ instruction: " << Ty << "\n"; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 467 | } |
| 468 | return Dest; |
| 469 | } |
| 470 | |
| 471 | static GenericValue executeSetNEInst(GenericValue Src1, GenericValue Src2, |
| 472 | const Type *Ty, ExecutionContext &SF) { |
| 473 | GenericValue Dest; |
| 474 | switch (Ty->getPrimitiveID()) { |
| 475 | IMPLEMENT_SETCC(!=, UByte); |
| 476 | IMPLEMENT_SETCC(!=, SByte); |
| 477 | IMPLEMENT_SETCC(!=, UShort); |
| 478 | IMPLEMENT_SETCC(!=, Short); |
| 479 | IMPLEMENT_SETCC(!=, UInt); |
| 480 | IMPLEMENT_SETCC(!=, Int); |
Chris Lattner | 7b851ab | 2001-10-15 19:18:26 +0000 | [diff] [blame] | 481 | IMPLEMENT_SETCC(!=, ULong); |
| 482 | IMPLEMENT_SETCC(!=, Long); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 483 | IMPLEMENT_SETCC(!=, Float); |
| 484 | IMPLEMENT_SETCC(!=, Double); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 485 | IMPLEMENT_SETCC(!=, Pointer); |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 486 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 487 | default: |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 488 | cout << "Unhandled type for SetNE instruction: " << Ty << "\n"; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 489 | } |
| 490 | return Dest; |
| 491 | } |
| 492 | |
| 493 | static GenericValue executeSetLEInst(GenericValue Src1, GenericValue Src2, |
| 494 | const Type *Ty, ExecutionContext &SF) { |
| 495 | GenericValue Dest; |
| 496 | switch (Ty->getPrimitiveID()) { |
| 497 | IMPLEMENT_SETCC(<=, UByte); |
| 498 | IMPLEMENT_SETCC(<=, SByte); |
| 499 | IMPLEMENT_SETCC(<=, UShort); |
| 500 | IMPLEMENT_SETCC(<=, Short); |
| 501 | IMPLEMENT_SETCC(<=, UInt); |
| 502 | IMPLEMENT_SETCC(<=, Int); |
Chris Lattner | 7b851ab | 2001-10-15 19:18:26 +0000 | [diff] [blame] | 503 | IMPLEMENT_SETCC(<=, ULong); |
| 504 | IMPLEMENT_SETCC(<=, Long); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 505 | IMPLEMENT_SETCC(<=, Float); |
| 506 | IMPLEMENT_SETCC(<=, Double); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 507 | IMPLEMENT_SETCC(<=, Pointer); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 508 | default: |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 509 | cout << "Unhandled type for SetLE instruction: " << Ty << "\n"; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 510 | } |
| 511 | return Dest; |
| 512 | } |
| 513 | |
| 514 | static GenericValue executeSetGEInst(GenericValue Src1, GenericValue Src2, |
| 515 | const Type *Ty, ExecutionContext &SF) { |
| 516 | GenericValue Dest; |
| 517 | switch (Ty->getPrimitiveID()) { |
| 518 | IMPLEMENT_SETCC(>=, UByte); |
| 519 | IMPLEMENT_SETCC(>=, SByte); |
| 520 | IMPLEMENT_SETCC(>=, UShort); |
| 521 | IMPLEMENT_SETCC(>=, Short); |
| 522 | IMPLEMENT_SETCC(>=, UInt); |
| 523 | IMPLEMENT_SETCC(>=, Int); |
Chris Lattner | 7b851ab | 2001-10-15 19:18:26 +0000 | [diff] [blame] | 524 | IMPLEMENT_SETCC(>=, ULong); |
| 525 | IMPLEMENT_SETCC(>=, Long); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 526 | IMPLEMENT_SETCC(>=, Float); |
| 527 | IMPLEMENT_SETCC(>=, Double); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 528 | IMPLEMENT_SETCC(>=, Pointer); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 529 | default: |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 530 | cout << "Unhandled type for SetGE instruction: " << Ty << "\n"; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 531 | } |
| 532 | return Dest; |
| 533 | } |
| 534 | |
| 535 | static GenericValue executeSetLTInst(GenericValue Src1, GenericValue Src2, |
| 536 | const Type *Ty, ExecutionContext &SF) { |
| 537 | GenericValue Dest; |
| 538 | switch (Ty->getPrimitiveID()) { |
| 539 | IMPLEMENT_SETCC(<, UByte); |
| 540 | IMPLEMENT_SETCC(<, SByte); |
| 541 | IMPLEMENT_SETCC(<, UShort); |
| 542 | IMPLEMENT_SETCC(<, Short); |
| 543 | IMPLEMENT_SETCC(<, UInt); |
| 544 | IMPLEMENT_SETCC(<, Int); |
Chris Lattner | 7b851ab | 2001-10-15 19:18:26 +0000 | [diff] [blame] | 545 | IMPLEMENT_SETCC(<, ULong); |
| 546 | IMPLEMENT_SETCC(<, Long); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 547 | IMPLEMENT_SETCC(<, Float); |
| 548 | IMPLEMENT_SETCC(<, Double); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 549 | IMPLEMENT_SETCC(<, Pointer); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 550 | default: |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 551 | cout << "Unhandled type for SetLT instruction: " << Ty << "\n"; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 552 | } |
| 553 | return Dest; |
| 554 | } |
| 555 | |
| 556 | static GenericValue executeSetGTInst(GenericValue Src1, GenericValue Src2, |
| 557 | const Type *Ty, ExecutionContext &SF) { |
| 558 | GenericValue Dest; |
| 559 | switch (Ty->getPrimitiveID()) { |
| 560 | IMPLEMENT_SETCC(>, UByte); |
| 561 | IMPLEMENT_SETCC(>, SByte); |
| 562 | IMPLEMENT_SETCC(>, UShort); |
| 563 | IMPLEMENT_SETCC(>, Short); |
| 564 | IMPLEMENT_SETCC(>, UInt); |
| 565 | IMPLEMENT_SETCC(>, Int); |
Chris Lattner | 7b851ab | 2001-10-15 19:18:26 +0000 | [diff] [blame] | 566 | IMPLEMENT_SETCC(>, ULong); |
| 567 | IMPLEMENT_SETCC(>, Long); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 568 | IMPLEMENT_SETCC(>, Float); |
| 569 | IMPLEMENT_SETCC(>, Double); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 570 | IMPLEMENT_SETCC(>, Pointer); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 571 | default: |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 572 | cout << "Unhandled type for SetGT instruction: " << Ty << "\n"; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 573 | } |
| 574 | return Dest; |
| 575 | } |
| 576 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 577 | static void executeBinaryInst(BinaryOperator &I, ExecutionContext &SF) { |
| 578 | const Type *Ty = I.getOperand(0)->getType(); |
| 579 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 580 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 581 | GenericValue R; // Result |
| 582 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 583 | switch (I.getOpcode()) { |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 584 | case Instruction::Add: R = executeAddInst (Src1, Src2, Ty, SF); break; |
| 585 | case Instruction::Sub: R = executeSubInst (Src1, Src2, Ty, SF); break; |
| 586 | case Instruction::Mul: R = executeMulInst (Src1, Src2, Ty, SF); break; |
| 587 | case Instruction::Div: R = executeDivInst (Src1, Src2, Ty, SF); break; |
| 588 | case Instruction::Rem: R = executeRemInst (Src1, Src2, Ty, SF); break; |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 589 | case Instruction::And: R = executeAndInst (Src1, Src2, Ty, SF); break; |
| 590 | case Instruction::Or: R = executeOrInst (Src1, Src2, Ty, SF); break; |
Chris Lattner | 4d0e1f9 | 2001-10-30 20:54:36 +0000 | [diff] [blame] | 591 | case Instruction::Xor: R = executeXorInst (Src1, Src2, Ty, SF); break; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 592 | case Instruction::SetEQ: R = executeSetEQInst(Src1, Src2, Ty, SF); break; |
| 593 | case Instruction::SetNE: R = executeSetNEInst(Src1, Src2, Ty, SF); break; |
| 594 | case Instruction::SetLE: R = executeSetLEInst(Src1, Src2, Ty, SF); break; |
| 595 | case Instruction::SetGE: R = executeSetGEInst(Src1, Src2, Ty, SF); break; |
| 596 | case Instruction::SetLT: R = executeSetLTInst(Src1, Src2, Ty, SF); break; |
| 597 | case Instruction::SetGT: R = executeSetGTInst(Src1, Src2, Ty, SF); break; |
| 598 | default: |
| 599 | cout << "Don't know how to handle this binary operator!\n-->" << I; |
Chris Lattner | 4d0e1f9 | 2001-10-30 20:54:36 +0000 | [diff] [blame] | 600 | R = Src1; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 601 | } |
| 602 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 603 | SetValue(&I, R, SF); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 604 | } |
| 605 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 606 | //===----------------------------------------------------------------------===// |
| 607 | // Terminator Instruction Implementations |
| 608 | //===----------------------------------------------------------------------===// |
| 609 | |
Chris Lattner | a95c699 | 2001-11-12 16:28:48 +0000 | [diff] [blame] | 610 | static void PerformExitStuff() { |
| 611 | #ifdef PROFILE_STRUCTURE_FIELDS |
| 612 | // Print out structure field accounting information... |
| 613 | if (!FieldAccessCounts.empty()) { |
Chris Lattner | 84efe09 | 2001-11-12 20:13:14 +0000 | [diff] [blame] | 614 | CW << "Profile Field Access Counts:\n"; |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 615 | std::map<const StructType *, vector<unsigned> >::iterator |
Chris Lattner | a95c699 | 2001-11-12 16:28:48 +0000 | [diff] [blame] | 616 | I = FieldAccessCounts.begin(), E = FieldAccessCounts.end(); |
| 617 | for (; I != E; ++I) { |
| 618 | vector<unsigned> &OfC = I->second; |
| 619 | CW << " '" << (Value*)I->first << "'\t- Sum="; |
| 620 | |
| 621 | unsigned Sum = 0; |
| 622 | for (unsigned i = 0; i < OfC.size(); ++i) |
| 623 | Sum += OfC[i]; |
| 624 | CW << Sum << " - "; |
| 625 | |
| 626 | for (unsigned i = 0; i < OfC.size(); ++i) { |
| 627 | if (i) CW << ", "; |
| 628 | CW << OfC[i]; |
| 629 | } |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 630 | CW << "\n"; |
Chris Lattner | a95c699 | 2001-11-12 16:28:48 +0000 | [diff] [blame] | 631 | } |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 632 | CW << "\n"; |
Chris Lattner | 84efe09 | 2001-11-12 20:13:14 +0000 | [diff] [blame] | 633 | |
| 634 | CW << "Profile Field Access Percentages:\n"; |
| 635 | cout.precision(3); |
| 636 | for (I = FieldAccessCounts.begin(); I != E; ++I) { |
| 637 | vector<unsigned> &OfC = I->second; |
| 638 | unsigned Sum = 0; |
| 639 | for (unsigned i = 0; i < OfC.size(); ++i) |
| 640 | Sum += OfC[i]; |
| 641 | |
| 642 | CW << " '" << (Value*)I->first << "'\t- "; |
| 643 | for (unsigned i = 0; i < OfC.size(); ++i) { |
| 644 | if (i) CW << ", "; |
| 645 | CW << double(OfC[i])/Sum; |
| 646 | } |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 647 | CW << "\n"; |
Chris Lattner | 84efe09 | 2001-11-12 20:13:14 +0000 | [diff] [blame] | 648 | } |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 649 | CW << "\n"; |
Chris Lattner | 84efe09 | 2001-11-12 20:13:14 +0000 | [diff] [blame] | 650 | |
Chris Lattner | a95c699 | 2001-11-12 16:28:48 +0000 | [diff] [blame] | 651 | FieldAccessCounts.clear(); |
| 652 | } |
| 653 | #endif |
| 654 | } |
| 655 | |
Chris Lattner | e43db88 | 2001-10-27 04:15:57 +0000 | [diff] [blame] | 656 | void Interpreter::exitCalled(GenericValue GV) { |
Chris Lattner | f23eb85 | 2001-12-14 16:49:29 +0000 | [diff] [blame] | 657 | if (!QuietMode) { |
| 658 | cout << "Program returned "; |
| 659 | print(Type::IntTy, GV); |
| 660 | cout << " via 'void exit(int)'\n"; |
| 661 | } |
Chris Lattner | e43db88 | 2001-10-27 04:15:57 +0000 | [diff] [blame] | 662 | |
| 663 | ExitCode = GV.SByteVal; |
| 664 | ECStack.clear(); |
Chris Lattner | a95c699 | 2001-11-12 16:28:48 +0000 | [diff] [blame] | 665 | PerformExitStuff(); |
Chris Lattner | e43db88 | 2001-10-27 04:15:57 +0000 | [diff] [blame] | 666 | } |
| 667 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 668 | void Interpreter::executeRetInst(ReturnInst &I, ExecutionContext &SF) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 669 | const Type *RetTy = 0; |
| 670 | GenericValue Result; |
| 671 | |
| 672 | // Save away the return value... (if we are not 'ret void') |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 673 | if (I.getNumOperands()) { |
| 674 | RetTy = I.getReturnValue()->getType(); |
| 675 | Result = getOperandValue(I.getReturnValue(), SF); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | // Save previously executing meth |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 679 | const Function *M = ECStack.back().CurMethod; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 680 | |
| 681 | // Pop the current stack frame... this invalidates SF |
| 682 | ECStack.pop_back(); |
| 683 | |
| 684 | if (ECStack.empty()) { // Finished main. Put result into exit code... |
| 685 | if (RetTy) { // Nonvoid return type? |
Chris Lattner | f23eb85 | 2001-12-14 16:49:29 +0000 | [diff] [blame] | 686 | if (!QuietMode) { |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 687 | CW << "Function " << M->getType() << " \"" << M->getName() |
Chris Lattner | f23eb85 | 2001-12-14 16:49:29 +0000 | [diff] [blame] | 688 | << "\" returned "; |
| 689 | print(RetTy, Result); |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 690 | cout << "\n"; |
Chris Lattner | f23eb85 | 2001-12-14 16:49:29 +0000 | [diff] [blame] | 691 | } |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 692 | |
| 693 | if (RetTy->isIntegral()) |
Chris Lattner | f4dca80 | 2002-05-02 19:28:45 +0000 | [diff] [blame] | 694 | ExitCode = Result.IntVal; // Capture the exit code of the program |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 695 | } else { |
| 696 | ExitCode = 0; |
| 697 | } |
Chris Lattner | e240906 | 2001-11-12 16:19:45 +0000 | [diff] [blame] | 698 | |
Chris Lattner | a95c699 | 2001-11-12 16:28:48 +0000 | [diff] [blame] | 699 | PerformExitStuff(); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 700 | return; |
| 701 | } |
| 702 | |
| 703 | // If we have a previous stack frame, and we have a previous call, fill in |
| 704 | // the return value... |
| 705 | // |
| 706 | ExecutionContext &NewSF = ECStack.back(); |
| 707 | if (NewSF.Caller) { |
| 708 | if (NewSF.Caller->getType() != Type::VoidTy) // Save result... |
| 709 | SetValue(NewSF.Caller, Result, NewSF); |
| 710 | |
| 711 | NewSF.Caller = 0; // We returned from the call... |
Chris Lattner | f23eb85 | 2001-12-14 16:49:29 +0000 | [diff] [blame] | 712 | } else if (!QuietMode) { |
Chris Lattner | 365a76e | 2001-09-10 04:49:44 +0000 | [diff] [blame] | 713 | // This must be a function that is executing because of a user 'call' |
| 714 | // instruction. |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 715 | CW << "Function " << M->getType() << " \"" << M->getName() |
Chris Lattner | 5af0c48 | 2001-11-07 04:23:00 +0000 | [diff] [blame] | 716 | << "\" returned "; |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 717 | print(RetTy, Result); |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 718 | cout << "\n"; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 722 | void Interpreter::executeBrInst(BranchInst &I, ExecutionContext &SF) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 723 | SF.PrevBB = SF.CurBB; // Update PrevBB so that PHI nodes work... |
| 724 | BasicBlock *Dest; |
| 725 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 726 | Dest = I.getSuccessor(0); // Uncond branches have a fixed dest... |
| 727 | if (!I.isUnconditional()) { |
| 728 | Value *Cond = I.getCondition(); |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 729 | GenericValue CondVal = getOperandValue(Cond, SF); |
| 730 | if (CondVal.BoolVal == 0) // If false cond... |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 731 | Dest = I.getSuccessor(1); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 732 | } |
| 733 | SF.CurBB = Dest; // Update CurBB to branch destination |
| 734 | SF.CurInst = SF.CurBB->begin(); // Update new instruction ptr... |
| 735 | } |
| 736 | |
| 737 | //===----------------------------------------------------------------------===// |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 738 | // Memory Instruction Implementations |
| 739 | //===----------------------------------------------------------------------===// |
| 740 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 741 | void Interpreter::executeAllocInst(AllocationInst &I, ExecutionContext &SF) { |
| 742 | const Type *Ty = I.getType()->getElementType(); // Type to be allocated |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 743 | |
Chris Lattner | cc82cc1 | 2002-04-28 21:57:33 +0000 | [diff] [blame] | 744 | // Get the number of elements being allocated by the array... |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 745 | unsigned NumElements = getOperandValue(I.getOperand(0), SF).UIntVal; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 746 | |
| 747 | // Allocate enough memory to hold the type... |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 748 | // FIXME: Don't use CALLOC, use a tainted malloc. |
Chris Lattner | 9bffa73 | 2002-02-19 18:50:09 +0000 | [diff] [blame] | 749 | void *Memory = calloc(NumElements, TD.getTypeSize(Ty)); |
| 750 | |
| 751 | GenericValue Result; |
| 752 | Result.PointerVal = (PointerTy)Memory; |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 753 | assert(Result.PointerVal != 0 && "Null pointer returned by malloc!"); |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 754 | SetValue(&I, Result, SF); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 755 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 756 | if (I.getOpcode() == Instruction::Alloca) |
Chris Lattner | 9bffa73 | 2002-02-19 18:50:09 +0000 | [diff] [blame] | 757 | ECStack.back().Allocas.add(Memory); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 758 | } |
| 759 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 760 | static void executeFreeInst(FreeInst &I, ExecutionContext &SF) { |
| 761 | assert(isa<PointerType>(I.getOperand(0)->getType()) && "Freeing nonptr?"); |
| 762 | GenericValue Value = getOperandValue(I.getOperand(0), SF); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 763 | // TODO: Check to make sure memory is allocated |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 764 | free((void*)Value.PointerVal); // Free memory |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 765 | } |
| 766 | |
Chris Lattner | 95c3af5 | 2001-10-29 19:32:19 +0000 | [diff] [blame] | 767 | |
Chris Lattner | 24ea74e | 2002-08-22 22:49:05 +0000 | [diff] [blame] | 768 | // getElementOffset - The workhorse for getelementptr. This function returns |
| 769 | // the offset that arguments ArgOff+1 -> NumArgs specify for the pointer type |
| 770 | // specified by argument Arg. |
Chris Lattner | 95c3af5 | 2001-10-29 19:32:19 +0000 | [diff] [blame] | 771 | // |
Chris Lattner | cc63f1c | 2002-08-22 23:37:20 +0000 | [diff] [blame^] | 772 | static PointerTy getElementOffset(GetElementPtrInst &I, ExecutionContext &SF) { |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 773 | assert(isa<PointerType>(I.getPointerOperand()->getType()) && |
Chris Lattner | 95c3af5 | 2001-10-29 19:32:19 +0000 | [diff] [blame] | 774 | "Cannot getElementOffset of a nonpointer type!"); |
| 775 | |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 776 | PointerTy Total = 0; |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 777 | const Type *Ty = I.getPointerOperand()->getType(); |
Chris Lattner | 95c3af5 | 2001-10-29 19:32:19 +0000 | [diff] [blame] | 778 | |
Chris Lattner | cc63f1c | 2002-08-22 23:37:20 +0000 | [diff] [blame^] | 779 | unsigned ArgOff = 1; |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 780 | while (ArgOff < I.getNumOperands()) { |
Chris Lattner | 782b939 | 2001-11-26 18:18:18 +0000 | [diff] [blame] | 781 | if (const StructType *STy = dyn_cast<StructType>(Ty)) { |
| 782 | const StructLayout *SLO = TD.getStructLayout(STy); |
| 783 | |
| 784 | // Indicies must be ubyte constants... |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 785 | const ConstantUInt *CPU = cast<ConstantUInt>(I.getOperand(ArgOff++)); |
Chris Lattner | 782b939 | 2001-11-26 18:18:18 +0000 | [diff] [blame] | 786 | assert(CPU->getType() == Type::UByteTy); |
| 787 | unsigned Index = CPU->getValue(); |
| 788 | |
Chris Lattner | e240906 | 2001-11-12 16:19:45 +0000 | [diff] [blame] | 789 | #ifdef PROFILE_STRUCTURE_FIELDS |
Chris Lattner | 782b939 | 2001-11-26 18:18:18 +0000 | [diff] [blame] | 790 | if (ProfileStructureFields) { |
| 791 | // Do accounting for this field... |
| 792 | vector<unsigned> &OfC = FieldAccessCounts[STy]; |
| 793 | if (OfC.size() == 0) OfC.resize(STy->getElementTypes().size()); |
| 794 | OfC[Index]++; |
| 795 | } |
Chris Lattner | e240906 | 2001-11-12 16:19:45 +0000 | [diff] [blame] | 796 | #endif |
Chris Lattner | 782b939 | 2001-11-26 18:18:18 +0000 | [diff] [blame] | 797 | |
| 798 | Total += SLO->MemberOffsets[Index]; |
| 799 | Ty = STy->getElementTypes()[Index]; |
Chris Lattner | f23eb85 | 2001-12-14 16:49:29 +0000 | [diff] [blame] | 800 | } else if (const SequentialType *ST = cast<SequentialType>(Ty)) { |
Chris Lattner | e240906 | 2001-11-12 16:19:45 +0000 | [diff] [blame] | 801 | |
Chris Lattner | 782b939 | 2001-11-26 18:18:18 +0000 | [diff] [blame] | 802 | // Get the index number for the array... which must be uint type... |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 803 | assert(I.getOperand(ArgOff)->getType() == Type::UIntTy); |
| 804 | unsigned Idx = getOperandValue(I.getOperand(ArgOff++), SF).UIntVal; |
Chris Lattner | f23eb85 | 2001-12-14 16:49:29 +0000 | [diff] [blame] | 805 | if (const ArrayType *AT = dyn_cast<ArrayType>(ST)) |
Chris Lattner | c0fbd57 | 2002-02-11 20:19:16 +0000 | [diff] [blame] | 806 | if (Idx >= AT->getNumElements() && ArrayChecksEnabled) { |
Chris Lattner | f23eb85 | 2001-12-14 16:49:29 +0000 | [diff] [blame] | 807 | cerr << "Out of range memory access to element #" << Idx |
| 808 | << " of a " << AT->getNumElements() << " element array." |
Chris Lattner | cc63f1c | 2002-08-22 23:37:20 +0000 | [diff] [blame^] | 809 | << " Subscript #" << (ArgOff-1) << "\n"; |
Chris Lattner | f23eb85 | 2001-12-14 16:49:29 +0000 | [diff] [blame] | 810 | // Get outta here!!! |
Chris Lattner | 7403025 | 2002-02-12 15:47:23 +0000 | [diff] [blame] | 811 | siglongjmp(SignalRecoverBuffer, SIGTRAP); |
Chris Lattner | f23eb85 | 2001-12-14 16:49:29 +0000 | [diff] [blame] | 812 | } |
Chris Lattner | 782b939 | 2001-11-26 18:18:18 +0000 | [diff] [blame] | 813 | |
Chris Lattner | f23eb85 | 2001-12-14 16:49:29 +0000 | [diff] [blame] | 814 | Ty = ST->getElementType(); |
Chris Lattner | 782b939 | 2001-11-26 18:18:18 +0000 | [diff] [blame] | 815 | unsigned Size = TD.getTypeSize(Ty); |
| 816 | Total += Size*Idx; |
| 817 | } |
Chris Lattner | 95c3af5 | 2001-10-29 19:32:19 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | return Total; |
| 821 | } |
| 822 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 823 | static void executeGEPInst(GetElementPtrInst &I, ExecutionContext &SF) { |
| 824 | GenericValue SRC = getOperandValue(I.getPointerOperand(), SF); |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 825 | PointerTy SrcPtr = SRC.PointerVal; |
Chris Lattner | 95c3af5 | 2001-10-29 19:32:19 +0000 | [diff] [blame] | 826 | |
| 827 | GenericValue Result; |
Chris Lattner | 782b939 | 2001-11-26 18:18:18 +0000 | [diff] [blame] | 828 | Result.PointerVal = SrcPtr + getElementOffset(I, SF); |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 829 | SetValue(&I, Result, SF); |
Chris Lattner | 95c3af5 | 2001-10-29 19:32:19 +0000 | [diff] [blame] | 830 | } |
| 831 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 832 | static void executeLoadInst(LoadInst &I, ExecutionContext &SF) { |
| 833 | GenericValue SRC = getOperandValue(I.getPointerOperand(), SF); |
Chris Lattner | 24ea74e | 2002-08-22 22:49:05 +0000 | [diff] [blame] | 834 | GenericValue *Ptr = (GenericValue*)SRC.PointerVal; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 835 | GenericValue Result; |
| 836 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 837 | switch (I.getType()->getPrimitiveID()) { |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 838 | case Type::BoolTyID: |
| 839 | case Type::UByteTyID: |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 840 | case Type::SByteTyID: Result.SByteVal = Ptr->SByteVal; break; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 841 | case Type::UShortTyID: |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 842 | case Type::ShortTyID: Result.ShortVal = Ptr->ShortVal; break; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 843 | case Type::UIntTyID: |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 844 | case Type::IntTyID: Result.IntVal = Ptr->IntVal; break; |
Chris Lattner | 7b851ab | 2001-10-15 19:18:26 +0000 | [diff] [blame] | 845 | case Type::ULongTyID: |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 846 | case Type::LongTyID: Result.ULongVal = Ptr->ULongVal; break; |
| 847 | case Type::PointerTyID: Result.PointerVal = Ptr->PointerVal; break; |
| 848 | case Type::FloatTyID: Result.FloatVal = Ptr->FloatVal; break; |
| 849 | case Type::DoubleTyID: Result.DoubleVal = Ptr->DoubleVal; break; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 850 | default: |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 851 | cout << "Cannot load value of type " << I.getType() << "!\n"; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 852 | } |
| 853 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 854 | SetValue(&I, Result, SF); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 855 | } |
| 856 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 857 | static void executeStoreInst(StoreInst &I, ExecutionContext &SF) { |
| 858 | GenericValue SRC = getOperandValue(I.getPointerOperand(), SF); |
Chris Lattner | 24ea74e | 2002-08-22 22:49:05 +0000 | [diff] [blame] | 859 | GenericValue *Ptr = (GenericValue *)SRC.PointerVal; |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 860 | GenericValue Val = getOperandValue(I.getOperand(0), SF); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 861 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 862 | switch (I.getOperand(0)->getType()->getPrimitiveID()) { |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 863 | case Type::BoolTyID: |
| 864 | case Type::UByteTyID: |
| 865 | case Type::SByteTyID: Ptr->SByteVal = Val.SByteVal; break; |
| 866 | case Type::UShortTyID: |
| 867 | case Type::ShortTyID: Ptr->ShortVal = Val.ShortVal; break; |
| 868 | case Type::UIntTyID: |
| 869 | case Type::IntTyID: Ptr->IntVal = Val.IntVal; break; |
Chris Lattner | 7b851ab | 2001-10-15 19:18:26 +0000 | [diff] [blame] | 870 | case Type::ULongTyID: |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 871 | case Type::LongTyID: Ptr->LongVal = Val.LongVal; break; |
| 872 | case Type::PointerTyID: Ptr->PointerVal = Val.PointerVal; break; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 873 | case Type::FloatTyID: Ptr->FloatVal = Val.FloatVal; break; |
| 874 | case Type::DoubleTyID: Ptr->DoubleVal = Val.DoubleVal; break; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 875 | default: |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 876 | cout << "Cannot store value of type " << I.getType() << "!\n"; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 877 | } |
| 878 | } |
| 879 | |
| 880 | |
| 881 | //===----------------------------------------------------------------------===// |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 882 | // Miscellaneous Instruction Implementations |
| 883 | //===----------------------------------------------------------------------===// |
| 884 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 885 | void Interpreter::executeCallInst(CallInst &I, ExecutionContext &SF) { |
| 886 | ECStack.back().Caller = &I; |
Chris Lattner | 365a76e | 2001-09-10 04:49:44 +0000 | [diff] [blame] | 887 | vector<GenericValue> ArgVals; |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 888 | ArgVals.reserve(I.getNumOperands()-1); |
| 889 | for (unsigned i = 1; i < I.getNumOperands(); ++i) |
| 890 | ArgVals.push_back(getOperandValue(I.getOperand(i), SF)); |
Chris Lattner | 365a76e | 2001-09-10 04:49:44 +0000 | [diff] [blame] | 891 | |
Chris Lattner | 070cf5e | 2001-11-07 20:12:30 +0000 | [diff] [blame] | 892 | // To handle indirect calls, we must get the pointer value from the argument |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 893 | // and treat it as a function pointer. |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 894 | GenericValue SRC = getOperandValue(I.getCalledValue(), SF); |
Chris Lattner | 070cf5e | 2001-11-07 20:12:30 +0000 | [diff] [blame] | 895 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 896 | callMethod((Function*)SRC.PointerVal, ArgVals); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 897 | } |
| 898 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 899 | static void executePHINode(PHINode &I, ExecutionContext &SF) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 900 | BasicBlock *PrevBB = SF.PrevBB; |
| 901 | Value *IncomingValue = 0; |
| 902 | |
| 903 | // Search for the value corresponding to this previous bb... |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 904 | for (unsigned i = I.getNumIncomingValues(); i > 0;) { |
| 905 | if (I.getIncomingBlock(--i) == PrevBB) { |
| 906 | IncomingValue = I.getIncomingValue(i); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 907 | break; |
| 908 | } |
| 909 | } |
| 910 | assert(IncomingValue && "No PHI node predecessor for current PrevBB!"); |
| 911 | |
| 912 | // Found the value, set as the result... |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 913 | SetValue(&I, getOperandValue(IncomingValue, SF), SF); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 914 | } |
| 915 | |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 916 | #define IMPLEMENT_SHIFT(OP, TY) \ |
| 917 | case Type::TY##TyID: Dest.TY##Val = Src1.TY##Val OP Src2.UByteVal; break |
| 918 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 919 | static void executeShlInst(ShiftInst &I, ExecutionContext &SF) { |
| 920 | const Type *Ty = I.getOperand(0)->getType(); |
| 921 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 922 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 923 | GenericValue Dest; |
| 924 | |
| 925 | switch (Ty->getPrimitiveID()) { |
| 926 | IMPLEMENT_SHIFT(<<, UByte); |
| 927 | IMPLEMENT_SHIFT(<<, SByte); |
| 928 | IMPLEMENT_SHIFT(<<, UShort); |
| 929 | IMPLEMENT_SHIFT(<<, Short); |
| 930 | IMPLEMENT_SHIFT(<<, UInt); |
| 931 | IMPLEMENT_SHIFT(<<, Int); |
Chris Lattner | 7b851ab | 2001-10-15 19:18:26 +0000 | [diff] [blame] | 932 | IMPLEMENT_SHIFT(<<, ULong); |
| 933 | IMPLEMENT_SHIFT(<<, Long); |
Chris Lattner | 743cd3e | 2002-07-09 18:42:36 +0000 | [diff] [blame] | 934 | IMPLEMENT_SHIFT(<<, Pointer); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 935 | default: |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 936 | cout << "Unhandled type for Shl instruction: " << Ty << "\n"; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 937 | } |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 938 | SetValue(&I, Dest, SF); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 939 | } |
| 940 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 941 | static void executeShrInst(ShiftInst &I, ExecutionContext &SF) { |
| 942 | const Type *Ty = I.getOperand(0)->getType(); |
| 943 | GenericValue Src1 = getOperandValue(I.getOperand(0), SF); |
| 944 | GenericValue Src2 = getOperandValue(I.getOperand(1), SF); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 945 | GenericValue Dest; |
| 946 | |
| 947 | switch (Ty->getPrimitiveID()) { |
| 948 | IMPLEMENT_SHIFT(>>, UByte); |
| 949 | IMPLEMENT_SHIFT(>>, SByte); |
| 950 | IMPLEMENT_SHIFT(>>, UShort); |
| 951 | IMPLEMENT_SHIFT(>>, Short); |
| 952 | IMPLEMENT_SHIFT(>>, UInt); |
| 953 | IMPLEMENT_SHIFT(>>, Int); |
Chris Lattner | 7b851ab | 2001-10-15 19:18:26 +0000 | [diff] [blame] | 954 | IMPLEMENT_SHIFT(>>, ULong); |
| 955 | IMPLEMENT_SHIFT(>>, Long); |
Chris Lattner | 743cd3e | 2002-07-09 18:42:36 +0000 | [diff] [blame] | 956 | IMPLEMENT_SHIFT(>>, Pointer); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 957 | default: |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 958 | cout << "Unhandled type for Shr instruction: " << Ty << "\n"; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 959 | } |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 960 | SetValue(&I, Dest, SF); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | #define IMPLEMENT_CAST(DTY, DCTY, STY) \ |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 964 | case Type::STY##TyID: Dest.DTY##Val = DCTY Src.STY##Val; break; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 965 | |
| 966 | #define IMPLEMENT_CAST_CASE_START(DESTTY, DESTCTY) \ |
| 967 | case Type::DESTTY##TyID: \ |
| 968 | switch (SrcTy->getPrimitiveID()) { \ |
Chris Lattner | f4dca80 | 2002-05-02 19:28:45 +0000 | [diff] [blame] | 969 | IMPLEMENT_CAST(DESTTY, DESTCTY, Bool); \ |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 970 | IMPLEMENT_CAST(DESTTY, DESTCTY, UByte); \ |
| 971 | IMPLEMENT_CAST(DESTTY, DESTCTY, SByte); \ |
| 972 | IMPLEMENT_CAST(DESTTY, DESTCTY, UShort); \ |
| 973 | IMPLEMENT_CAST(DESTTY, DESTCTY, Short); \ |
| 974 | IMPLEMENT_CAST(DESTTY, DESTCTY, UInt); \ |
Chris Lattner | 7b851ab | 2001-10-15 19:18:26 +0000 | [diff] [blame] | 975 | IMPLEMENT_CAST(DESTTY, DESTCTY, Int); \ |
| 976 | IMPLEMENT_CAST(DESTTY, DESTCTY, ULong); \ |
Chris Lattner | c259316 | 2001-10-27 08:28:11 +0000 | [diff] [blame] | 977 | IMPLEMENT_CAST(DESTTY, DESTCTY, Long); \ |
| 978 | IMPLEMENT_CAST(DESTTY, DESTCTY, Pointer); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 979 | |
| 980 | #define IMPLEMENT_CAST_CASE_FP_IMP(DESTTY, DESTCTY) \ |
| 981 | IMPLEMENT_CAST(DESTTY, DESTCTY, Float); \ |
| 982 | IMPLEMENT_CAST(DESTTY, DESTCTY, Double) |
| 983 | |
| 984 | #define IMPLEMENT_CAST_CASE_END() \ |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 985 | default: cout << "Unhandled cast: " << SrcTy << " to " << Ty << "\n"; \ |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 986 | break; \ |
| 987 | } \ |
| 988 | break |
| 989 | |
| 990 | #define IMPLEMENT_CAST_CASE(DESTTY, DESTCTY) \ |
| 991 | IMPLEMENT_CAST_CASE_START(DESTTY, DESTCTY); \ |
| 992 | IMPLEMENT_CAST_CASE_FP_IMP(DESTTY, DESTCTY); \ |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 993 | IMPLEMENT_CAST_CASE_END() |
| 994 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 995 | static void executeCastInst(CastInst &I, ExecutionContext &SF) { |
| 996 | const Type *Ty = I.getType(); |
| 997 | const Type *SrcTy = I.getOperand(0)->getType(); |
| 998 | GenericValue Src = getOperandValue(I.getOperand(0), SF); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 999 | GenericValue Dest; |
| 1000 | |
| 1001 | switch (Ty->getPrimitiveID()) { |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 1002 | IMPLEMENT_CAST_CASE(UByte , (unsigned char)); |
| 1003 | IMPLEMENT_CAST_CASE(SByte , ( signed char)); |
| 1004 | IMPLEMENT_CAST_CASE(UShort , (unsigned short)); |
Chris Lattner | 1bbd361 | 2002-08-02 22:06:04 +0000 | [diff] [blame] | 1005 | IMPLEMENT_CAST_CASE(Short , ( signed short)); |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 1006 | IMPLEMENT_CAST_CASE(UInt , (unsigned int )); |
| 1007 | IMPLEMENT_CAST_CASE(Int , ( signed int )); |
| 1008 | IMPLEMENT_CAST_CASE(ULong , (uint64_t)); |
| 1009 | IMPLEMENT_CAST_CASE(Long , ( int64_t)); |
| 1010 | IMPLEMENT_CAST_CASE(Pointer, (PointerTy)(uint32_t)); |
| 1011 | IMPLEMENT_CAST_CASE(Float , (float)); |
| 1012 | IMPLEMENT_CAST_CASE(Double , (double)); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1013 | default: |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1014 | cout << "Unhandled dest type for cast instruction: " << Ty << "\n"; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1015 | } |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1016 | SetValue(&I, Dest, SF); |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1017 | } |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1018 | |
| 1019 | |
| 1020 | |
| 1021 | |
| 1022 | //===----------------------------------------------------------------------===// |
| 1023 | // Dispatch and Execution Code |
| 1024 | //===----------------------------------------------------------------------===// |
| 1025 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1026 | MethodInfo::MethodInfo(Function *F) : Annotation(MethodInfoAID) { |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 1027 | // Assign slot numbers to the function arguments... |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1028 | for (Function::const_aiterator AI = F->abegin(), E = F->aend(); AI != E; ++AI) |
| 1029 | AI->addAnnotation(new SlotNumber(getValueSlot(AI))); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1030 | |
| 1031 | // Iterate over all of the instructions... |
| 1032 | unsigned InstNum = 0; |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1033 | for (Function::iterator BB = F->begin(), BBE = F->end(); BB != BBE; ++BB) |
| 1034 | for (BasicBlock::iterator II = BB->begin(), IE = BB->end(); II != IE; ++II) |
| 1035 | // For each instruction... Add Annote |
| 1036 | II->addAnnotation(new InstNumber(++InstNum, getValueSlot(II))); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | unsigned MethodInfo::getValueSlot(const Value *V) { |
| 1040 | unsigned Plane = V->getType()->getUniqueID(); |
| 1041 | if (Plane >= NumPlaneElements.size()) |
| 1042 | NumPlaneElements.resize(Plane+1, 0); |
| 1043 | return NumPlaneElements[Plane]++; |
| 1044 | } |
| 1045 | |
| 1046 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1047 | //===----------------------------------------------------------------------===// |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 1048 | // callMethod - Execute the specified function... |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1049 | // |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 1050 | void Interpreter::callMethod(Function *M, const vector<GenericValue> &ArgVals) { |
Chris Lattner | 365a76e | 2001-09-10 04:49:44 +0000 | [diff] [blame] | 1051 | assert((ECStack.empty() || ECStack.back().Caller == 0 || |
| 1052 | ECStack.back().Caller->getNumOperands()-1 == ArgVals.size()) && |
| 1053 | "Incorrect number of arguments passed into function call!"); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1054 | if (M->isExternal()) { |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 1055 | GenericValue Result = callExternalMethod(M, ArgVals); |
| 1056 | const Type *RetTy = M->getReturnType(); |
| 1057 | |
| 1058 | // Copy the result back into the result variable if we are not returning |
| 1059 | // void. |
| 1060 | if (RetTy != Type::VoidTy) { |
| 1061 | if (!ECStack.empty() && ECStack.back().Caller) { |
| 1062 | ExecutionContext &SF = ECStack.back(); |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 1063 | SetValue(SF.Caller, Result, SF); |
| 1064 | |
| 1065 | SF.Caller = 0; // We returned from the call... |
Chris Lattner | f23eb85 | 2001-12-14 16:49:29 +0000 | [diff] [blame] | 1066 | } else if (!QuietMode) { |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 1067 | // print it. |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 1068 | CW << "Function " << M->getType() << " \"" << M->getName() |
Chris Lattner | 5af0c48 | 2001-11-07 04:23:00 +0000 | [diff] [blame] | 1069 | << "\" returned "; |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 1070 | print(RetTy, Result); |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1071 | cout << "\n"; |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 1072 | |
| 1073 | if (RetTy->isIntegral()) |
| 1074 | ExitCode = Result.SByteVal; // Capture the exit code of the program |
| 1075 | } |
| 1076 | } |
| 1077 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1078 | return; |
| 1079 | } |
| 1080 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 1081 | // Process the function, assigning instruction numbers to the instructions in |
| 1082 | // the function. Also calculate the number of values for each type slot |
| 1083 | // active. |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1084 | // |
| 1085 | MethodInfo *MethInfo = (MethodInfo*)M->getOrCreateAnnotation(MethodInfoAID); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1086 | ECStack.push_back(ExecutionContext()); // Make a new stack frame... |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1087 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1088 | ExecutionContext &StackFrame = ECStack.back(); // Fill it in... |
| 1089 | StackFrame.CurMethod = M; |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1090 | StackFrame.CurBB = M->begin(); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1091 | StackFrame.CurInst = StackFrame.CurBB->begin(); |
| 1092 | StackFrame.MethInfo = MethInfo; |
| 1093 | |
| 1094 | // Initialize the values to nothing... |
| 1095 | StackFrame.Values.resize(MethInfo->NumPlaneElements.size()); |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 1096 | for (unsigned i = 0; i < MethInfo->NumPlaneElements.size(); ++i) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1097 | StackFrame.Values[i].resize(MethInfo->NumPlaneElements[i]); |
| 1098 | |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 1099 | // Taint the initial values of stuff |
| 1100 | memset(&StackFrame.Values[i][0], 42, |
| 1101 | MethInfo->NumPlaneElements[i]*sizeof(GenericValue)); |
| 1102 | } |
| 1103 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1104 | StackFrame.PrevBB = 0; // No previous BB for PHI nodes... |
| 1105 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1106 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 1107 | // Run through the function arguments and initialize their values... |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1108 | assert(ArgVals.size() == M->asize() && |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 1109 | "Invalid number of values passed to function invocation!"); |
Chris Lattner | 365a76e | 2001-09-10 04:49:44 +0000 | [diff] [blame] | 1110 | unsigned i = 0; |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1111 | for (Function::aiterator AI = M->abegin(), E = M->aend(); AI != E; ++AI, ++i) |
| 1112 | SetValue(AI, ArgVals[i], StackFrame); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | // executeInstruction - Interpret a single instruction, increment the "PC", and |
| 1116 | // return true if the next instruction is a breakpoint... |
| 1117 | // |
| 1118 | bool Interpreter::executeInstruction() { |
| 1119 | assert(!ECStack.empty() && "No program running, cannot execute inst!"); |
| 1120 | |
| 1121 | ExecutionContext &SF = ECStack.back(); // Current stack frame |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1122 | Instruction &I = *SF.CurInst++; // Increment before execute |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1123 | |
Chris Lattner | 43e3f7c | 2001-10-27 08:43:52 +0000 | [diff] [blame] | 1124 | if (Trace) |
Chris Lattner | 5af0c48 | 2001-11-07 04:23:00 +0000 | [diff] [blame] | 1125 | CW << "Run:" << I; |
| 1126 | |
| 1127 | // Set a sigsetjmp buffer so that we can recover if an error happens during |
| 1128 | // instruction execution... |
| 1129 | // |
| 1130 | if (int SigNo = sigsetjmp(SignalRecoverBuffer, 1)) { |
| 1131 | --SF.CurInst; // Back up to erroring instruction |
Chris Lattner | 7403025 | 2002-02-12 15:47:23 +0000 | [diff] [blame] | 1132 | if (SigNo != SIGINT) { |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 1133 | cout << "EXCEPTION OCCURRED [" << _sys_siglistp[SigNo] << "]:\n"; |
Chris Lattner | 461f02f | 2001-11-07 05:31:27 +0000 | [diff] [blame] | 1134 | printStackTrace(); |
Chris Lattner | 7403025 | 2002-02-12 15:47:23 +0000 | [diff] [blame] | 1135 | // If -abort-on-exception was specified, terminate LLI instead of trying |
| 1136 | // to debug it. |
| 1137 | // |
| 1138 | if (AbortOnExceptions) exit(1); |
Chris Lattner | 782b939 | 2001-11-26 18:18:18 +0000 | [diff] [blame] | 1139 | } else if (SigNo == SIGINT) { |
Chris Lattner | 461f02f | 2001-11-07 05:31:27 +0000 | [diff] [blame] | 1140 | cout << "CTRL-C Detected, execution halted.\n"; |
| 1141 | } |
| 1142 | InInstruction = false; |
Chris Lattner | 5af0c48 | 2001-11-07 04:23:00 +0000 | [diff] [blame] | 1143 | return true; |
| 1144 | } |
Chris Lattner | 43e3f7c | 2001-10-27 08:43:52 +0000 | [diff] [blame] | 1145 | |
Chris Lattner | 461f02f | 2001-11-07 05:31:27 +0000 | [diff] [blame] | 1146 | InInstruction = true; |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1147 | if (I.isBinaryOp()) { |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 1148 | executeBinaryInst(cast<BinaryOperator>(I), SF); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1149 | } else { |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1150 | switch (I.getOpcode()) { |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1151 | // Terminators |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 1152 | case Instruction::Ret: executeRetInst (cast<ReturnInst>(I), SF); break; |
| 1153 | case Instruction::Br: executeBrInst (cast<BranchInst>(I), SF); break; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1154 | // Memory Instructions |
| 1155 | case Instruction::Alloca: |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1156 | case Instruction::Malloc: executeAllocInst((AllocationInst&)I, SF); break; |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 1157 | case Instruction::Free: executeFreeInst (cast<FreeInst> (I), SF); break; |
| 1158 | case Instruction::Load: executeLoadInst (cast<LoadInst> (I), SF); break; |
| 1159 | case Instruction::Store: executeStoreInst(cast<StoreInst>(I), SF); break; |
Chris Lattner | 95c3af5 | 2001-10-29 19:32:19 +0000 | [diff] [blame] | 1160 | case Instruction::GetElementPtr: |
| 1161 | executeGEPInst(cast<GetElementPtrInst>(I), SF); break; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1162 | |
| 1163 | // Miscellaneous Instructions |
Chris Lattner | bb76f02 | 2001-10-30 20:27:31 +0000 | [diff] [blame] | 1164 | case Instruction::Call: executeCallInst (cast<CallInst> (I), SF); break; |
| 1165 | case Instruction::PHINode: executePHINode (cast<PHINode> (I), SF); break; |
| 1166 | case Instruction::Shl: executeShlInst (cast<ShiftInst>(I), SF); break; |
| 1167 | case Instruction::Shr: executeShrInst (cast<ShiftInst>(I), SF); break; |
| 1168 | case Instruction::Cast: executeCastInst (cast<CastInst> (I), SF); break; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1169 | default: |
| 1170 | cout << "Don't know how to execute this instruction!\n-->" << I; |
| 1171 | } |
| 1172 | } |
Chris Lattner | 461f02f | 2001-11-07 05:31:27 +0000 | [diff] [blame] | 1173 | InInstruction = false; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1174 | |
| 1175 | // Reset the current frame location to the top of stack |
| 1176 | CurFrame = ECStack.size()-1; |
| 1177 | |
| 1178 | if (CurFrame == -1) return false; // No breakpoint if no code |
| 1179 | |
| 1180 | // Return true if there is a breakpoint annotation on the instruction... |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1181 | return ECStack[CurFrame].CurInst->getAnnotation(BreakpointAID) != 0; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | void Interpreter::stepInstruction() { // Do the 'step' command |
| 1185 | if (ECStack.empty()) { |
| 1186 | cout << "Error: no program running, cannot step!\n"; |
| 1187 | return; |
| 1188 | } |
| 1189 | |
| 1190 | // Run an instruction... |
| 1191 | executeInstruction(); |
| 1192 | |
| 1193 | // Print the next instruction to execute... |
| 1194 | printCurrentInstruction(); |
| 1195 | } |
| 1196 | |
| 1197 | // --- UI Stuff... |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1198 | void Interpreter::nextInstruction() { // Do the 'next' command |
| 1199 | if (ECStack.empty()) { |
| 1200 | cout << "Error: no program running, cannot 'next'!\n"; |
| 1201 | return; |
| 1202 | } |
| 1203 | |
| 1204 | // If this is a call instruction, step over the call instruction... |
| 1205 | // TODO: ICALL, CALL WITH, ... |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1206 | if (ECStack.back().CurInst->getOpcode() == Instruction::Call) { |
Chris Lattner | a74a6b5 | 2001-10-29 14:08:33 +0000 | [diff] [blame] | 1207 | unsigned StackSize = ECStack.size(); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1208 | // Step into the function... |
| 1209 | if (executeInstruction()) { |
| 1210 | // Hit a breakpoint, print current instruction, then return to user... |
| 1211 | cout << "Breakpoint hit!\n"; |
| 1212 | printCurrentInstruction(); |
| 1213 | return; |
| 1214 | } |
| 1215 | |
Chris Lattner | a74a6b5 | 2001-10-29 14:08:33 +0000 | [diff] [blame] | 1216 | // If we we able to step into the function, finish it now. We might not be |
| 1217 | // able the step into a function, if it's external for example. |
| 1218 | if (ECStack.size() != StackSize) |
| 1219 | finish(); // Finish executing the function... |
Chris Lattner | 069aa25 | 2001-10-29 16:05:19 +0000 | [diff] [blame] | 1220 | else |
| 1221 | printCurrentInstruction(); |
Chris Lattner | a74a6b5 | 2001-10-29 14:08:33 +0000 | [diff] [blame] | 1222 | |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1223 | } else { |
| 1224 | // Normal instruction, just step... |
| 1225 | stepInstruction(); |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | void Interpreter::run() { |
| 1230 | if (ECStack.empty()) { |
| 1231 | cout << "Error: no program running, cannot run!\n"; |
| 1232 | return; |
| 1233 | } |
| 1234 | |
| 1235 | bool HitBreakpoint = false; |
| 1236 | while (!ECStack.empty() && !HitBreakpoint) { |
| 1237 | // Run an instruction... |
| 1238 | HitBreakpoint = executeInstruction(); |
| 1239 | } |
| 1240 | |
| 1241 | if (HitBreakpoint) { |
| 1242 | cout << "Breakpoint hit!\n"; |
| 1243 | } |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1244 | // Print the next instruction to execute... |
| 1245 | printCurrentInstruction(); |
| 1246 | } |
| 1247 | |
| 1248 | void Interpreter::finish() { |
| 1249 | if (ECStack.empty()) { |
| 1250 | cout << "Error: no program running, cannot run!\n"; |
| 1251 | return; |
| 1252 | } |
| 1253 | |
| 1254 | unsigned StackSize = ECStack.size(); |
| 1255 | bool HitBreakpoint = false; |
| 1256 | while (ECStack.size() >= StackSize && !HitBreakpoint) { |
| 1257 | // Run an instruction... |
| 1258 | HitBreakpoint = executeInstruction(); |
| 1259 | } |
| 1260 | |
| 1261 | if (HitBreakpoint) { |
| 1262 | cout << "Breakpoint hit!\n"; |
| 1263 | } |
| 1264 | |
| 1265 | // Print the next instruction to execute... |
| 1266 | printCurrentInstruction(); |
| 1267 | } |
| 1268 | |
| 1269 | |
| 1270 | |
| 1271 | // printCurrentInstruction - Print out the instruction that the virtual PC is |
| 1272 | // at, or fail silently if no program is running. |
| 1273 | // |
| 1274 | void Interpreter::printCurrentInstruction() { |
| 1275 | if (!ECStack.empty()) { |
Chris Lattner | f5b2ec1 | 2001-10-29 20:44:34 +0000 | [diff] [blame] | 1276 | if (ECStack.back().CurBB->begin() == ECStack.back().CurInst) // print label |
| 1277 | WriteAsOperand(cout, ECStack.back().CurBB) << ":\n"; |
| 1278 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1279 | Instruction &I = *ECStack.back().CurInst; |
| 1280 | InstNumber *IN = (InstNumber*)I.getAnnotation(SlotNumberAID); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1281 | assert(IN && "Instruction has no numbering annotation!"); |
| 1282 | cout << "#" << IN->InstNum << I; |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | void Interpreter::printValue(const Type *Ty, GenericValue V) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1287 | switch (Ty->getPrimitiveID()) { |
| 1288 | case Type::BoolTyID: cout << (V.BoolVal?"true":"false"); break; |
Chris Lattner | 65629d5 | 2002-08-13 20:45:11 +0000 | [diff] [blame] | 1289 | case Type::SByteTyID: |
| 1290 | cout << (int)V.SByteVal << " '" << V.SByteVal << "'"; break; |
| 1291 | case Type::UByteTyID: |
| 1292 | cout << (unsigned)V.UByteVal << " '" << V.UByteVal << "'"; break; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1293 | case Type::ShortTyID: cout << V.ShortVal; break; |
| 1294 | case Type::UShortTyID: cout << V.UShortVal; break; |
| 1295 | case Type::IntTyID: cout << V.IntVal; break; |
| 1296 | case Type::UIntTyID: cout << V.UIntVal; break; |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1297 | case Type::LongTyID: cout << (long)V.LongVal; break; |
| 1298 | case Type::ULongTyID: cout << (unsigned long)V.ULongVal; break; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1299 | case Type::FloatTyID: cout << V.FloatVal; break; |
| 1300 | case Type::DoubleTyID: cout << V.DoubleVal; break; |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 1301 | case Type::PointerTyID:cout << (void*)V.PointerVal; break; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1302 | default: |
| 1303 | cout << "- Don't know how to print value of this type!"; |
| 1304 | break; |
| 1305 | } |
| 1306 | } |
| 1307 | |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 1308 | void Interpreter::print(const Type *Ty, GenericValue V) { |
Chris Lattner | 5af0c48 | 2001-11-07 04:23:00 +0000 | [diff] [blame] | 1309 | CW << Ty << " "; |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 1310 | printValue(Ty, V); |
| 1311 | } |
| 1312 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1313 | void Interpreter::print(const std::string &Name) { |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1314 | Value *PickedVal = ChooseOneOption(Name, LookupMatchingNames(Name)); |
| 1315 | if (!PickedVal) return; |
| 1316 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 1317 | if (const Function *F = dyn_cast<const Function>(PickedVal)) { |
| 1318 | CW << F; // Print the function |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 1319 | } else if (const Type *Ty = dyn_cast<const Type>(PickedVal)) { |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1320 | CW << "type %" << Name << " = " << Ty->getDescription() << "\n"; |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 1321 | } else if (const BasicBlock *BB = dyn_cast<const BasicBlock>(PickedVal)) { |
| 1322 | CW << BB; // Print the basic block |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1323 | } else { // Otherwise there should be an annotation for the slot# |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 1324 | print(PickedVal->getType(), |
| 1325 | getOperandValue(PickedVal, ECStack[CurFrame])); |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1326 | cout << "\n"; |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1327 | } |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1328 | } |
| 1329 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1330 | void Interpreter::infoValue(const std::string &Name) { |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1331 | Value *PickedVal = ChooseOneOption(Name, LookupMatchingNames(Name)); |
| 1332 | if (!PickedVal) return; |
| 1333 | |
| 1334 | cout << "Value: "; |
Chris Lattner | 2e42d3a | 2001-10-15 05:51:48 +0000 | [diff] [blame] | 1335 | print(PickedVal->getType(), |
| 1336 | getOperandValue(PickedVal, ECStack[CurFrame])); |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1337 | cout << "\n"; |
Chris Lattner | 8666098 | 2001-08-27 05:16:50 +0000 | [diff] [blame] | 1338 | printOperandInfo(PickedVal, ECStack[CurFrame]); |
| 1339 | } |
| 1340 | |
Chris Lattner | 461f02f | 2001-11-07 05:31:27 +0000 | [diff] [blame] | 1341 | // printStackFrame - Print information about the specified stack frame, or -1 |
| 1342 | // for the default one. |
| 1343 | // |
Chris Lattner | 601d715 | 2002-07-25 17:37:05 +0000 | [diff] [blame] | 1344 | void Interpreter::printStackFrame(int FrameNo) { |
Chris Lattner | 461f02f | 2001-11-07 05:31:27 +0000 | [diff] [blame] | 1345 | if (FrameNo == -1) FrameNo = CurFrame; |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1346 | Function *F = ECStack[FrameNo].CurMethod; |
| 1347 | const Type *RetTy = F->getReturnType(); |
Chris Lattner | ea38c0e | 2001-11-07 19:46:27 +0000 | [diff] [blame] | 1348 | |
| 1349 | CW << ((FrameNo == CurFrame) ? '>' : '-') << "#" << FrameNo << ". " |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1350 | << (Value*)RetTy << " \"" << F->getName() << "\"("; |
Chris Lattner | 461f02f | 2001-11-07 05:31:27 +0000 | [diff] [blame] | 1351 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1352 | unsigned i = 0; |
| 1353 | for (Function::aiterator I = F->abegin(), E = F->aend(); I != E; ++I, ++i) { |
Chris Lattner | 461f02f | 2001-11-07 05:31:27 +0000 | [diff] [blame] | 1354 | if (i != 0) cout << ", "; |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1355 | CW << *I << "="; |
Chris Lattner | 461f02f | 2001-11-07 05:31:27 +0000 | [diff] [blame] | 1356 | |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1357 | printValue(I->getType(), getOperandValue(I, ECStack[FrameNo])); |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1358 | } |
Chris Lattner | 461f02f | 2001-11-07 05:31:27 +0000 | [diff] [blame] | 1359 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1360 | cout << ")\n"; |
Chris Lattner | 0b12b5f | 2002-06-25 16:13:21 +0000 | [diff] [blame] | 1361 | |
| 1362 | if (FrameNo != int(ECStack.size()-1)) { |
| 1363 | BasicBlock::iterator I = ECStack[FrameNo].CurInst; |
| 1364 | CW << --I; |
| 1365 | } else { |
| 1366 | CW << *ECStack[FrameNo].CurInst; |
| 1367 | } |
Chris Lattner | 92101ac | 2001-08-23 17:05:04 +0000 | [diff] [blame] | 1368 | } |
Chris Lattner | 461f02f | 2001-11-07 05:31:27 +0000 | [diff] [blame] | 1369 | |