blob: d11ed6e5218f01d895315b8e622bde9c6d9e9403 [file] [log] [blame]
Chris Lattner92101ac2001-08-23 17:05:04 +00001//===-- 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 Lattner7061dc52001-12-03 18:02:31 +00009#include "llvm/iPHINode.h"
Chris Lattner92101ac2001-08-23 17:05:04 +000010#include "llvm/iOther.h"
11#include "llvm/iTerminators.h"
Chris Lattner86660982001-08-27 05:16:50 +000012#include "llvm/iMemory.h"
Chris Lattnere2cbbce2002-04-29 18:56:45 +000013#include "llvm/DerivedTypes.h"
Chris Lattner31bcdb82002-04-28 19:55:58 +000014#include "llvm/Constants.h"
Chris Lattner92101ac2001-08-23 17:05:04 +000015#include "llvm/Assembly/Writer.h"
Chris Lattner41c2e5c2001-09-28 22:56:43 +000016#include "llvm/Target/TargetData.h"
Chris Lattnerf23eb852001-12-14 16:49:29 +000017#include "Support/CommandLine.h"
Chris Lattnerbb76f022001-10-30 20:27:31 +000018#include <math.h> // For fmod
Chris Lattner5af0c482001-11-07 04:23:00 +000019#include <signal.h>
20#include <setjmp.h>
Chris Lattner697954c2002-01-20 22:54:45 +000021using std::vector;
22using std::cout;
23using std::cerr;
Chris Lattner2e42d3a2001-10-15 05:51:48 +000024
Chris Lattner5ff62e92002-07-22 02:10:13 +000025static cl::opt<bool>
26QuietMode("quiet", cl::desc("Do not emit any non-program output"));
27
28static cl::alias
29QuietModeA("q", cl::desc("Alias for -quiet"), cl::aliasopt(QuietMode));
30
31static cl::opt<bool>
32ArrayChecksEnabled("array-checks", cl::desc("Enable array bound checks"));
33
34static cl::opt<bool>
35AbortOnExceptions("abort-on-exception",
36 cl::desc("Halt execution on a machine exception"));
Chris Lattnere9bb2df2001-12-03 22:26:30 +000037
Chris Lattner2e42d3a2001-10-15 05:51:48 +000038// Create a TargetData structure to handle memory addressing and size/alignment
39// computations
40//
Chris Lattnerdbaf74d2002-10-02 21:10:48 +000041TargetData TD("lli Interpreter");
Chris Lattnerea38c0e2001-11-07 19:46:27 +000042CachedWriter CW; // Object to accelerate printing of LLVM
Chris Lattner5af0c482001-11-07 04:23:00 +000043
44
Chris Lattnere2409062001-11-12 16:19:45 +000045#ifdef PROFILE_STRUCTURE_FIELDS
Chris Lattner5ff62e92002-07-22 02:10:13 +000046static cl::opt<bool>
47ProfileStructureFields("profilestructfields",
48 cl::desc("Profile Structure Field Accesses"));
Chris Lattnere2409062001-11-12 16:19:45 +000049#include <map>
Chris Lattner697954c2002-01-20 22:54:45 +000050static std::map<const StructType *, vector<unsigned> > FieldAccessCounts;
Chris Lattnere2409062001-11-12 16:19:45 +000051#endif
52
Chris Lattner5af0c482001-11-07 04:23:00 +000053sigjmp_buf SignalRecoverBuffer;
Chris Lattner461f02f2001-11-07 05:31:27 +000054static bool InInstruction = false;
Chris Lattner5af0c482001-11-07 04:23:00 +000055
56extern "C" {
57static void SigHandler(int Signal) {
Chris Lattner461f02f2001-11-07 05:31:27 +000058 if (InInstruction)
59 siglongjmp(SignalRecoverBuffer, Signal);
Chris Lattner5af0c482001-11-07 04:23:00 +000060}
61}
62
63static void initializeSignalHandlers() {
64 struct sigaction Action;
65 Action.sa_handler = SigHandler;
66 Action.sa_flags = SA_SIGINFO;
67 sigemptyset(&Action.sa_mask);
68 sigaction(SIGSEGV, &Action, 0);
69 sigaction(SIGBUS, &Action, 0);
Chris Lattner461f02f2001-11-07 05:31:27 +000070 sigaction(SIGINT, &Action, 0);
Chris Lattnerea38c0e2001-11-07 19:46:27 +000071 sigaction(SIGFPE, &Action, 0);
Chris Lattner5af0c482001-11-07 04:23:00 +000072}
73
Chris Lattner2e42d3a2001-10-15 05:51:48 +000074
75//===----------------------------------------------------------------------===//
Chris Lattner39bb5b42001-10-15 13:25:40 +000076// Value Manipulation code
77//===----------------------------------------------------------------------===//
78
79static unsigned getOperandSlot(Value *V) {
80 SlotNumber *SN = (SlotNumber*)V->getAnnotation(SlotNumberAID);
81 assert(SN && "Operand does not have a slot number annotation!");
82 return SN->SlotNum;
83}
84
85#define GET_CONST_VAL(TY, CLASS) \
Chris Lattnerfddc7552002-10-15 20:34:05 +000086 case Type::TY##TyID: Result.TY##Val = cast<CLASS>(C)->getValue(); break
Chris Lattner39bb5b42001-10-15 13:25:40 +000087
Chris Lattnera34c5682002-08-27 22:33:45 +000088// Operations used by constant expr implementations...
89static GenericValue executeCastOperation(Value *Src, const Type *DestTy,
90 ExecutionContext &SF);
91static GenericValue executeGEPOperation(Value *Src, User::op_iterator IdxBegin,
92 User::op_iterator IdxEnd,
93 ExecutionContext &SF);
94static GenericValue executeAddInst(GenericValue Src1, GenericValue Src2,
95 const Type *Ty, ExecutionContext &SF);
96
Chris Lattnerfddc7552002-10-15 20:34:05 +000097static GenericValue getConstantValue(const Constant *C) {
98 GenericValue Result;
99 switch (C->getType()->getPrimitiveID()) {
100 GET_CONST_VAL(Bool , ConstantBool);
101 GET_CONST_VAL(UByte , ConstantUInt);
102 GET_CONST_VAL(SByte , ConstantSInt);
103 GET_CONST_VAL(UShort , ConstantUInt);
104 GET_CONST_VAL(Short , ConstantSInt);
105 GET_CONST_VAL(UInt , ConstantUInt);
106 GET_CONST_VAL(Int , ConstantSInt);
107 GET_CONST_VAL(ULong , ConstantUInt);
108 GET_CONST_VAL(Long , ConstantSInt);
109 GET_CONST_VAL(Float , ConstantFP);
110 GET_CONST_VAL(Double , ConstantFP);
111 case Type::PointerTyID:
112 if (isa<ConstantPointerNull>(C)) {
113 Result.PointerVal = 0;
114 } else if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(C)){
115 GlobalAddress *Address =
116 (GlobalAddress*)CPR->getValue()->getOrCreateAnnotation(GlobalAddressAID);
117 Result.PointerVal = (PointerTy)Address->Ptr;
118 } else {
119 assert(0 && "Unknown constant pointer type!");
120 }
121 break;
122 default:
123 cout << "ERROR: Constant unimp for type: " << C->getType() << "\n";
124 }
125 return Result;
126}
127
Chris Lattner39bb5b42001-10-15 13:25:40 +0000128static GenericValue getOperandValue(Value *V, ExecutionContext &SF) {
Chris Lattnera34c5682002-08-27 22:33:45 +0000129 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
130 switch (CE->getOpcode()) {
131 case Instruction::Cast:
132 return executeCastOperation(CE->getOperand(0), CE->getType(), SF);
133 case Instruction::GetElementPtr:
134 return executeGEPOperation(CE->getOperand(0), CE->op_begin()+1,
135 CE->op_end(), SF);
136 case Instruction::Add:
137 return executeAddInst(getOperandValue(CE->getOperand(0), SF),
138 getOperandValue(CE->getOperand(1), SF),
139 CE->getType(), SF);
140 default:
141 cerr << "Unhandled ConstantExpr: " << CE << "\n";
142 abort();
143 { GenericValue V; return V; }
144 }
145 } else if (Constant *CPV = dyn_cast<Constant>(V)) {
Chris Lattnerfddc7552002-10-15 20:34:05 +0000146 return getConstantValue(CPV);
Chris Lattner39bb5b42001-10-15 13:25:40 +0000147 } else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
148 GlobalAddress *Address =
149 (GlobalAddress*)GV->getOrCreateAnnotation(GlobalAddressAID);
150 GenericValue Result;
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000151 Result.PointerVal = (PointerTy)(GenericValue*)Address->Ptr;
Chris Lattner39bb5b42001-10-15 13:25:40 +0000152 return Result;
153 } else {
154 unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value
Chris Lattnerbb76f022001-10-30 20:27:31 +0000155 unsigned OpSlot = getOperandSlot(V);
156 assert(TyP < SF.Values.size() &&
157 OpSlot < SF.Values[TyP].size() && "Value out of range!");
Chris Lattner39bb5b42001-10-15 13:25:40 +0000158 return SF.Values[TyP][getOperandSlot(V)];
159 }
160}
161
162static void printOperandInfo(Value *V, ExecutionContext &SF) {
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000163 if (isa<Constant>(V)) {
Chris Lattner39bb5b42001-10-15 13:25:40 +0000164 cout << "Constant Pool Value\n";
165 } else if (isa<GlobalValue>(V)) {
166 cout << "Global Value\n";
167 } else {
168 unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value
169 unsigned Slot = getOperandSlot(V);
170 cout << "Value=" << (void*)V << " TypeID=" << TyP << " Slot=" << Slot
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000171 << " Addr=" << &SF.Values[TyP][Slot] << " SF=" << &SF
172 << " Contents=0x";
173
174 const unsigned char *Buf = (const unsigned char*)&SF.Values[TyP][Slot];
175 for (unsigned i = 0; i < sizeof(GenericValue); ++i) {
176 unsigned char Cur = Buf[i];
177 cout << ( Cur >= 160? char((Cur>>4)+'A'-10) : char((Cur>>4) + '0'))
178 << ((Cur&15) >= 10? char((Cur&15)+'A'-10) : char((Cur&15) + '0'));
179 }
Chris Lattner697954c2002-01-20 22:54:45 +0000180 cout << "\n";
Chris Lattner39bb5b42001-10-15 13:25:40 +0000181 }
182}
183
184
185
186static void SetValue(Value *V, GenericValue Val, ExecutionContext &SF) {
187 unsigned TyP = V->getType()->getUniqueID(); // TypePlane for value
188
Chris Lattner697954c2002-01-20 22:54:45 +0000189 //cout << "Setting value: " << &SF.Values[TyP][getOperandSlot(V)] << "\n";
Chris Lattner39bb5b42001-10-15 13:25:40 +0000190 SF.Values[TyP][getOperandSlot(V)] = Val;
191}
192
193
194//===----------------------------------------------------------------------===//
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000195// Annotation Wrangling code
196//===----------------------------------------------------------------------===//
197
198void Interpreter::initializeExecutionEngine() {
199 AnnotationManager::registerAnnotationFactory(MethodInfoAID,
200 &MethodInfo::Create);
201 AnnotationManager::registerAnnotationFactory(GlobalAddressAID,
202 &GlobalAddress::Create);
Chris Lattner5af0c482001-11-07 04:23:00 +0000203 initializeSignalHandlers();
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000204}
205
Chris Lattnerfddc7552002-10-15 20:34:05 +0000206static void StoreValueToMemory(GenericValue Val, GenericValue *Ptr,
207 const Type *Ty);
208
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000209// InitializeMemory - Recursive function to apply a Constant value into the
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000210// specified memory location...
211//
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000212static void InitializeMemory(const Constant *Init, char *Addr) {
Chris Lattnerfddc7552002-10-15 20:34:05 +0000213
214 if (Init->getType()->isFirstClassType()) {
215 GenericValue Val = getConstantValue(Init);
216 StoreValueToMemory(Val, (GenericValue*)Addr, Init->getType());
217 return;
218 }
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000219
220 switch (Init->getType()->getPrimitiveID()) {
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000221 case Type::ArrayTyID: {
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000222 const ConstantArray *CPA = cast<ConstantArray>(Init);
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000223 const vector<Use> &Val = CPA->getValues();
224 unsigned ElementSize =
225 TD.getTypeSize(cast<ArrayType>(CPA->getType())->getElementType());
226 for (unsigned i = 0; i < Val.size(); ++i)
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000227 InitializeMemory(cast<Constant>(Val[i].get()), Addr+i*ElementSize);
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000228 return;
229 }
Chris Lattner39bb5b42001-10-15 13:25:40 +0000230
231 case Type::StructTyID: {
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000232 const ConstantStruct *CPS = cast<ConstantStruct>(Init);
Chris Lattner39bb5b42001-10-15 13:25:40 +0000233 const StructLayout *SL=TD.getStructLayout(cast<StructType>(CPS->getType()));
234 const vector<Use> &Val = CPS->getValues();
235 for (unsigned i = 0; i < Val.size(); ++i)
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000236 InitializeMemory(cast<Constant>(Val[i].get()),
Chris Lattner39bb5b42001-10-15 13:25:40 +0000237 Addr+SL->MemberOffsets[i]);
238 return;
239 }
240
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000241 default:
Chris Lattner697954c2002-01-20 22:54:45 +0000242 CW << "Bad Type: " << Init->getType() << "\n";
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000243 assert(0 && "Unknown constant type to initialize memory with!");
244 }
245}
246
247Annotation *GlobalAddress::Create(AnnotationID AID, const Annotable *O, void *){
248 assert(AID == GlobalAddressAID);
249
250 // This annotation will only be created on GlobalValue objects...
251 GlobalValue *GVal = cast<GlobalValue>((Value*)O);
252
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000253 if (isa<Function>(GVal)) {
254 // The GlobalAddress object for a function is just a pointer to function
255 // itself. Don't delete it when the annotation is gone though!
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000256 return new GlobalAddress(GVal, false);
257 }
258
259 // Handle the case of a global variable...
260 assert(isa<GlobalVariable>(GVal) &&
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000261 "Global value found that isn't a function or global variable!");
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000262 GlobalVariable *GV = cast<GlobalVariable>(GVal);
263
264 // First off, we must allocate space for the global variable to point at...
Chris Lattner7a176752001-12-04 00:03:30 +0000265 const Type *Ty = GV->getType()->getElementType(); // Type to be allocated
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000266
267 // Allocate enough memory to hold the type...
Chris Lattnerf23eb852001-12-14 16:49:29 +0000268 void *Addr = calloc(1, TD.getTypeSize(Ty));
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000269 assert(Addr != 0 && "Null pointer returned by malloc!");
270
271 // Initialize the memory if there is an initializer...
272 if (GV->hasInitializer())
273 InitializeMemory(GV->getInitializer(), (char*)Addr);
274
275 return new GlobalAddress(Addr, true); // Simply invoke the ctor
276}
277
Chris Lattner2adcd832002-05-03 19:52:30 +0000278//===----------------------------------------------------------------------===//
Chris Lattner92101ac2001-08-23 17:05:04 +0000279// Binary Instruction Implementations
280//===----------------------------------------------------------------------===//
281
282#define IMPLEMENT_BINARY_OPERATOR(OP, TY) \
283 case Type::TY##TyID: Dest.TY##Val = Src1.TY##Val OP Src2.TY##Val; break
284
285static GenericValue executeAddInst(GenericValue Src1, GenericValue Src2,
286 const Type *Ty, ExecutionContext &SF) {
287 GenericValue Dest;
288 switch (Ty->getPrimitiveID()) {
289 IMPLEMENT_BINARY_OPERATOR(+, UByte);
290 IMPLEMENT_BINARY_OPERATOR(+, SByte);
291 IMPLEMENT_BINARY_OPERATOR(+, UShort);
292 IMPLEMENT_BINARY_OPERATOR(+, Short);
293 IMPLEMENT_BINARY_OPERATOR(+, UInt);
294 IMPLEMENT_BINARY_OPERATOR(+, Int);
Chris Lattner7b851ab2001-10-15 19:18:26 +0000295 IMPLEMENT_BINARY_OPERATOR(+, ULong);
296 IMPLEMENT_BINARY_OPERATOR(+, Long);
Chris Lattner92101ac2001-08-23 17:05:04 +0000297 IMPLEMENT_BINARY_OPERATOR(+, Float);
298 IMPLEMENT_BINARY_OPERATOR(+, Double);
Chris Lattnerc2593162001-10-27 08:28:11 +0000299 IMPLEMENT_BINARY_OPERATOR(+, Pointer);
Chris Lattner92101ac2001-08-23 17:05:04 +0000300 default:
Chris Lattner697954c2002-01-20 22:54:45 +0000301 cout << "Unhandled type for Add instruction: " << Ty << "\n";
Chris Lattner92101ac2001-08-23 17:05:04 +0000302 }
303 return Dest;
304}
305
306static GenericValue executeSubInst(GenericValue Src1, GenericValue Src2,
307 const Type *Ty, ExecutionContext &SF) {
308 GenericValue Dest;
309 switch (Ty->getPrimitiveID()) {
310 IMPLEMENT_BINARY_OPERATOR(-, UByte);
311 IMPLEMENT_BINARY_OPERATOR(-, SByte);
312 IMPLEMENT_BINARY_OPERATOR(-, UShort);
313 IMPLEMENT_BINARY_OPERATOR(-, Short);
314 IMPLEMENT_BINARY_OPERATOR(-, UInt);
315 IMPLEMENT_BINARY_OPERATOR(-, Int);
Chris Lattner7b851ab2001-10-15 19:18:26 +0000316 IMPLEMENT_BINARY_OPERATOR(-, ULong);
317 IMPLEMENT_BINARY_OPERATOR(-, Long);
Chris Lattner92101ac2001-08-23 17:05:04 +0000318 IMPLEMENT_BINARY_OPERATOR(-, Float);
319 IMPLEMENT_BINARY_OPERATOR(-, Double);
Chris Lattnerc2593162001-10-27 08:28:11 +0000320 IMPLEMENT_BINARY_OPERATOR(-, Pointer);
Chris Lattner92101ac2001-08-23 17:05:04 +0000321 default:
Chris Lattner697954c2002-01-20 22:54:45 +0000322 cout << "Unhandled type for Sub instruction: " << Ty << "\n";
Chris Lattner92101ac2001-08-23 17:05:04 +0000323 }
324 return Dest;
325}
326
Chris Lattnerc2593162001-10-27 08:28:11 +0000327static GenericValue executeMulInst(GenericValue Src1, GenericValue Src2,
328 const Type *Ty, ExecutionContext &SF) {
329 GenericValue Dest;
330 switch (Ty->getPrimitiveID()) {
331 IMPLEMENT_BINARY_OPERATOR(*, UByte);
332 IMPLEMENT_BINARY_OPERATOR(*, SByte);
333 IMPLEMENT_BINARY_OPERATOR(*, UShort);
334 IMPLEMENT_BINARY_OPERATOR(*, Short);
335 IMPLEMENT_BINARY_OPERATOR(*, UInt);
336 IMPLEMENT_BINARY_OPERATOR(*, Int);
337 IMPLEMENT_BINARY_OPERATOR(*, ULong);
338 IMPLEMENT_BINARY_OPERATOR(*, Long);
339 IMPLEMENT_BINARY_OPERATOR(*, Float);
340 IMPLEMENT_BINARY_OPERATOR(*, Double);
341 IMPLEMENT_BINARY_OPERATOR(*, Pointer);
342 default:
Chris Lattner697954c2002-01-20 22:54:45 +0000343 cout << "Unhandled type for Mul instruction: " << Ty << "\n";
Chris Lattnerc2593162001-10-27 08:28:11 +0000344 }
345 return Dest;
346}
347
348static GenericValue executeDivInst(GenericValue Src1, GenericValue Src2,
349 const Type *Ty, ExecutionContext &SF) {
350 GenericValue Dest;
351 switch (Ty->getPrimitiveID()) {
352 IMPLEMENT_BINARY_OPERATOR(/, UByte);
353 IMPLEMENT_BINARY_OPERATOR(/, SByte);
354 IMPLEMENT_BINARY_OPERATOR(/, UShort);
355 IMPLEMENT_BINARY_OPERATOR(/, Short);
356 IMPLEMENT_BINARY_OPERATOR(/, UInt);
357 IMPLEMENT_BINARY_OPERATOR(/, Int);
358 IMPLEMENT_BINARY_OPERATOR(/, ULong);
359 IMPLEMENT_BINARY_OPERATOR(/, Long);
360 IMPLEMENT_BINARY_OPERATOR(/, Float);
361 IMPLEMENT_BINARY_OPERATOR(/, Double);
362 IMPLEMENT_BINARY_OPERATOR(/, Pointer);
363 default:
Chris Lattner697954c2002-01-20 22:54:45 +0000364 cout << "Unhandled type for Div instruction: " << Ty << "\n";
Chris Lattnerbb76f022001-10-30 20:27:31 +0000365 }
366 return Dest;
367}
368
369static GenericValue executeRemInst(GenericValue Src1, GenericValue Src2,
370 const Type *Ty, ExecutionContext &SF) {
371 GenericValue Dest;
372 switch (Ty->getPrimitiveID()) {
373 IMPLEMENT_BINARY_OPERATOR(%, UByte);
374 IMPLEMENT_BINARY_OPERATOR(%, SByte);
375 IMPLEMENT_BINARY_OPERATOR(%, UShort);
376 IMPLEMENT_BINARY_OPERATOR(%, Short);
377 IMPLEMENT_BINARY_OPERATOR(%, UInt);
378 IMPLEMENT_BINARY_OPERATOR(%, Int);
379 IMPLEMENT_BINARY_OPERATOR(%, ULong);
380 IMPLEMENT_BINARY_OPERATOR(%, Long);
381 IMPLEMENT_BINARY_OPERATOR(%, Pointer);
382 case Type::FloatTyID:
383 Dest.FloatVal = fmod(Src1.FloatVal, Src2.FloatVal);
384 break;
385 case Type::DoubleTyID:
386 Dest.DoubleVal = fmod(Src1.DoubleVal, Src2.DoubleVal);
387 break;
388 default:
Chris Lattner697954c2002-01-20 22:54:45 +0000389 cout << "Unhandled type for Rem instruction: " << Ty << "\n";
Chris Lattnerc2593162001-10-27 08:28:11 +0000390 }
391 return Dest;
392}
393
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000394static GenericValue executeAndInst(GenericValue Src1, GenericValue Src2,
Chris Lattner4d0e1f92001-10-30 20:54:36 +0000395 const Type *Ty, ExecutionContext &SF) {
396 GenericValue Dest;
397 switch (Ty->getPrimitiveID()) {
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000398 IMPLEMENT_BINARY_OPERATOR(&, UByte);
399 IMPLEMENT_BINARY_OPERATOR(&, SByte);
400 IMPLEMENT_BINARY_OPERATOR(&, UShort);
401 IMPLEMENT_BINARY_OPERATOR(&, Short);
402 IMPLEMENT_BINARY_OPERATOR(&, UInt);
403 IMPLEMENT_BINARY_OPERATOR(&, Int);
404 IMPLEMENT_BINARY_OPERATOR(&, ULong);
405 IMPLEMENT_BINARY_OPERATOR(&, Long);
406 IMPLEMENT_BINARY_OPERATOR(&, Pointer);
407 default:
Chris Lattner697954c2002-01-20 22:54:45 +0000408 cout << "Unhandled type for And instruction: " << Ty << "\n";
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000409 }
410 return Dest;
411}
412
413
414static GenericValue executeOrInst(GenericValue Src1, GenericValue Src2,
415 const Type *Ty, ExecutionContext &SF) {
416 GenericValue Dest;
417 switch (Ty->getPrimitiveID()) {
418 IMPLEMENT_BINARY_OPERATOR(|, UByte);
419 IMPLEMENT_BINARY_OPERATOR(|, SByte);
420 IMPLEMENT_BINARY_OPERATOR(|, UShort);
421 IMPLEMENT_BINARY_OPERATOR(|, Short);
422 IMPLEMENT_BINARY_OPERATOR(|, UInt);
423 IMPLEMENT_BINARY_OPERATOR(|, Int);
424 IMPLEMENT_BINARY_OPERATOR(|, ULong);
425 IMPLEMENT_BINARY_OPERATOR(|, Long);
426 IMPLEMENT_BINARY_OPERATOR(|, Pointer);
427 default:
Chris Lattner697954c2002-01-20 22:54:45 +0000428 cout << "Unhandled type for Or instruction: " << Ty << "\n";
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000429 }
430 return Dest;
431}
432
433
434static GenericValue executeXorInst(GenericValue Src1, GenericValue Src2,
435 const Type *Ty, ExecutionContext &SF) {
436 GenericValue Dest;
437 switch (Ty->getPrimitiveID()) {
Chris Lattner4d0e1f92001-10-30 20:54:36 +0000438 IMPLEMENT_BINARY_OPERATOR(^, UByte);
439 IMPLEMENT_BINARY_OPERATOR(^, SByte);
440 IMPLEMENT_BINARY_OPERATOR(^, UShort);
441 IMPLEMENT_BINARY_OPERATOR(^, Short);
442 IMPLEMENT_BINARY_OPERATOR(^, UInt);
443 IMPLEMENT_BINARY_OPERATOR(^, Int);
444 IMPLEMENT_BINARY_OPERATOR(^, ULong);
445 IMPLEMENT_BINARY_OPERATOR(^, Long);
446 IMPLEMENT_BINARY_OPERATOR(^, Pointer);
447 default:
Chris Lattner697954c2002-01-20 22:54:45 +0000448 cout << "Unhandled type for Xor instruction: " << Ty << "\n";
Chris Lattner4d0e1f92001-10-30 20:54:36 +0000449 }
450 return Dest;
451}
452
453
Chris Lattner92101ac2001-08-23 17:05:04 +0000454#define IMPLEMENT_SETCC(OP, TY) \
455 case Type::TY##TyID: Dest.BoolVal = Src1.TY##Val OP Src2.TY##Val; break
456
Chris Lattner92101ac2001-08-23 17:05:04 +0000457static GenericValue executeSetEQInst(GenericValue Src1, GenericValue Src2,
458 const Type *Ty, ExecutionContext &SF) {
459 GenericValue Dest;
460 switch (Ty->getPrimitiveID()) {
461 IMPLEMENT_SETCC(==, UByte);
462 IMPLEMENT_SETCC(==, SByte);
463 IMPLEMENT_SETCC(==, UShort);
464 IMPLEMENT_SETCC(==, Short);
465 IMPLEMENT_SETCC(==, UInt);
466 IMPLEMENT_SETCC(==, Int);
Chris Lattner7b851ab2001-10-15 19:18:26 +0000467 IMPLEMENT_SETCC(==, ULong);
468 IMPLEMENT_SETCC(==, Long);
Chris Lattner92101ac2001-08-23 17:05:04 +0000469 IMPLEMENT_SETCC(==, Float);
470 IMPLEMENT_SETCC(==, Double);
Chris Lattner86660982001-08-27 05:16:50 +0000471 IMPLEMENT_SETCC(==, Pointer);
Chris Lattner92101ac2001-08-23 17:05:04 +0000472 default:
Chris Lattner697954c2002-01-20 22:54:45 +0000473 cout << "Unhandled type for SetEQ instruction: " << Ty << "\n";
Chris Lattner92101ac2001-08-23 17:05:04 +0000474 }
475 return Dest;
476}
477
478static GenericValue executeSetNEInst(GenericValue Src1, GenericValue Src2,
479 const Type *Ty, ExecutionContext &SF) {
480 GenericValue Dest;
481 switch (Ty->getPrimitiveID()) {
482 IMPLEMENT_SETCC(!=, UByte);
483 IMPLEMENT_SETCC(!=, SByte);
484 IMPLEMENT_SETCC(!=, UShort);
485 IMPLEMENT_SETCC(!=, Short);
486 IMPLEMENT_SETCC(!=, UInt);
487 IMPLEMENT_SETCC(!=, Int);
Chris Lattner7b851ab2001-10-15 19:18:26 +0000488 IMPLEMENT_SETCC(!=, ULong);
489 IMPLEMENT_SETCC(!=, Long);
Chris Lattner92101ac2001-08-23 17:05:04 +0000490 IMPLEMENT_SETCC(!=, Float);
491 IMPLEMENT_SETCC(!=, Double);
Chris Lattner86660982001-08-27 05:16:50 +0000492 IMPLEMENT_SETCC(!=, Pointer);
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000493
Chris Lattner92101ac2001-08-23 17:05:04 +0000494 default:
Chris Lattner697954c2002-01-20 22:54:45 +0000495 cout << "Unhandled type for SetNE instruction: " << Ty << "\n";
Chris Lattner92101ac2001-08-23 17:05:04 +0000496 }
497 return Dest;
498}
499
500static GenericValue executeSetLEInst(GenericValue Src1, GenericValue Src2,
501 const Type *Ty, ExecutionContext &SF) {
502 GenericValue Dest;
503 switch (Ty->getPrimitiveID()) {
504 IMPLEMENT_SETCC(<=, UByte);
505 IMPLEMENT_SETCC(<=, SByte);
506 IMPLEMENT_SETCC(<=, UShort);
507 IMPLEMENT_SETCC(<=, Short);
508 IMPLEMENT_SETCC(<=, UInt);
509 IMPLEMENT_SETCC(<=, Int);
Chris Lattner7b851ab2001-10-15 19:18:26 +0000510 IMPLEMENT_SETCC(<=, ULong);
511 IMPLEMENT_SETCC(<=, Long);
Chris Lattner92101ac2001-08-23 17:05:04 +0000512 IMPLEMENT_SETCC(<=, Float);
513 IMPLEMENT_SETCC(<=, Double);
Chris Lattner86660982001-08-27 05:16:50 +0000514 IMPLEMENT_SETCC(<=, Pointer);
Chris Lattner92101ac2001-08-23 17:05:04 +0000515 default:
Chris Lattner697954c2002-01-20 22:54:45 +0000516 cout << "Unhandled type for SetLE instruction: " << Ty << "\n";
Chris Lattner92101ac2001-08-23 17:05:04 +0000517 }
518 return Dest;
519}
520
521static GenericValue executeSetGEInst(GenericValue Src1, GenericValue Src2,
522 const Type *Ty, ExecutionContext &SF) {
523 GenericValue Dest;
524 switch (Ty->getPrimitiveID()) {
525 IMPLEMENT_SETCC(>=, UByte);
526 IMPLEMENT_SETCC(>=, SByte);
527 IMPLEMENT_SETCC(>=, UShort);
528 IMPLEMENT_SETCC(>=, Short);
529 IMPLEMENT_SETCC(>=, UInt);
530 IMPLEMENT_SETCC(>=, Int);
Chris Lattner7b851ab2001-10-15 19:18:26 +0000531 IMPLEMENT_SETCC(>=, ULong);
532 IMPLEMENT_SETCC(>=, Long);
Chris Lattner92101ac2001-08-23 17:05:04 +0000533 IMPLEMENT_SETCC(>=, Float);
534 IMPLEMENT_SETCC(>=, Double);
Chris Lattner86660982001-08-27 05:16:50 +0000535 IMPLEMENT_SETCC(>=, Pointer);
Chris Lattner92101ac2001-08-23 17:05:04 +0000536 default:
Chris Lattner697954c2002-01-20 22:54:45 +0000537 cout << "Unhandled type for SetGE instruction: " << Ty << "\n";
Chris Lattner92101ac2001-08-23 17:05:04 +0000538 }
539 return Dest;
540}
541
542static GenericValue executeSetLTInst(GenericValue Src1, GenericValue Src2,
543 const Type *Ty, ExecutionContext &SF) {
544 GenericValue Dest;
545 switch (Ty->getPrimitiveID()) {
546 IMPLEMENT_SETCC(<, UByte);
547 IMPLEMENT_SETCC(<, SByte);
548 IMPLEMENT_SETCC(<, UShort);
549 IMPLEMENT_SETCC(<, Short);
550 IMPLEMENT_SETCC(<, UInt);
551 IMPLEMENT_SETCC(<, Int);
Chris Lattner7b851ab2001-10-15 19:18:26 +0000552 IMPLEMENT_SETCC(<, ULong);
553 IMPLEMENT_SETCC(<, Long);
Chris Lattner92101ac2001-08-23 17:05:04 +0000554 IMPLEMENT_SETCC(<, Float);
555 IMPLEMENT_SETCC(<, Double);
Chris Lattner86660982001-08-27 05:16:50 +0000556 IMPLEMENT_SETCC(<, Pointer);
Chris Lattner92101ac2001-08-23 17:05:04 +0000557 default:
Chris Lattner697954c2002-01-20 22:54:45 +0000558 cout << "Unhandled type for SetLT instruction: " << Ty << "\n";
Chris Lattner92101ac2001-08-23 17:05:04 +0000559 }
560 return Dest;
561}
562
563static GenericValue executeSetGTInst(GenericValue Src1, GenericValue Src2,
564 const Type *Ty, ExecutionContext &SF) {
565 GenericValue Dest;
566 switch (Ty->getPrimitiveID()) {
567 IMPLEMENT_SETCC(>, UByte);
568 IMPLEMENT_SETCC(>, SByte);
569 IMPLEMENT_SETCC(>, UShort);
570 IMPLEMENT_SETCC(>, Short);
571 IMPLEMENT_SETCC(>, UInt);
572 IMPLEMENT_SETCC(>, Int);
Chris Lattner7b851ab2001-10-15 19:18:26 +0000573 IMPLEMENT_SETCC(>, ULong);
574 IMPLEMENT_SETCC(>, Long);
Chris Lattner92101ac2001-08-23 17:05:04 +0000575 IMPLEMENT_SETCC(>, Float);
576 IMPLEMENT_SETCC(>, Double);
Chris Lattner86660982001-08-27 05:16:50 +0000577 IMPLEMENT_SETCC(>, Pointer);
Chris Lattner92101ac2001-08-23 17:05:04 +0000578 default:
Chris Lattner697954c2002-01-20 22:54:45 +0000579 cout << "Unhandled type for SetGT instruction: " << Ty << "\n";
Chris Lattner92101ac2001-08-23 17:05:04 +0000580 }
581 return Dest;
582}
583
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000584static void executeBinaryInst(BinaryOperator &I, ExecutionContext &SF) {
585 const Type *Ty = I.getOperand(0)->getType();
586 GenericValue Src1 = getOperandValue(I.getOperand(0), SF);
587 GenericValue Src2 = getOperandValue(I.getOperand(1), SF);
Chris Lattner92101ac2001-08-23 17:05:04 +0000588 GenericValue R; // Result
589
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000590 switch (I.getOpcode()) {
Chris Lattnerbb76f022001-10-30 20:27:31 +0000591 case Instruction::Add: R = executeAddInst (Src1, Src2, Ty, SF); break;
592 case Instruction::Sub: R = executeSubInst (Src1, Src2, Ty, SF); break;
593 case Instruction::Mul: R = executeMulInst (Src1, Src2, Ty, SF); break;
594 case Instruction::Div: R = executeDivInst (Src1, Src2, Ty, SF); break;
595 case Instruction::Rem: R = executeRemInst (Src1, Src2, Ty, SF); break;
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000596 case Instruction::And: R = executeAndInst (Src1, Src2, Ty, SF); break;
597 case Instruction::Or: R = executeOrInst (Src1, Src2, Ty, SF); break;
Chris Lattner4d0e1f92001-10-30 20:54:36 +0000598 case Instruction::Xor: R = executeXorInst (Src1, Src2, Ty, SF); break;
Chris Lattner92101ac2001-08-23 17:05:04 +0000599 case Instruction::SetEQ: R = executeSetEQInst(Src1, Src2, Ty, SF); break;
600 case Instruction::SetNE: R = executeSetNEInst(Src1, Src2, Ty, SF); break;
601 case Instruction::SetLE: R = executeSetLEInst(Src1, Src2, Ty, SF); break;
602 case Instruction::SetGE: R = executeSetGEInst(Src1, Src2, Ty, SF); break;
603 case Instruction::SetLT: R = executeSetLTInst(Src1, Src2, Ty, SF); break;
604 case Instruction::SetGT: R = executeSetGTInst(Src1, Src2, Ty, SF); break;
605 default:
606 cout << "Don't know how to handle this binary operator!\n-->" << I;
Chris Lattner4d0e1f92001-10-30 20:54:36 +0000607 R = Src1;
Chris Lattner92101ac2001-08-23 17:05:04 +0000608 }
609
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000610 SetValue(&I, R, SF);
Chris Lattner92101ac2001-08-23 17:05:04 +0000611}
612
Chris Lattner92101ac2001-08-23 17:05:04 +0000613//===----------------------------------------------------------------------===//
614// Terminator Instruction Implementations
615//===----------------------------------------------------------------------===//
616
Chris Lattnera95c6992001-11-12 16:28:48 +0000617static void PerformExitStuff() {
618#ifdef PROFILE_STRUCTURE_FIELDS
619 // Print out structure field accounting information...
620 if (!FieldAccessCounts.empty()) {
Chris Lattner84efe092001-11-12 20:13:14 +0000621 CW << "Profile Field Access Counts:\n";
Chris Lattner697954c2002-01-20 22:54:45 +0000622 std::map<const StructType *, vector<unsigned> >::iterator
Chris Lattnera95c6992001-11-12 16:28:48 +0000623 I = FieldAccessCounts.begin(), E = FieldAccessCounts.end();
624 for (; I != E; ++I) {
625 vector<unsigned> &OfC = I->second;
626 CW << " '" << (Value*)I->first << "'\t- Sum=";
627
628 unsigned Sum = 0;
629 for (unsigned i = 0; i < OfC.size(); ++i)
630 Sum += OfC[i];
631 CW << Sum << " - ";
632
633 for (unsigned i = 0; i < OfC.size(); ++i) {
634 if (i) CW << ", ";
635 CW << OfC[i];
636 }
Chris Lattner697954c2002-01-20 22:54:45 +0000637 CW << "\n";
Chris Lattnera95c6992001-11-12 16:28:48 +0000638 }
Chris Lattner697954c2002-01-20 22:54:45 +0000639 CW << "\n";
Chris Lattner84efe092001-11-12 20:13:14 +0000640
641 CW << "Profile Field Access Percentages:\n";
642 cout.precision(3);
643 for (I = FieldAccessCounts.begin(); I != E; ++I) {
644 vector<unsigned> &OfC = I->second;
645 unsigned Sum = 0;
646 for (unsigned i = 0; i < OfC.size(); ++i)
647 Sum += OfC[i];
648
649 CW << " '" << (Value*)I->first << "'\t- ";
650 for (unsigned i = 0; i < OfC.size(); ++i) {
651 if (i) CW << ", ";
652 CW << double(OfC[i])/Sum;
653 }
Chris Lattner697954c2002-01-20 22:54:45 +0000654 CW << "\n";
Chris Lattner84efe092001-11-12 20:13:14 +0000655 }
Chris Lattner697954c2002-01-20 22:54:45 +0000656 CW << "\n";
Chris Lattner84efe092001-11-12 20:13:14 +0000657
Chris Lattnera95c6992001-11-12 16:28:48 +0000658 FieldAccessCounts.clear();
659 }
660#endif
661}
662
Chris Lattnere43db882001-10-27 04:15:57 +0000663void Interpreter::exitCalled(GenericValue GV) {
Chris Lattnerf23eb852001-12-14 16:49:29 +0000664 if (!QuietMode) {
665 cout << "Program returned ";
666 print(Type::IntTy, GV);
667 cout << " via 'void exit(int)'\n";
668 }
Chris Lattnere43db882001-10-27 04:15:57 +0000669
670 ExitCode = GV.SByteVal;
671 ECStack.clear();
Chris Lattnera95c6992001-11-12 16:28:48 +0000672 PerformExitStuff();
Chris Lattnere43db882001-10-27 04:15:57 +0000673}
674
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000675void Interpreter::executeRetInst(ReturnInst &I, ExecutionContext &SF) {
Chris Lattner92101ac2001-08-23 17:05:04 +0000676 const Type *RetTy = 0;
677 GenericValue Result;
678
679 // Save away the return value... (if we are not 'ret void')
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000680 if (I.getNumOperands()) {
681 RetTy = I.getReturnValue()->getType();
682 Result = getOperandValue(I.getReturnValue(), SF);
Chris Lattner92101ac2001-08-23 17:05:04 +0000683 }
684
685 // Save previously executing meth
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000686 const Function *M = ECStack.back().CurMethod;
Chris Lattner92101ac2001-08-23 17:05:04 +0000687
688 // Pop the current stack frame... this invalidates SF
689 ECStack.pop_back();
690
691 if (ECStack.empty()) { // Finished main. Put result into exit code...
692 if (RetTy) { // Nonvoid return type?
Chris Lattnerf23eb852001-12-14 16:49:29 +0000693 if (!QuietMode) {
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000694 CW << "Function " << M->getType() << " \"" << M->getName()
Chris Lattnerf23eb852001-12-14 16:49:29 +0000695 << "\" returned ";
696 print(RetTy, Result);
Chris Lattner697954c2002-01-20 22:54:45 +0000697 cout << "\n";
Chris Lattnerf23eb852001-12-14 16:49:29 +0000698 }
Chris Lattner92101ac2001-08-23 17:05:04 +0000699
700 if (RetTy->isIntegral())
Chris Lattnerf4dca802002-05-02 19:28:45 +0000701 ExitCode = Result.IntVal; // Capture the exit code of the program
Chris Lattner92101ac2001-08-23 17:05:04 +0000702 } else {
703 ExitCode = 0;
704 }
Chris Lattnere2409062001-11-12 16:19:45 +0000705
Chris Lattnera95c6992001-11-12 16:28:48 +0000706 PerformExitStuff();
Chris Lattner92101ac2001-08-23 17:05:04 +0000707 return;
708 }
709
710 // If we have a previous stack frame, and we have a previous call, fill in
711 // the return value...
712 //
713 ExecutionContext &NewSF = ECStack.back();
714 if (NewSF.Caller) {
715 if (NewSF.Caller->getType() != Type::VoidTy) // Save result...
716 SetValue(NewSF.Caller, Result, NewSF);
717
718 NewSF.Caller = 0; // We returned from the call...
Chris Lattnerf23eb852001-12-14 16:49:29 +0000719 } else if (!QuietMode) {
Chris Lattner365a76e2001-09-10 04:49:44 +0000720 // This must be a function that is executing because of a user 'call'
721 // instruction.
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000722 CW << "Function " << M->getType() << " \"" << M->getName()
Chris Lattner5af0c482001-11-07 04:23:00 +0000723 << "\" returned ";
Chris Lattner2e42d3a2001-10-15 05:51:48 +0000724 print(RetTy, Result);
Chris Lattner697954c2002-01-20 22:54:45 +0000725 cout << "\n";
Chris Lattner92101ac2001-08-23 17:05:04 +0000726 }
727}
728
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000729void Interpreter::executeBrInst(BranchInst &I, ExecutionContext &SF) {
Chris Lattner92101ac2001-08-23 17:05:04 +0000730 SF.PrevBB = SF.CurBB; // Update PrevBB so that PHI nodes work...
731 BasicBlock *Dest;
732
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000733 Dest = I.getSuccessor(0); // Uncond branches have a fixed dest...
734 if (!I.isUnconditional()) {
735 Value *Cond = I.getCondition();
Chris Lattnerbb76f022001-10-30 20:27:31 +0000736 GenericValue CondVal = getOperandValue(Cond, SF);
737 if (CondVal.BoolVal == 0) // If false cond...
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000738 Dest = I.getSuccessor(1);
Chris Lattner92101ac2001-08-23 17:05:04 +0000739 }
740 SF.CurBB = Dest; // Update CurBB to branch destination
741 SF.CurInst = SF.CurBB->begin(); // Update new instruction ptr...
742}
743
744//===----------------------------------------------------------------------===//
Chris Lattner86660982001-08-27 05:16:50 +0000745// Memory Instruction Implementations
746//===----------------------------------------------------------------------===//
747
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000748void Interpreter::executeAllocInst(AllocationInst &I, ExecutionContext &SF) {
749 const Type *Ty = I.getType()->getElementType(); // Type to be allocated
Chris Lattner86660982001-08-27 05:16:50 +0000750
Chris Lattnercc82cc12002-04-28 21:57:33 +0000751 // Get the number of elements being allocated by the array...
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000752 unsigned NumElements = getOperandValue(I.getOperand(0), SF).UIntVal;
Chris Lattner86660982001-08-27 05:16:50 +0000753
754 // Allocate enough memory to hold the type...
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000755 // FIXME: Don't use CALLOC, use a tainted malloc.
Chris Lattner9bffa732002-02-19 18:50:09 +0000756 void *Memory = calloc(NumElements, TD.getTypeSize(Ty));
757
758 GenericValue Result;
759 Result.PointerVal = (PointerTy)Memory;
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000760 assert(Result.PointerVal != 0 && "Null pointer returned by malloc!");
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000761 SetValue(&I, Result, SF);
Chris Lattner86660982001-08-27 05:16:50 +0000762
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000763 if (I.getOpcode() == Instruction::Alloca)
Chris Lattner9bffa732002-02-19 18:50:09 +0000764 ECStack.back().Allocas.add(Memory);
Chris Lattner86660982001-08-27 05:16:50 +0000765}
766
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000767static void executeFreeInst(FreeInst &I, ExecutionContext &SF) {
768 assert(isa<PointerType>(I.getOperand(0)->getType()) && "Freeing nonptr?");
769 GenericValue Value = getOperandValue(I.getOperand(0), SF);
Chris Lattner86660982001-08-27 05:16:50 +0000770 // TODO: Check to make sure memory is allocated
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000771 free((void*)Value.PointerVal); // Free memory
Chris Lattner86660982001-08-27 05:16:50 +0000772}
773
Chris Lattner95c3af52001-10-29 19:32:19 +0000774
Chris Lattnera34c5682002-08-27 22:33:45 +0000775// getElementOffset - The workhorse for getelementptr.
Chris Lattner95c3af52001-10-29 19:32:19 +0000776//
Chris Lattnera34c5682002-08-27 22:33:45 +0000777static GenericValue executeGEPOperation(Value *Ptr, User::op_iterator I,
778 User::op_iterator E,
779 ExecutionContext &SF) {
780 assert(isa<PointerType>(Ptr->getType()) &&
Chris Lattner95c3af52001-10-29 19:32:19 +0000781 "Cannot getElementOffset of a nonpointer type!");
782
Chris Lattnerea38c0e2001-11-07 19:46:27 +0000783 PointerTy Total = 0;
Chris Lattnera34c5682002-08-27 22:33:45 +0000784 const Type *Ty = Ptr->getType();
785
786 for (; I != E; ++I) {
Chris Lattner782b9392001-11-26 18:18:18 +0000787 if (const StructType *STy = dyn_cast<StructType>(Ty)) {
788 const StructLayout *SLO = TD.getStructLayout(STy);
789
790 // Indicies must be ubyte constants...
Chris Lattnera34c5682002-08-27 22:33:45 +0000791 const ConstantUInt *CPU = cast<ConstantUInt>(*I);
Chris Lattner782b9392001-11-26 18:18:18 +0000792 assert(CPU->getType() == Type::UByteTy);
793 unsigned Index = CPU->getValue();
794
Chris Lattnere2409062001-11-12 16:19:45 +0000795#ifdef PROFILE_STRUCTURE_FIELDS
Chris Lattner782b9392001-11-26 18:18:18 +0000796 if (ProfileStructureFields) {
797 // Do accounting for this field...
798 vector<unsigned> &OfC = FieldAccessCounts[STy];
799 if (OfC.size() == 0) OfC.resize(STy->getElementTypes().size());
800 OfC[Index]++;
801 }
Chris Lattnere2409062001-11-12 16:19:45 +0000802#endif
Chris Lattner782b9392001-11-26 18:18:18 +0000803
804 Total += SLO->MemberOffsets[Index];
805 Ty = STy->getElementTypes()[Index];
Chris Lattnerf23eb852001-12-14 16:49:29 +0000806 } else if (const SequentialType *ST = cast<SequentialType>(Ty)) {
Chris Lattnere2409062001-11-12 16:19:45 +0000807
Chris Lattner782b9392001-11-26 18:18:18 +0000808 // Get the index number for the array... which must be uint type...
Chris Lattner0374b8d2002-09-11 01:21:35 +0000809 assert((*I)->getType() == Type::LongTy);
Chris Lattnere8b3e9b2002-09-13 23:30:42 +0000810 unsigned Idx = getOperandValue(*I, SF).LongVal;
Chris Lattnerf23eb852001-12-14 16:49:29 +0000811 if (const ArrayType *AT = dyn_cast<ArrayType>(ST))
Chris Lattnerc0fbd572002-02-11 20:19:16 +0000812 if (Idx >= AT->getNumElements() && ArrayChecksEnabled) {
Chris Lattnerf23eb852001-12-14 16:49:29 +0000813 cerr << "Out of range memory access to element #" << Idx
814 << " of a " << AT->getNumElements() << " element array."
Chris Lattnera34c5682002-08-27 22:33:45 +0000815 << " Subscript #" << *I << "\n";
Chris Lattnerf23eb852001-12-14 16:49:29 +0000816 // Get outta here!!!
Chris Lattner74030252002-02-12 15:47:23 +0000817 siglongjmp(SignalRecoverBuffer, SIGTRAP);
Chris Lattnerf23eb852001-12-14 16:49:29 +0000818 }
Chris Lattner782b9392001-11-26 18:18:18 +0000819
Chris Lattnerf23eb852001-12-14 16:49:29 +0000820 Ty = ST->getElementType();
Chris Lattner782b9392001-11-26 18:18:18 +0000821 unsigned Size = TD.getTypeSize(Ty);
822 Total += Size*Idx;
823 }
Chris Lattner95c3af52001-10-29 19:32:19 +0000824 }
825
Chris Lattnera34c5682002-08-27 22:33:45 +0000826 GenericValue Result;
827 Result.PointerVal = getOperandValue(Ptr, SF).PointerVal + Total;
828 return Result;
Chris Lattner95c3af52001-10-29 19:32:19 +0000829}
830
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000831static void executeGEPInst(GetElementPtrInst &I, ExecutionContext &SF) {
Chris Lattnera34c5682002-08-27 22:33:45 +0000832 SetValue(&I, executeGEPOperation(I.getPointerOperand(),
833 I.idx_begin(), I.idx_end(), SF), SF);
Chris Lattner95c3af52001-10-29 19:32:19 +0000834}
835
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000836static void executeLoadInst(LoadInst &I, ExecutionContext &SF) {
837 GenericValue SRC = getOperandValue(I.getPointerOperand(), SF);
Chris Lattner24ea74e2002-08-22 22:49:05 +0000838 GenericValue *Ptr = (GenericValue*)SRC.PointerVal;
Chris Lattner86660982001-08-27 05:16:50 +0000839 GenericValue Result;
840
Chris Lattnerfddc7552002-10-15 20:34:05 +0000841 if (TD.isLittleEndian()) {
842 switch (I.getType()->getPrimitiveID()) {
843 case Type::BoolTyID:
844 case Type::UByteTyID:
Chris Lattner2fdaddf2002-10-30 21:47:57 +0000845 case Type::SByteTyID: Result.UByteVal = Ptr->Untyped[0]; break;
Chris Lattnerfddc7552002-10-15 20:34:05 +0000846 case Type::UShortTyID:
Chris Lattner2fdaddf2002-10-30 21:47:57 +0000847 case Type::ShortTyID: Result.UShortVal = (unsigned)Ptr->Untyped[0] |
848 ((unsigned)Ptr->Untyped[1] << 8);
Chris Lattnerfddc7552002-10-15 20:34:05 +0000849 break;
850 case Type::FloatTyID:
851 case Type::UIntTyID:
Chris Lattner2fdaddf2002-10-30 21:47:57 +0000852 case Type::IntTyID: Result.UIntVal = (unsigned)Ptr->Untyped[0] |
853 ((unsigned)Ptr->Untyped[1] << 8) |
854 ((unsigned)Ptr->Untyped[2] << 16) |
855 ((unsigned)Ptr->Untyped[3] << 24);
Chris Lattnerfddc7552002-10-15 20:34:05 +0000856 break;
857 case Type::DoubleTyID:
858 case Type::ULongTyID:
859 case Type::LongTyID:
Chris Lattner2fdaddf2002-10-30 21:47:57 +0000860 case Type::PointerTyID: Result.ULongVal = (uint64_t)Ptr->Untyped[0] |
861 ((uint64_t)Ptr->Untyped[1] << 8) |
862 ((uint64_t)Ptr->Untyped[2] << 16) |
863 ((uint64_t)Ptr->Untyped[3] << 24) |
864 ((uint64_t)Ptr->Untyped[4] << 32) |
865 ((uint64_t)Ptr->Untyped[5] << 40) |
866 ((uint64_t)Ptr->Untyped[6] << 48) |
867 ((uint64_t)Ptr->Untyped[7] << 56);
Chris Lattnerfddc7552002-10-15 20:34:05 +0000868 break;
869 default:
870 cout << "Cannot load value of type " << I.getType() << "!\n";
871 }
872 } else {
873 switch (I.getType()->getPrimitiveID()) {
874 case Type::BoolTyID:
875 case Type::UByteTyID:
Chris Lattner2fdaddf2002-10-30 21:47:57 +0000876 case Type::SByteTyID: Result.UByteVal = Ptr->Untyped[0]; break;
Chris Lattnerfddc7552002-10-15 20:34:05 +0000877 case Type::UShortTyID:
Chris Lattner2fdaddf2002-10-30 21:47:57 +0000878 case Type::ShortTyID: Result.UShortVal = (unsigned)Ptr->Untyped[1] |
879 ((unsigned)Ptr->Untyped[0] << 8);
Chris Lattnerfddc7552002-10-15 20:34:05 +0000880 break;
881 case Type::FloatTyID:
882 case Type::UIntTyID:
Chris Lattner2fdaddf2002-10-30 21:47:57 +0000883 case Type::IntTyID: Result.UIntVal = (unsigned)Ptr->Untyped[3] |
884 ((unsigned)Ptr->Untyped[2] << 8) |
885 ((unsigned)Ptr->Untyped[1] << 16) |
886 ((unsigned)Ptr->Untyped[0] << 24);
Chris Lattnerfddc7552002-10-15 20:34:05 +0000887 break;
888 case Type::DoubleTyID:
889 case Type::ULongTyID:
890 case Type::LongTyID:
Chris Lattner2fdaddf2002-10-30 21:47:57 +0000891 case Type::PointerTyID: Result.ULongVal = (uint64_t)Ptr->Untyped[7] |
892 ((uint64_t)Ptr->Untyped[6] << 8) |
893 ((uint64_t)Ptr->Untyped[5] << 16) |
894 ((uint64_t)Ptr->Untyped[4] << 24) |
895 ((uint64_t)Ptr->Untyped[3] << 32) |
896 ((uint64_t)Ptr->Untyped[2] << 40) |
897 ((uint64_t)Ptr->Untyped[1] << 48) |
898 ((uint64_t)Ptr->Untyped[0] << 56);
Chris Lattnerfddc7552002-10-15 20:34:05 +0000899 break;
900 default:
901 cout << "Cannot load value of type " << I.getType() << "!\n";
902 }
Chris Lattner86660982001-08-27 05:16:50 +0000903 }
904
Chris Lattner0b12b5f2002-06-25 16:13:21 +0000905 SetValue(&I, Result, SF);
Chris Lattner86660982001-08-27 05:16:50 +0000906}
907
Chris Lattnerfddc7552002-10-15 20:34:05 +0000908static void StoreValueToMemory(GenericValue Val, GenericValue *Ptr,
909 const Type *Ty) {
910 if (TD.isLittleEndian()) {
911 switch (Ty->getPrimitiveID()) {
912 case Type::BoolTyID:
913 case Type::UByteTyID:
914 case Type::SByteTyID: Ptr->Untyped[0] = Val.UByteVal; break;
915 case Type::UShortTyID:
916 case Type::ShortTyID: Ptr->Untyped[0] = Val.UShortVal & 255;
917 Ptr->Untyped[1] = (Val.UShortVal >> 8) & 255;
918 break;
919 case Type::FloatTyID:
920 case Type::UIntTyID:
921 case Type::IntTyID: Ptr->Untyped[0] = Val.UIntVal & 255;
922 Ptr->Untyped[1] = (Val.UIntVal >> 8) & 255;
923 Ptr->Untyped[2] = (Val.UIntVal >> 16) & 255;
924 Ptr->Untyped[3] = (Val.UIntVal >> 24) & 255;
925 break;
926 case Type::DoubleTyID:
927 case Type::ULongTyID:
928 case Type::LongTyID:
929 case Type::PointerTyID: Ptr->Untyped[0] = Val.ULongVal & 255;
930 Ptr->Untyped[1] = (Val.ULongVal >> 8) & 255;
931 Ptr->Untyped[2] = (Val.ULongVal >> 16) & 255;
932 Ptr->Untyped[3] = (Val.ULongVal >> 24) & 255;
933 Ptr->Untyped[4] = (Val.ULongVal >> 32) & 255;
934 Ptr->Untyped[5] = (Val.ULongVal >> 40) & 255;
935 Ptr->Untyped[6] = (Val.ULongVal >> 48) & 255;
936 Ptr->Untyped[7] = (Val.ULongVal >> 56) & 255;
937 break;
938 default:
Chris Lattner683d5da92002-10-26 01:57:15 +0000939 cout << "Cannot store value of type " << Ty << "!\n";
Chris Lattnerfddc7552002-10-15 20:34:05 +0000940 }
941 } else {
942 switch (Ty->getPrimitiveID()) {
943 case Type::BoolTyID:
944 case Type::UByteTyID:
945 case Type::SByteTyID: Ptr->Untyped[0] = Val.UByteVal; break;
946 case Type::UShortTyID:
947 case Type::ShortTyID: Ptr->Untyped[1] = Val.UShortVal & 255;
948 Ptr->Untyped[0] = (Val.UShortVal >> 8) & 255;
949 break;
950 case Type::FloatTyID:
951 case Type::UIntTyID:
952 case Type::IntTyID: Ptr->Untyped[3] = Val.UIntVal & 255;
953 Ptr->Untyped[2] = (Val.UIntVal >> 8) & 255;
954 Ptr->Untyped[1] = (Val.UIntVal >> 16) & 255;
955 Ptr->Untyped[0] = (Val.UIntVal >> 24) & 255;
956 break;
957 case Type::DoubleTyID:
958 case Type::ULongTyID:
959 case Type::LongTyID:
960 case Type::PointerTyID: Ptr->Untyped[7] = Val.ULongVal & 255;
961 Ptr->Untyped[6] = (Val.ULongVal >> 8) & 255;
962 Ptr->Untyped[5] = (Val.ULongVal >> 16) & 255;
963 Ptr->Untyped[4] = (Val.ULongVal >> 24) & 255;
964 Ptr->Untyped[3] = (Val.ULongVal >> 32) & 255;
965 Ptr->Untyped[2] = (Val.ULongVal >> 40) & 255;
966 Ptr->Untyped[1] = (Val.ULongVal >> 48) & 255;
967 Ptr->Untyped[0] = (Val.ULongVal >> 56) & 255;
968 break;
969 default:
Chris Lattner683d5da92002-10-26 01:57:15 +0000970 cout << "Cannot store value of type " << Ty << "!\n";
Chris Lattnerfddc7552002-10-15 20:34:05 +0000971 }
Chris Lattner86660982001-08-27 05:16:50 +0000972 }
973}
974
Chris Lattnerfddc7552002-10-15 20:34:05 +0000975static void executeStoreInst(StoreInst &I, ExecutionContext &SF) {
976 GenericValue Val = getOperandValue(I.getOperand(0), SF);
977 GenericValue SRC = getOperandValue(I.getPointerOperand(), SF);
Chris Lattner683d5da92002-10-26 01:57:15 +0000978 StoreValueToMemory(Val, (GenericValue *)SRC.PointerVal,
979 I.getOperand(0)->getType());
Chris Lattnerfddc7552002-10-15 20:34:05 +0000980}
981
Chris Lattner86660982001-08-27 05:16:50 +0000982
Chris Lattnerab2dea52002-11-07 19:29:31 +0000983GenericValue Interpreter::CreateArgv(const std::vector<std::string> &InputArgv){
984 // Pointers are 64 bits...
985 PointerTy *Result = new PointerTy[InputArgv.size()+1]; // 64 bit assumption
986
987 for (unsigned i = 0; i < InputArgv.size(); ++i) {
988 unsigned Size = InputArgv[i].size()+1;
989 char *Dest = new char[Size];
990 copy(InputArgv[i].begin(), InputArgv[i].end(), Dest);
991 Dest[Size-1] = 0;
992
993 GenericValue GV; GV.PointerVal = (PointerTy)Dest;
994 // Endian safe: Result[i] = (PointerTy)Dest;
995 StoreValueToMemory(GV, (GenericValue*)(Result+i),
996 Type::LongTy); // 64 bit assumption
997 }
998
999 Result[InputArgv.size()] = 0;
1000 GenericValue GV; GV.PointerVal = (PointerTy)Result;
1001 return GV;
1002}
1003
1004
Chris Lattner86660982001-08-27 05:16:50 +00001005//===----------------------------------------------------------------------===//
Chris Lattner92101ac2001-08-23 17:05:04 +00001006// Miscellaneous Instruction Implementations
1007//===----------------------------------------------------------------------===//
1008
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001009void Interpreter::executeCallInst(CallInst &I, ExecutionContext &SF) {
1010 ECStack.back().Caller = &I;
Chris Lattner365a76e2001-09-10 04:49:44 +00001011 vector<GenericValue> ArgVals;
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001012 ArgVals.reserve(I.getNumOperands()-1);
1013 for (unsigned i = 1; i < I.getNumOperands(); ++i)
1014 ArgVals.push_back(getOperandValue(I.getOperand(i), SF));
Chris Lattner365a76e2001-09-10 04:49:44 +00001015
Chris Lattner070cf5e2001-11-07 20:12:30 +00001016 // To handle indirect calls, we must get the pointer value from the argument
Chris Lattner2fbfdcf2002-04-07 20:49:59 +00001017 // and treat it as a function pointer.
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001018 GenericValue SRC = getOperandValue(I.getCalledValue(), SF);
Chris Lattner070cf5e2001-11-07 20:12:30 +00001019
Chris Lattner2fbfdcf2002-04-07 20:49:59 +00001020 callMethod((Function*)SRC.PointerVal, ArgVals);
Chris Lattner92101ac2001-08-23 17:05:04 +00001021}
1022
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001023static void executePHINode(PHINode &I, ExecutionContext &SF) {
Chris Lattner92101ac2001-08-23 17:05:04 +00001024 BasicBlock *PrevBB = SF.PrevBB;
1025 Value *IncomingValue = 0;
1026
1027 // Search for the value corresponding to this previous bb...
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001028 for (unsigned i = I.getNumIncomingValues(); i > 0;) {
1029 if (I.getIncomingBlock(--i) == PrevBB) {
1030 IncomingValue = I.getIncomingValue(i);
Chris Lattner92101ac2001-08-23 17:05:04 +00001031 break;
1032 }
1033 }
1034 assert(IncomingValue && "No PHI node predecessor for current PrevBB!");
1035
1036 // Found the value, set as the result...
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001037 SetValue(&I, getOperandValue(IncomingValue, SF), SF);
Chris Lattner92101ac2001-08-23 17:05:04 +00001038}
1039
Chris Lattner86660982001-08-27 05:16:50 +00001040#define IMPLEMENT_SHIFT(OP, TY) \
1041 case Type::TY##TyID: Dest.TY##Val = Src1.TY##Val OP Src2.UByteVal; break
1042
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001043static void executeShlInst(ShiftInst &I, ExecutionContext &SF) {
1044 const Type *Ty = I.getOperand(0)->getType();
1045 GenericValue Src1 = getOperandValue(I.getOperand(0), SF);
1046 GenericValue Src2 = getOperandValue(I.getOperand(1), SF);
Chris Lattner86660982001-08-27 05:16:50 +00001047 GenericValue Dest;
1048
1049 switch (Ty->getPrimitiveID()) {
1050 IMPLEMENT_SHIFT(<<, UByte);
1051 IMPLEMENT_SHIFT(<<, SByte);
1052 IMPLEMENT_SHIFT(<<, UShort);
1053 IMPLEMENT_SHIFT(<<, Short);
1054 IMPLEMENT_SHIFT(<<, UInt);
1055 IMPLEMENT_SHIFT(<<, Int);
Chris Lattner7b851ab2001-10-15 19:18:26 +00001056 IMPLEMENT_SHIFT(<<, ULong);
1057 IMPLEMENT_SHIFT(<<, Long);
Chris Lattner743cd3e2002-07-09 18:42:36 +00001058 IMPLEMENT_SHIFT(<<, Pointer);
Chris Lattner86660982001-08-27 05:16:50 +00001059 default:
Chris Lattner697954c2002-01-20 22:54:45 +00001060 cout << "Unhandled type for Shl instruction: " << Ty << "\n";
Chris Lattner86660982001-08-27 05:16:50 +00001061 }
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001062 SetValue(&I, Dest, SF);
Chris Lattner86660982001-08-27 05:16:50 +00001063}
1064
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001065static void executeShrInst(ShiftInst &I, ExecutionContext &SF) {
1066 const Type *Ty = I.getOperand(0)->getType();
1067 GenericValue Src1 = getOperandValue(I.getOperand(0), SF);
1068 GenericValue Src2 = getOperandValue(I.getOperand(1), SF);
Chris Lattner86660982001-08-27 05:16:50 +00001069 GenericValue Dest;
1070
1071 switch (Ty->getPrimitiveID()) {
1072 IMPLEMENT_SHIFT(>>, UByte);
1073 IMPLEMENT_SHIFT(>>, SByte);
1074 IMPLEMENT_SHIFT(>>, UShort);
1075 IMPLEMENT_SHIFT(>>, Short);
1076 IMPLEMENT_SHIFT(>>, UInt);
1077 IMPLEMENT_SHIFT(>>, Int);
Chris Lattner7b851ab2001-10-15 19:18:26 +00001078 IMPLEMENT_SHIFT(>>, ULong);
1079 IMPLEMENT_SHIFT(>>, Long);
Chris Lattner743cd3e2002-07-09 18:42:36 +00001080 IMPLEMENT_SHIFT(>>, Pointer);
Chris Lattner86660982001-08-27 05:16:50 +00001081 default:
Chris Lattner697954c2002-01-20 22:54:45 +00001082 cout << "Unhandled type for Shr instruction: " << Ty << "\n";
Chris Lattner86660982001-08-27 05:16:50 +00001083 }
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001084 SetValue(&I, Dest, SF);
Chris Lattner86660982001-08-27 05:16:50 +00001085}
1086
1087#define IMPLEMENT_CAST(DTY, DCTY, STY) \
Chris Lattnerea38c0e2001-11-07 19:46:27 +00001088 case Type::STY##TyID: Dest.DTY##Val = DCTY Src.STY##Val; break;
Chris Lattner86660982001-08-27 05:16:50 +00001089
1090#define IMPLEMENT_CAST_CASE_START(DESTTY, DESTCTY) \
1091 case Type::DESTTY##TyID: \
1092 switch (SrcTy->getPrimitiveID()) { \
Chris Lattnerf4dca802002-05-02 19:28:45 +00001093 IMPLEMENT_CAST(DESTTY, DESTCTY, Bool); \
Chris Lattner86660982001-08-27 05:16:50 +00001094 IMPLEMENT_CAST(DESTTY, DESTCTY, UByte); \
1095 IMPLEMENT_CAST(DESTTY, DESTCTY, SByte); \
1096 IMPLEMENT_CAST(DESTTY, DESTCTY, UShort); \
1097 IMPLEMENT_CAST(DESTTY, DESTCTY, Short); \
1098 IMPLEMENT_CAST(DESTTY, DESTCTY, UInt); \
Chris Lattner7b851ab2001-10-15 19:18:26 +00001099 IMPLEMENT_CAST(DESTTY, DESTCTY, Int); \
1100 IMPLEMENT_CAST(DESTTY, DESTCTY, ULong); \
Chris Lattnerc2593162001-10-27 08:28:11 +00001101 IMPLEMENT_CAST(DESTTY, DESTCTY, Long); \
1102 IMPLEMENT_CAST(DESTTY, DESTCTY, Pointer);
Chris Lattner86660982001-08-27 05:16:50 +00001103
1104#define IMPLEMENT_CAST_CASE_FP_IMP(DESTTY, DESTCTY) \
1105 IMPLEMENT_CAST(DESTTY, DESTCTY, Float); \
1106 IMPLEMENT_CAST(DESTTY, DESTCTY, Double)
1107
1108#define IMPLEMENT_CAST_CASE_END() \
Chris Lattner697954c2002-01-20 22:54:45 +00001109 default: cout << "Unhandled cast: " << SrcTy << " to " << Ty << "\n"; \
Chris Lattner86660982001-08-27 05:16:50 +00001110 break; \
1111 } \
1112 break
1113
1114#define IMPLEMENT_CAST_CASE(DESTTY, DESTCTY) \
1115 IMPLEMENT_CAST_CASE_START(DESTTY, DESTCTY); \
1116 IMPLEMENT_CAST_CASE_FP_IMP(DESTTY, DESTCTY); \
Chris Lattner86660982001-08-27 05:16:50 +00001117 IMPLEMENT_CAST_CASE_END()
1118
Chris Lattnera34c5682002-08-27 22:33:45 +00001119static GenericValue executeCastOperation(Value *SrcVal, const Type *Ty,
1120 ExecutionContext &SF) {
1121 const Type *SrcTy = SrcVal->getType();
1122 GenericValue Dest, Src = getOperandValue(SrcVal, SF);
Chris Lattner86660982001-08-27 05:16:50 +00001123
1124 switch (Ty->getPrimitiveID()) {
Chris Lattnerea38c0e2001-11-07 19:46:27 +00001125 IMPLEMENT_CAST_CASE(UByte , (unsigned char));
1126 IMPLEMENT_CAST_CASE(SByte , ( signed char));
1127 IMPLEMENT_CAST_CASE(UShort , (unsigned short));
Chris Lattner1bbd3612002-08-02 22:06:04 +00001128 IMPLEMENT_CAST_CASE(Short , ( signed short));
Chris Lattnerea38c0e2001-11-07 19:46:27 +00001129 IMPLEMENT_CAST_CASE(UInt , (unsigned int ));
1130 IMPLEMENT_CAST_CASE(Int , ( signed int ));
1131 IMPLEMENT_CAST_CASE(ULong , (uint64_t));
1132 IMPLEMENT_CAST_CASE(Long , ( int64_t));
Chris Lattner2fdaddf2002-10-30 21:47:57 +00001133 IMPLEMENT_CAST_CASE(Pointer, (PointerTy));
Chris Lattnerea38c0e2001-11-07 19:46:27 +00001134 IMPLEMENT_CAST_CASE(Float , (float));
1135 IMPLEMENT_CAST_CASE(Double , (double));
Chris Lattner86660982001-08-27 05:16:50 +00001136 default:
Chris Lattner697954c2002-01-20 22:54:45 +00001137 cout << "Unhandled dest type for cast instruction: " << Ty << "\n";
Chris Lattner86660982001-08-27 05:16:50 +00001138 }
Chris Lattnera34c5682002-08-27 22:33:45 +00001139
1140 return Dest;
Chris Lattner86660982001-08-27 05:16:50 +00001141}
Chris Lattner92101ac2001-08-23 17:05:04 +00001142
1143
Chris Lattnera34c5682002-08-27 22:33:45 +00001144static void executeCastInst(CastInst &I, ExecutionContext &SF) {
1145 SetValue(&I, executeCastOperation(I.getOperand(0), I.getType(), SF), SF);
1146}
Chris Lattner92101ac2001-08-23 17:05:04 +00001147
1148
1149//===----------------------------------------------------------------------===//
1150// Dispatch and Execution Code
1151//===----------------------------------------------------------------------===//
1152
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001153MethodInfo::MethodInfo(Function *F) : Annotation(MethodInfoAID) {
Chris Lattner2fbfdcf2002-04-07 20:49:59 +00001154 // Assign slot numbers to the function arguments...
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001155 for (Function::const_aiterator AI = F->abegin(), E = F->aend(); AI != E; ++AI)
1156 AI->addAnnotation(new SlotNumber(getValueSlot(AI)));
Chris Lattner92101ac2001-08-23 17:05:04 +00001157
1158 // Iterate over all of the instructions...
1159 unsigned InstNum = 0;
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001160 for (Function::iterator BB = F->begin(), BBE = F->end(); BB != BBE; ++BB)
1161 for (BasicBlock::iterator II = BB->begin(), IE = BB->end(); II != IE; ++II)
1162 // For each instruction... Add Annote
1163 II->addAnnotation(new InstNumber(++InstNum, getValueSlot(II)));
Chris Lattner92101ac2001-08-23 17:05:04 +00001164}
1165
1166unsigned MethodInfo::getValueSlot(const Value *V) {
1167 unsigned Plane = V->getType()->getUniqueID();
1168 if (Plane >= NumPlaneElements.size())
1169 NumPlaneElements.resize(Plane+1, 0);
1170 return NumPlaneElements[Plane]++;
1171}
1172
1173
Chris Lattner92101ac2001-08-23 17:05:04 +00001174//===----------------------------------------------------------------------===//
Chris Lattner2fbfdcf2002-04-07 20:49:59 +00001175// callMethod - Execute the specified function...
Chris Lattner92101ac2001-08-23 17:05:04 +00001176//
Chris Lattner2fbfdcf2002-04-07 20:49:59 +00001177void Interpreter::callMethod(Function *M, const vector<GenericValue> &ArgVals) {
Chris Lattner365a76e2001-09-10 04:49:44 +00001178 assert((ECStack.empty() || ECStack.back().Caller == 0 ||
1179 ECStack.back().Caller->getNumOperands()-1 == ArgVals.size()) &&
1180 "Incorrect number of arguments passed into function call!");
Chris Lattner92101ac2001-08-23 17:05:04 +00001181 if (M->isExternal()) {
Chris Lattnerbb76f022001-10-30 20:27:31 +00001182 GenericValue Result = callExternalMethod(M, ArgVals);
1183 const Type *RetTy = M->getReturnType();
1184
1185 // Copy the result back into the result variable if we are not returning
1186 // void.
1187 if (RetTy != Type::VoidTy) {
1188 if (!ECStack.empty() && ECStack.back().Caller) {
1189 ExecutionContext &SF = ECStack.back();
Chris Lattnerbb76f022001-10-30 20:27:31 +00001190 SetValue(SF.Caller, Result, SF);
1191
1192 SF.Caller = 0; // We returned from the call...
Chris Lattnerf23eb852001-12-14 16:49:29 +00001193 } else if (!QuietMode) {
Chris Lattnerbb76f022001-10-30 20:27:31 +00001194 // print it.
Chris Lattner2fbfdcf2002-04-07 20:49:59 +00001195 CW << "Function " << M->getType() << " \"" << M->getName()
Chris Lattner5af0c482001-11-07 04:23:00 +00001196 << "\" returned ";
Chris Lattnerbb76f022001-10-30 20:27:31 +00001197 print(RetTy, Result);
Chris Lattner697954c2002-01-20 22:54:45 +00001198 cout << "\n";
Chris Lattnerbb76f022001-10-30 20:27:31 +00001199
1200 if (RetTy->isIntegral())
Chris Lattner0c4e8862002-09-03 01:08:28 +00001201 ExitCode = Result.IntVal; // Capture the exit code of the program
Chris Lattnerbb76f022001-10-30 20:27:31 +00001202 }
1203 }
1204
Chris Lattner92101ac2001-08-23 17:05:04 +00001205 return;
1206 }
1207
Chris Lattner2fbfdcf2002-04-07 20:49:59 +00001208 // Process the function, assigning instruction numbers to the instructions in
1209 // the function. Also calculate the number of values for each type slot
1210 // active.
Chris Lattner92101ac2001-08-23 17:05:04 +00001211 //
1212 MethodInfo *MethInfo = (MethodInfo*)M->getOrCreateAnnotation(MethodInfoAID);
Chris Lattner92101ac2001-08-23 17:05:04 +00001213 ECStack.push_back(ExecutionContext()); // Make a new stack frame...
Chris Lattner86660982001-08-27 05:16:50 +00001214
Chris Lattner92101ac2001-08-23 17:05:04 +00001215 ExecutionContext &StackFrame = ECStack.back(); // Fill it in...
1216 StackFrame.CurMethod = M;
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001217 StackFrame.CurBB = M->begin();
Chris Lattner92101ac2001-08-23 17:05:04 +00001218 StackFrame.CurInst = StackFrame.CurBB->begin();
1219 StackFrame.MethInfo = MethInfo;
1220
1221 // Initialize the values to nothing...
1222 StackFrame.Values.resize(MethInfo->NumPlaneElements.size());
Chris Lattnerea38c0e2001-11-07 19:46:27 +00001223 for (unsigned i = 0; i < MethInfo->NumPlaneElements.size(); ++i) {
Chris Lattner92101ac2001-08-23 17:05:04 +00001224 StackFrame.Values[i].resize(MethInfo->NumPlaneElements[i]);
1225
Chris Lattnerea38c0e2001-11-07 19:46:27 +00001226 // Taint the initial values of stuff
1227 memset(&StackFrame.Values[i][0], 42,
1228 MethInfo->NumPlaneElements[i]*sizeof(GenericValue));
1229 }
1230
Chris Lattner92101ac2001-08-23 17:05:04 +00001231 StackFrame.PrevBB = 0; // No previous BB for PHI nodes...
1232
Chris Lattner92101ac2001-08-23 17:05:04 +00001233
Chris Lattner2fbfdcf2002-04-07 20:49:59 +00001234 // Run through the function arguments and initialize their values...
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001235 assert(ArgVals.size() == M->asize() &&
Chris Lattner2fbfdcf2002-04-07 20:49:59 +00001236 "Invalid number of values passed to function invocation!");
Chris Lattner365a76e2001-09-10 04:49:44 +00001237 unsigned i = 0;
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001238 for (Function::aiterator AI = M->abegin(), E = M->aend(); AI != E; ++AI, ++i)
1239 SetValue(AI, ArgVals[i], StackFrame);
Chris Lattner92101ac2001-08-23 17:05:04 +00001240}
1241
1242// executeInstruction - Interpret a single instruction, increment the "PC", and
1243// return true if the next instruction is a breakpoint...
1244//
1245bool Interpreter::executeInstruction() {
1246 assert(!ECStack.empty() && "No program running, cannot execute inst!");
1247
1248 ExecutionContext &SF = ECStack.back(); // Current stack frame
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001249 Instruction &I = *SF.CurInst++; // Increment before execute
Chris Lattner92101ac2001-08-23 17:05:04 +00001250
Chris Lattner43e3f7c2001-10-27 08:43:52 +00001251 if (Trace)
Chris Lattner5af0c482001-11-07 04:23:00 +00001252 CW << "Run:" << I;
1253
1254 // Set a sigsetjmp buffer so that we can recover if an error happens during
1255 // instruction execution...
1256 //
1257 if (int SigNo = sigsetjmp(SignalRecoverBuffer, 1)) {
1258 --SF.CurInst; // Back up to erroring instruction
Chris Lattner74030252002-02-12 15:47:23 +00001259 if (SigNo != SIGINT) {
Chris Lattner8b77be22002-09-13 14:41:38 +00001260 cout << "EXCEPTION OCCURRED [" << strsignal(SigNo) << "]:\n";
Chris Lattner461f02f2001-11-07 05:31:27 +00001261 printStackTrace();
Chris Lattner74030252002-02-12 15:47:23 +00001262 // If -abort-on-exception was specified, terminate LLI instead of trying
1263 // to debug it.
1264 //
1265 if (AbortOnExceptions) exit(1);
Chris Lattner782b9392001-11-26 18:18:18 +00001266 } else if (SigNo == SIGINT) {
Chris Lattner461f02f2001-11-07 05:31:27 +00001267 cout << "CTRL-C Detected, execution halted.\n";
1268 }
1269 InInstruction = false;
Chris Lattner5af0c482001-11-07 04:23:00 +00001270 return true;
1271 }
Chris Lattner43e3f7c2001-10-27 08:43:52 +00001272
Chris Lattner461f02f2001-11-07 05:31:27 +00001273 InInstruction = true;
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001274 if (I.isBinaryOp()) {
Chris Lattnerbb76f022001-10-30 20:27:31 +00001275 executeBinaryInst(cast<BinaryOperator>(I), SF);
Chris Lattner92101ac2001-08-23 17:05:04 +00001276 } else {
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001277 switch (I.getOpcode()) {
Chris Lattner86660982001-08-27 05:16:50 +00001278 // Terminators
Chris Lattnerbb76f022001-10-30 20:27:31 +00001279 case Instruction::Ret: executeRetInst (cast<ReturnInst>(I), SF); break;
1280 case Instruction::Br: executeBrInst (cast<BranchInst>(I), SF); break;
Chris Lattner86660982001-08-27 05:16:50 +00001281 // Memory Instructions
1282 case Instruction::Alloca:
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001283 case Instruction::Malloc: executeAllocInst((AllocationInst&)I, SF); break;
Chris Lattnerbb76f022001-10-30 20:27:31 +00001284 case Instruction::Free: executeFreeInst (cast<FreeInst> (I), SF); break;
1285 case Instruction::Load: executeLoadInst (cast<LoadInst> (I), SF); break;
1286 case Instruction::Store: executeStoreInst(cast<StoreInst>(I), SF); break;
Chris Lattner95c3af52001-10-29 19:32:19 +00001287 case Instruction::GetElementPtr:
1288 executeGEPInst(cast<GetElementPtrInst>(I), SF); break;
Chris Lattner86660982001-08-27 05:16:50 +00001289
1290 // Miscellaneous Instructions
Chris Lattnerbb76f022001-10-30 20:27:31 +00001291 case Instruction::Call: executeCallInst (cast<CallInst> (I), SF); break;
1292 case Instruction::PHINode: executePHINode (cast<PHINode> (I), SF); break;
1293 case Instruction::Shl: executeShlInst (cast<ShiftInst>(I), SF); break;
1294 case Instruction::Shr: executeShrInst (cast<ShiftInst>(I), SF); break;
1295 case Instruction::Cast: executeCastInst (cast<CastInst> (I), SF); break;
Chris Lattner92101ac2001-08-23 17:05:04 +00001296 default:
1297 cout << "Don't know how to execute this instruction!\n-->" << I;
1298 }
1299 }
Chris Lattner461f02f2001-11-07 05:31:27 +00001300 InInstruction = false;
Chris Lattner92101ac2001-08-23 17:05:04 +00001301
1302 // Reset the current frame location to the top of stack
1303 CurFrame = ECStack.size()-1;
1304
1305 if (CurFrame == -1) return false; // No breakpoint if no code
1306
1307 // Return true if there is a breakpoint annotation on the instruction...
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001308 return ECStack[CurFrame].CurInst->getAnnotation(BreakpointAID) != 0;
Chris Lattner92101ac2001-08-23 17:05:04 +00001309}
1310
1311void Interpreter::stepInstruction() { // Do the 'step' command
1312 if (ECStack.empty()) {
1313 cout << "Error: no program running, cannot step!\n";
1314 return;
1315 }
1316
1317 // Run an instruction...
1318 executeInstruction();
1319
1320 // Print the next instruction to execute...
1321 printCurrentInstruction();
1322}
1323
1324// --- UI Stuff...
Chris Lattner92101ac2001-08-23 17:05:04 +00001325void Interpreter::nextInstruction() { // Do the 'next' command
1326 if (ECStack.empty()) {
1327 cout << "Error: no program running, cannot 'next'!\n";
1328 return;
1329 }
1330
1331 // If this is a call instruction, step over the call instruction...
1332 // TODO: ICALL, CALL WITH, ...
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001333 if (ECStack.back().CurInst->getOpcode() == Instruction::Call) {
Chris Lattnera74a6b52001-10-29 14:08:33 +00001334 unsigned StackSize = ECStack.size();
Chris Lattner92101ac2001-08-23 17:05:04 +00001335 // Step into the function...
1336 if (executeInstruction()) {
1337 // Hit a breakpoint, print current instruction, then return to user...
1338 cout << "Breakpoint hit!\n";
1339 printCurrentInstruction();
1340 return;
1341 }
1342
Chris Lattnera74a6b52001-10-29 14:08:33 +00001343 // If we we able to step into the function, finish it now. We might not be
1344 // able the step into a function, if it's external for example.
1345 if (ECStack.size() != StackSize)
1346 finish(); // Finish executing the function...
Chris Lattner069aa252001-10-29 16:05:19 +00001347 else
1348 printCurrentInstruction();
Chris Lattnera74a6b52001-10-29 14:08:33 +00001349
Chris Lattner92101ac2001-08-23 17:05:04 +00001350 } else {
1351 // Normal instruction, just step...
1352 stepInstruction();
1353 }
1354}
1355
1356void Interpreter::run() {
1357 if (ECStack.empty()) {
1358 cout << "Error: no program running, cannot run!\n";
1359 return;
1360 }
1361
1362 bool HitBreakpoint = false;
1363 while (!ECStack.empty() && !HitBreakpoint) {
1364 // Run an instruction...
1365 HitBreakpoint = executeInstruction();
1366 }
1367
1368 if (HitBreakpoint) {
1369 cout << "Breakpoint hit!\n";
1370 }
Chris Lattner92101ac2001-08-23 17:05:04 +00001371 // Print the next instruction to execute...
1372 printCurrentInstruction();
1373}
1374
1375void Interpreter::finish() {
1376 if (ECStack.empty()) {
1377 cout << "Error: no program running, cannot run!\n";
1378 return;
1379 }
1380
1381 unsigned StackSize = ECStack.size();
1382 bool HitBreakpoint = false;
1383 while (ECStack.size() >= StackSize && !HitBreakpoint) {
1384 // Run an instruction...
1385 HitBreakpoint = executeInstruction();
1386 }
1387
1388 if (HitBreakpoint) {
1389 cout << "Breakpoint hit!\n";
1390 }
1391
1392 // Print the next instruction to execute...
1393 printCurrentInstruction();
1394}
1395
1396
1397
1398// printCurrentInstruction - Print out the instruction that the virtual PC is
1399// at, or fail silently if no program is running.
1400//
1401void Interpreter::printCurrentInstruction() {
1402 if (!ECStack.empty()) {
Chris Lattnerf5b2ec12001-10-29 20:44:34 +00001403 if (ECStack.back().CurBB->begin() == ECStack.back().CurInst) // print label
1404 WriteAsOperand(cout, ECStack.back().CurBB) << ":\n";
1405
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001406 Instruction &I = *ECStack.back().CurInst;
1407 InstNumber *IN = (InstNumber*)I.getAnnotation(SlotNumberAID);
Chris Lattner92101ac2001-08-23 17:05:04 +00001408 assert(IN && "Instruction has no numbering annotation!");
1409 cout << "#" << IN->InstNum << I;
1410 }
1411}
1412
1413void Interpreter::printValue(const Type *Ty, GenericValue V) {
Chris Lattner92101ac2001-08-23 17:05:04 +00001414 switch (Ty->getPrimitiveID()) {
1415 case Type::BoolTyID: cout << (V.BoolVal?"true":"false"); break;
Chris Lattner65629d52002-08-13 20:45:11 +00001416 case Type::SByteTyID:
1417 cout << (int)V.SByteVal << " '" << V.SByteVal << "'"; break;
1418 case Type::UByteTyID:
1419 cout << (unsigned)V.UByteVal << " '" << V.UByteVal << "'"; break;
Chris Lattner92101ac2001-08-23 17:05:04 +00001420 case Type::ShortTyID: cout << V.ShortVal; break;
1421 case Type::UShortTyID: cout << V.UShortVal; break;
1422 case Type::IntTyID: cout << V.IntVal; break;
1423 case Type::UIntTyID: cout << V.UIntVal; break;
Chris Lattner697954c2002-01-20 22:54:45 +00001424 case Type::LongTyID: cout << (long)V.LongVal; break;
1425 case Type::ULongTyID: cout << (unsigned long)V.ULongVal; break;
Chris Lattner92101ac2001-08-23 17:05:04 +00001426 case Type::FloatTyID: cout << V.FloatVal; break;
1427 case Type::DoubleTyID: cout << V.DoubleVal; break;
Chris Lattnerea38c0e2001-11-07 19:46:27 +00001428 case Type::PointerTyID:cout << (void*)V.PointerVal; break;
Chris Lattner92101ac2001-08-23 17:05:04 +00001429 default:
1430 cout << "- Don't know how to print value of this type!";
1431 break;
1432 }
1433}
1434
Chris Lattner2e42d3a2001-10-15 05:51:48 +00001435void Interpreter::print(const Type *Ty, GenericValue V) {
Chris Lattner5af0c482001-11-07 04:23:00 +00001436 CW << Ty << " ";
Chris Lattner2e42d3a2001-10-15 05:51:48 +00001437 printValue(Ty, V);
1438}
1439
Chris Lattner697954c2002-01-20 22:54:45 +00001440void Interpreter::print(const std::string &Name) {
Chris Lattner92101ac2001-08-23 17:05:04 +00001441 Value *PickedVal = ChooseOneOption(Name, LookupMatchingNames(Name));
1442 if (!PickedVal) return;
1443
Chris Lattner2fbfdcf2002-04-07 20:49:59 +00001444 if (const Function *F = dyn_cast<const Function>(PickedVal)) {
1445 CW << F; // Print the function
Chris Lattnerea38c0e2001-11-07 19:46:27 +00001446 } else if (const Type *Ty = dyn_cast<const Type>(PickedVal)) {
Chris Lattner697954c2002-01-20 22:54:45 +00001447 CW << "type %" << Name << " = " << Ty->getDescription() << "\n";
Chris Lattnerea38c0e2001-11-07 19:46:27 +00001448 } else if (const BasicBlock *BB = dyn_cast<const BasicBlock>(PickedVal)) {
1449 CW << BB; // Print the basic block
Chris Lattner92101ac2001-08-23 17:05:04 +00001450 } else { // Otherwise there should be an annotation for the slot#
Chris Lattner2e42d3a2001-10-15 05:51:48 +00001451 print(PickedVal->getType(),
1452 getOperandValue(PickedVal, ECStack[CurFrame]));
Chris Lattner697954c2002-01-20 22:54:45 +00001453 cout << "\n";
Chris Lattner92101ac2001-08-23 17:05:04 +00001454 }
Chris Lattner92101ac2001-08-23 17:05:04 +00001455}
1456
Chris Lattner697954c2002-01-20 22:54:45 +00001457void Interpreter::infoValue(const std::string &Name) {
Chris Lattner86660982001-08-27 05:16:50 +00001458 Value *PickedVal = ChooseOneOption(Name, LookupMatchingNames(Name));
1459 if (!PickedVal) return;
1460
1461 cout << "Value: ";
Chris Lattner2e42d3a2001-10-15 05:51:48 +00001462 print(PickedVal->getType(),
1463 getOperandValue(PickedVal, ECStack[CurFrame]));
Chris Lattner697954c2002-01-20 22:54:45 +00001464 cout << "\n";
Chris Lattner86660982001-08-27 05:16:50 +00001465 printOperandInfo(PickedVal, ECStack[CurFrame]);
1466}
1467
Chris Lattner461f02f2001-11-07 05:31:27 +00001468// printStackFrame - Print information about the specified stack frame, or -1
1469// for the default one.
1470//
Chris Lattner601d7152002-07-25 17:37:05 +00001471void Interpreter::printStackFrame(int FrameNo) {
Chris Lattner461f02f2001-11-07 05:31:27 +00001472 if (FrameNo == -1) FrameNo = CurFrame;
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001473 Function *F = ECStack[FrameNo].CurMethod;
1474 const Type *RetTy = F->getReturnType();
Chris Lattnerea38c0e2001-11-07 19:46:27 +00001475
1476 CW << ((FrameNo == CurFrame) ? '>' : '-') << "#" << FrameNo << ". "
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001477 << (Value*)RetTy << " \"" << F->getName() << "\"(";
Chris Lattner461f02f2001-11-07 05:31:27 +00001478
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001479 unsigned i = 0;
1480 for (Function::aiterator I = F->abegin(), E = F->aend(); I != E; ++I, ++i) {
Chris Lattner461f02f2001-11-07 05:31:27 +00001481 if (i != 0) cout << ", ";
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001482 CW << *I << "=";
Chris Lattner461f02f2001-11-07 05:31:27 +00001483
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001484 printValue(I->getType(), getOperandValue(I, ECStack[FrameNo]));
Chris Lattner92101ac2001-08-23 17:05:04 +00001485 }
Chris Lattner461f02f2001-11-07 05:31:27 +00001486
Chris Lattner697954c2002-01-20 22:54:45 +00001487 cout << ")\n";
Chris Lattner0b12b5f2002-06-25 16:13:21 +00001488
1489 if (FrameNo != int(ECStack.size()-1)) {
1490 BasicBlock::iterator I = ECStack[FrameNo].CurInst;
1491 CW << --I;
1492 } else {
1493 CW << *ECStack[FrameNo].CurInst;
1494 }
Chris Lattner92101ac2001-08-23 17:05:04 +00001495}
Chris Lattner461f02f2001-11-07 05:31:27 +00001496