blob: 9ad6b57ecd734f5151e9f0505d5d862c3a55f429 [file] [log] [blame]
Misha Brukman4afac182003-10-10 17:45:12 +00001//===-- ExecutionEngine.cpp - Common Implementation shared by EEs ---------===//
Misha Brukmanedf128a2005-04-21 22:36:52 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukmanedf128a2005-04-21 22:36:52 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Misha Brukmanedf128a2005-04-21 22:36:52 +00009//
Chris Lattnerbd199fb2002-12-24 00:01:05 +000010// This file defines the common interface used by the various execution engine
11// subclasses.
12//
13//===----------------------------------------------------------------------===//
14
Chris Lattner3785fad2003-08-05 17:00:32 +000015#define DEBUG_TYPE "jit"
Chris Lattnerbd199fb2002-12-24 00:01:05 +000016#include "llvm/Constants.h"
Misha Brukman19684162003-10-16 21:18:05 +000017#include "llvm/DerivedTypes.h"
Chris Lattnerbd199fb2002-12-24 00:01:05 +000018#include "llvm/Module.h"
Misha Brukman19684162003-10-16 21:18:05 +000019#include "llvm/ModuleProvider.h"
Reid Spencerdf5a37e2004-11-29 14:11:29 +000020#include "llvm/ADT/Statistic.h"
Misha Brukman19684162003-10-16 21:18:05 +000021#include "llvm/ExecutionEngine/ExecutionEngine.h"
Chris Lattnerfd131292003-09-05 20:08:15 +000022#include "llvm/ExecutionEngine/GenericValue.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000023#include "llvm/Support/Debug.h"
Chris Lattnere7fd5532006-05-08 22:00:52 +000024#include "llvm/Support/MutexGuard.h"
Reid Spencerdf5a37e2004-11-29 14:11:29 +000025#include "llvm/System/DynamicLibrary.h"
26#include "llvm/Target/TargetData.h"
Chris Lattner2fe4bb02006-03-22 06:07:50 +000027#include <iostream>
Chris Lattnerc2ee9b92003-11-19 21:08:57 +000028using namespace llvm;
Chris Lattnerbd199fb2002-12-24 00:01:05 +000029
Chris Lattnerc2ee9b92003-11-19 21:08:57 +000030namespace {
31 Statistic<> NumInitBytes("lli", "Number of bytes of global vars initialized");
Chris Lattner24b0a182003-12-20 02:45:37 +000032 Statistic<> NumGlobals ("lli", "Number of global vars initialized");
Chris Lattnerc2ee9b92003-11-19 21:08:57 +000033}
Chris Lattnerbd199fb2002-12-24 00:01:05 +000034
Chris Lattner2fe4bb02006-03-22 06:07:50 +000035ExecutionEngine::EECtorFn ExecutionEngine::JITCtor = 0;
36ExecutionEngine::EECtorFn ExecutionEngine::InterpCtor = 0;
37
Chris Lattnerfe854032006-08-16 01:24:12 +000038ExecutionEngine::ExecutionEngine(ModuleProvider *P) {
39 Modules.push_back(P);
Misha Brukman19684162003-10-16 21:18:05 +000040 assert(P && "ModuleProvider is null?");
41}
42
Chris Lattnerfe854032006-08-16 01:24:12 +000043ExecutionEngine::ExecutionEngine(Module *M) {
Misha Brukman05701572003-10-17 18:31:59 +000044 assert(M && "Module is null?");
Chris Lattnerfe854032006-08-16 01:24:12 +000045 Modules.push_back(new ExistingModuleProvider(M));
Misha Brukman19684162003-10-16 21:18:05 +000046}
47
Brian Gaeke8e539482003-09-04 22:57:27 +000048ExecutionEngine::~ExecutionEngine() {
Chris Lattnerfe854032006-08-16 01:24:12 +000049 for (unsigned i = 0, e = Modules.size(); i != e; ++i)
50 delete Modules[i];
Brian Gaeke8e539482003-09-04 22:57:27 +000051}
52
Chris Lattnerfe854032006-08-16 01:24:12 +000053/// FindFunctionNamed - Search all of the active modules to find the one that
54/// defines FnName. This is very slow operation and shouldn't be used for
55/// general code.
56Function *ExecutionEngine::FindFunctionNamed(const char *FnName) {
57 for (unsigned i = 0, e = Modules.size(); i != e; ++i) {
58 if (Function *F = Modules[i]->getModule()->getNamedFunction(FnName))
59 return F;
60 }
61 return 0;
62}
63
64
Chris Lattnere7fd5532006-05-08 22:00:52 +000065/// addGlobalMapping - Tell the execution engine that the specified global is
66/// at the specified location. This is used internally as functions are JIT'd
67/// and as global variables are laid out in memory. It can and should also be
68/// used by clients of the EE that want to have an LLVM global overlay
69/// existing data in memory.
70void ExecutionEngine::addGlobalMapping(const GlobalValue *GV, void *Addr) {
71 MutexGuard locked(lock);
72
73 void *&CurVal = state.getGlobalAddressMap(locked)[GV];
74 assert((CurVal == 0 || Addr == 0) && "GlobalMapping already established!");
75 CurVal = Addr;
76
77 // If we are using the reverse mapping, add it too
78 if (!state.getGlobalAddressReverseMap(locked).empty()) {
79 const GlobalValue *&V = state.getGlobalAddressReverseMap(locked)[Addr];
80 assert((V == 0 || GV == 0) && "GlobalMapping already established!");
81 V = GV;
82 }
83}
84
85/// clearAllGlobalMappings - Clear all global mappings and start over again
86/// use in dynamic compilation scenarios when you want to move globals
87void ExecutionEngine::clearAllGlobalMappings() {
88 MutexGuard locked(lock);
89
90 state.getGlobalAddressMap(locked).clear();
91 state.getGlobalAddressReverseMap(locked).clear();
92}
93
94/// updateGlobalMapping - Replace an existing mapping for GV with a new
95/// address. This updates both maps as required. If "Addr" is null, the
96/// entry for the global is removed from the mappings.
97void ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, void *Addr) {
98 MutexGuard locked(lock);
99
100 // Deleting from the mapping?
101 if (Addr == 0) {
102 state.getGlobalAddressMap(locked).erase(GV);
103 if (!state.getGlobalAddressReverseMap(locked).empty())
104 state.getGlobalAddressReverseMap(locked).erase(Addr);
105 return;
106 }
107
108 void *&CurVal = state.getGlobalAddressMap(locked)[GV];
109 if (CurVal && !state.getGlobalAddressReverseMap(locked).empty())
110 state.getGlobalAddressReverseMap(locked).erase(CurVal);
111 CurVal = Addr;
112
113 // If we are using the reverse mapping, add it too
114 if (!state.getGlobalAddressReverseMap(locked).empty()) {
115 const GlobalValue *&V = state.getGlobalAddressReverseMap(locked)[Addr];
116 assert((V == 0 || GV == 0) && "GlobalMapping already established!");
117 V = GV;
118 }
119}
120
121/// getPointerToGlobalIfAvailable - This returns the address of the specified
122/// global value if it is has already been codegen'd, otherwise it returns null.
123///
124void *ExecutionEngine::getPointerToGlobalIfAvailable(const GlobalValue *GV) {
125 MutexGuard locked(lock);
126
127 std::map<const GlobalValue*, void*>::iterator I =
128 state.getGlobalAddressMap(locked).find(GV);
129 return I != state.getGlobalAddressMap(locked).end() ? I->second : 0;
130}
131
Chris Lattner55d86482003-12-31 20:21:04 +0000132/// getGlobalValueAtAddress - Return the LLVM global value object that starts
133/// at the specified address.
134///
135const GlobalValue *ExecutionEngine::getGlobalValueAtAddress(void *Addr) {
Reid Spenceree448632005-07-12 15:51:55 +0000136 MutexGuard locked(lock);
137
Chris Lattner55d86482003-12-31 20:21:04 +0000138 // If we haven't computed the reverse mapping yet, do so first.
Reid Spenceree448632005-07-12 15:51:55 +0000139 if (state.getGlobalAddressReverseMap(locked).empty()) {
Chris Lattnere7fd5532006-05-08 22:00:52 +0000140 for (std::map<const GlobalValue*, void *>::iterator
141 I = state.getGlobalAddressMap(locked).begin(),
142 E = state.getGlobalAddressMap(locked).end(); I != E; ++I)
143 state.getGlobalAddressReverseMap(locked).insert(std::make_pair(I->second,
144 I->first));
Chris Lattner55d86482003-12-31 20:21:04 +0000145 }
146
147 std::map<void *, const GlobalValue*>::iterator I =
Reid Spenceree448632005-07-12 15:51:55 +0000148 state.getGlobalAddressReverseMap(locked).find(Addr);
149 return I != state.getGlobalAddressReverseMap(locked).end() ? I->second : 0;
Chris Lattner55d86482003-12-31 20:21:04 +0000150}
Chris Lattner87f03102003-12-26 06:50:30 +0000151
152// CreateArgv - Turn a vector of strings into a nice argv style array of
153// pointers to null terminated strings.
154//
155static void *CreateArgv(ExecutionEngine *EE,
156 const std::vector<std::string> &InputArgv) {
Owen Andersona69571c2006-05-03 01:29:57 +0000157 unsigned PtrSize = EE->getTargetData()->getPointerSize();
Chris Lattner87f03102003-12-26 06:50:30 +0000158 char *Result = new char[(InputArgv.size()+1)*PtrSize];
159
160 DEBUG(std::cerr << "ARGV = " << (void*)Result << "\n");
161 const Type *SBytePtr = PointerType::get(Type::SByteTy);
162
163 for (unsigned i = 0; i != InputArgv.size(); ++i) {
164 unsigned Size = InputArgv[i].size()+1;
165 char *Dest = new char[Size];
166 DEBUG(std::cerr << "ARGV[" << i << "] = " << (void*)Dest << "\n");
Misha Brukmanedf128a2005-04-21 22:36:52 +0000167
Chris Lattner87f03102003-12-26 06:50:30 +0000168 std::copy(InputArgv[i].begin(), InputArgv[i].end(), Dest);
169 Dest[Size-1] = 0;
Misha Brukmanedf128a2005-04-21 22:36:52 +0000170
Chris Lattner87f03102003-12-26 06:50:30 +0000171 // Endian safe: Result[i] = (PointerTy)Dest;
172 EE->StoreValueToMemory(PTOGV(Dest), (GenericValue*)(Result+i*PtrSize),
173 SBytePtr);
174 }
175
176 // Null terminate it
177 EE->StoreValueToMemory(PTOGV(0),
178 (GenericValue*)(Result+InputArgv.size()*PtrSize),
179 SBytePtr);
180 return Result;
181}
182
Chris Lattner9ca6cda2006-03-08 18:42:46 +0000183
184/// runStaticConstructorsDestructors - This method is used to execute all of
Chris Lattnerfe854032006-08-16 01:24:12 +0000185/// the static constructors or destructors for a program, depending on the
Chris Lattner9ca6cda2006-03-08 18:42:46 +0000186/// value of isDtors.
187void ExecutionEngine::runStaticConstructorsDestructors(bool isDtors) {
188 const char *Name = isDtors ? "llvm.global_dtors" : "llvm.global_ctors";
Chris Lattner9ca6cda2006-03-08 18:42:46 +0000189
Chris Lattnerfe854032006-08-16 01:24:12 +0000190 // Execute global ctors/dtors for each module in the program.
191 for (unsigned m = 0, e = Modules.size(); m != e; ++m) {
192 GlobalVariable *GV = Modules[m]->getModule()->getNamedGlobal(Name);
193
194 // If this global has internal linkage, or if it has a use, then it must be
195 // an old-style (llvmgcc3) static ctor with __main linked in and in use. If
196 // this is the case, don't execute any of the global ctors, __main will do
197 // it.
198 if (!GV || GV->isExternal() || GV->hasInternalLinkage()) continue;
199
200 // Should be an array of '{ int, void ()* }' structs. The first value is
201 // the init priority, which we ignore.
202 ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer());
203 if (!InitList) continue;
204 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
205 if (ConstantStruct *CS =
206 dyn_cast<ConstantStruct>(InitList->getOperand(i))) {
207 if (CS->getNumOperands() != 2) break; // Not array of 2-element structs.
Chris Lattner9ca6cda2006-03-08 18:42:46 +0000208
Chris Lattnerfe854032006-08-16 01:24:12 +0000209 Constant *FP = CS->getOperand(1);
210 if (FP->isNullValue())
211 break; // Found a null terminator, exit.
Chris Lattner9ca6cda2006-03-08 18:42:46 +0000212
Chris Lattnerfe854032006-08-16 01:24:12 +0000213 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(FP))
214 if (CE->getOpcode() == Instruction::Cast)
215 FP = CE->getOperand(0);
216 if (Function *F = dyn_cast<Function>(FP)) {
217 // Execute the ctor/dtor function!
218 runFunction(F, std::vector<GenericValue>());
219 }
Chris Lattner9ca6cda2006-03-08 18:42:46 +0000220 }
Chris Lattnerfe854032006-08-16 01:24:12 +0000221 }
Chris Lattner9ca6cda2006-03-08 18:42:46 +0000222}
223
Chris Lattner87f03102003-12-26 06:50:30 +0000224/// runFunctionAsMain - This is a helper function which wraps runFunction to
225/// handle the common task of starting up main with the specified argc, argv,
226/// and envp parameters.
227int ExecutionEngine::runFunctionAsMain(Function *Fn,
228 const std::vector<std::string> &argv,
229 const char * const * envp) {
230 std::vector<GenericValue> GVArgs;
231 GenericValue GVArgc;
232 GVArgc.IntVal = argv.size();
Chris Lattnerf24d0992004-08-16 01:05:35 +0000233 unsigned NumArgs = Fn->getFunctionType()->getNumParams();
234 if (NumArgs) {
235 GVArgs.push_back(GVArgc); // Arg #0 = argc.
236 if (NumArgs > 1) {
237 GVArgs.push_back(PTOGV(CreateArgv(this, argv))); // Arg #1 = argv.
238 assert(((char **)GVTOP(GVArgs[1]))[0] &&
239 "argv[0] was null after CreateArgv");
240 if (NumArgs > 2) {
241 std::vector<std::string> EnvVars;
242 for (unsigned i = 0; envp[i]; ++i)
243 EnvVars.push_back(envp[i]);
244 GVArgs.push_back(PTOGV(CreateArgv(this, EnvVars))); // Arg #2 = envp.
245 }
246 }
247 }
Chris Lattner87f03102003-12-26 06:50:30 +0000248 return runFunction(Fn, GVArgs).IntVal;
249}
250
Misha Brukman19684162003-10-16 21:18:05 +0000251/// If possible, create a JIT, unless the caller specifically requests an
252/// Interpreter or there's an error. If even an Interpreter cannot be created,
Misha Brukmanedf128a2005-04-21 22:36:52 +0000253/// NULL is returned.
Misha Brukman4afac182003-10-10 17:45:12 +0000254///
Misha Brukmanedf128a2005-04-21 22:36:52 +0000255ExecutionEngine *ExecutionEngine::create(ModuleProvider *MP,
Chris Lattner726c1ef2006-03-23 05:22:51 +0000256 bool ForceInterpreter) {
Brian Gaeke82d82772003-09-03 20:34:19 +0000257 ExecutionEngine *EE = 0;
258
Chris Lattner73011782003-12-28 09:44:37 +0000259 // Unless the interpreter was explicitly selected, try making a JIT.
Chris Lattner2fe4bb02006-03-22 06:07:50 +0000260 if (!ForceInterpreter && JITCtor)
Chris Lattner726c1ef2006-03-23 05:22:51 +0000261 EE = JITCtor(MP);
Brian Gaeke82d82772003-09-03 20:34:19 +0000262
263 // If we can't make a JIT, make an interpreter instead.
Chris Lattner2fe4bb02006-03-22 06:07:50 +0000264 if (EE == 0 && InterpCtor)
Chris Lattner726c1ef2006-03-23 05:22:51 +0000265 EE = InterpCtor(MP);
Chris Lattner73011782003-12-28 09:44:37 +0000266
Chris Lattner726c1ef2006-03-23 05:22:51 +0000267 if (EE) {
Misha Brukmanedf128a2005-04-21 22:36:52 +0000268 // Make sure we can resolve symbols in the program as well. The zero arg
Reid Spencerdf5a37e2004-11-29 14:11:29 +0000269 // to the function tells DynamicLibrary to load the program, not a library.
Chris Lattner6f3ada52006-05-14 19:01:55 +0000270 try {
271 sys::DynamicLibrary::LoadLibraryPermanently(0);
272 } catch (...) {
273 }
Chris Lattner726c1ef2006-03-23 05:22:51 +0000274 }
Reid Spencerdf5a37e2004-11-29 14:11:29 +0000275
Brian Gaeke82d82772003-09-03 20:34:19 +0000276 return EE;
277}
278
Misha Brukman4afac182003-10-10 17:45:12 +0000279/// getPointerToGlobal - This returns the address of the specified global
280/// value. This may involve code generation if it's a function.
281///
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000282void *ExecutionEngine::getPointerToGlobal(const GlobalValue *GV) {
Brian Gaeke37df4602003-08-13 18:16:14 +0000283 if (Function *F = const_cast<Function*>(dyn_cast<Function>(GV)))
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000284 return getPointerToFunction(F);
285
Reid Spenceree448632005-07-12 15:51:55 +0000286 MutexGuard locked(lock);
Jeff Cohen68835dd2006-02-07 05:11:57 +0000287 void *p = state.getGlobalAddressMap(locked)[GV];
288 if (p)
289 return p;
290
291 // Global variable might have been added since interpreter started.
292 if (GlobalVariable *GVar =
293 const_cast<GlobalVariable *>(dyn_cast<GlobalVariable>(GV)))
294 EmitGlobalVariable(GVar);
295 else
296 assert("Global hasn't had an address allocated yet!");
Reid Spenceree448632005-07-12 15:51:55 +0000297 return state.getGlobalAddressMap(locked)[GV];
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000298}
299
Misha Brukman4afac182003-10-10 17:45:12 +0000300/// FIXME: document
Misha Brukmanedf128a2005-04-21 22:36:52 +0000301///
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000302GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
303 GenericValue Result;
Chris Lattner6f335f92004-10-26 05:35:14 +0000304 if (isa<UndefValue>(C)) return Result;
Chris Lattnerd8c03bf2003-04-23 19:01:49 +0000305
Chris Lattner9a231222003-05-14 17:51:49 +0000306 if (ConstantExpr *CE = const_cast<ConstantExpr*>(dyn_cast<ConstantExpr>(C))) {
Chris Lattnerd8c03bf2003-04-23 19:01:49 +0000307 switch (CE->getOpcode()) {
308 case Instruction::GetElementPtr: {
Chris Lattner9a231222003-05-14 17:51:49 +0000309 Result = getConstantValue(CE->getOperand(0));
Chris Lattnerd8c03bf2003-04-23 19:01:49 +0000310 std::vector<Value*> Indexes(CE->op_begin()+1, CE->op_end());
311 uint64_t Offset =
312 TD->getIndexedOffset(CE->getOperand(0)->getType(), Indexes);
Misha Brukmanedf128a2005-04-21 22:36:52 +0000313
Owen Andersona69571c2006-05-03 01:29:57 +0000314 if (getTargetData()->getPointerSize() == 4)
Chris Lattner3db4b622005-10-23 23:54:56 +0000315 Result.IntVal += Offset;
316 else
317 Result.LongVal += Offset;
Chris Lattnerd8c03bf2003-04-23 19:01:49 +0000318 return Result;
319 }
Chris Lattner9a231222003-05-14 17:51:49 +0000320 case Instruction::Cast: {
321 // We only need to handle a few cases here. Almost all casts will
322 // automatically fold, just the ones involving pointers won't.
323 //
324 Constant *Op = CE->getOperand(0);
Chris Lattner7d1bd332004-03-16 08:38:56 +0000325 GenericValue GV = getConstantValue(Op);
Chris Lattnerd8c03bf2003-04-23 19:01:49 +0000326
Chris Lattner9a231222003-05-14 17:51:49 +0000327 // Handle cast of pointer to pointer...
Chris Lattnerf70c22b2004-06-17 18:19:28 +0000328 if (Op->getType()->getTypeID() == C->getType()->getTypeID())
Chris Lattner7d1bd332004-03-16 08:38:56 +0000329 return GV;
Chris Lattner9a231222003-05-14 17:51:49 +0000330
Chris Lattner74cf8192003-08-18 17:23:40 +0000331 // Handle a cast of pointer to any integral type...
Chris Lattnerc88a4ea2003-08-18 17:33:15 +0000332 if (isa<PointerType>(Op->getType()) && C->getType()->isIntegral())
Chris Lattner7d1bd332004-03-16 08:38:56 +0000333 return GV;
Misha Brukmanedf128a2005-04-21 22:36:52 +0000334
Chris Lattner7d1bd332004-03-16 08:38:56 +0000335 // Handle cast of integer to a pointer...
336 if (isa<PointerType>(C->getType()) && Op->getType()->isIntegral())
Chris Lattnerf70c22b2004-06-17 18:19:28 +0000337 switch (Op->getType()->getTypeID()) {
Chris Lattner7d1bd332004-03-16 08:38:56 +0000338 case Type::BoolTyID: return PTOGV((void*)(uintptr_t)GV.BoolVal);
339 case Type::SByteTyID: return PTOGV((void*)( intptr_t)GV.SByteVal);
340 case Type::UByteTyID: return PTOGV((void*)(uintptr_t)GV.UByteVal);
341 case Type::ShortTyID: return PTOGV((void*)( intptr_t)GV.ShortVal);
342 case Type::UShortTyID: return PTOGV((void*)(uintptr_t)GV.UShortVal);
343 case Type::IntTyID: return PTOGV((void*)( intptr_t)GV.IntVal);
344 case Type::UIntTyID: return PTOGV((void*)(uintptr_t)GV.UIntVal);
345 case Type::LongTyID: return PTOGV((void*)( intptr_t)GV.LongVal);
346 case Type::ULongTyID: return PTOGV((void*)(uintptr_t)GV.ULongVal);
347 default: assert(0 && "Unknown integral type!");
348 }
Chris Lattner9a231222003-05-14 17:51:49 +0000349 break;
Chris Lattnerd8c03bf2003-04-23 19:01:49 +0000350 }
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000351
Chris Lattner9a231222003-05-14 17:51:49 +0000352 case Instruction::Add:
Chris Lattner5f90cb82004-07-11 08:01:11 +0000353 switch (CE->getOperand(0)->getType()->getTypeID()) {
354 default: assert(0 && "Bad add type!"); abort();
355 case Type::LongTyID:
356 case Type::ULongTyID:
Chris Lattner6b2125c2003-05-14 17:53:49 +0000357 Result.LongVal = getConstantValue(CE->getOperand(0)).LongVal +
358 getConstantValue(CE->getOperand(1)).LongVal;
Chris Lattner9a231222003-05-14 17:51:49 +0000359 break;
Chris Lattner5f90cb82004-07-11 08:01:11 +0000360 case Type::IntTyID:
361 case Type::UIntTyID:
362 Result.IntVal = getConstantValue(CE->getOperand(0)).IntVal +
363 getConstantValue(CE->getOperand(1)).IntVal;
364 break;
365 case Type::ShortTyID:
366 case Type::UShortTyID:
367 Result.ShortVal = getConstantValue(CE->getOperand(0)).ShortVal +
368 getConstantValue(CE->getOperand(1)).ShortVal;
369 break;
370 case Type::SByteTyID:
371 case Type::UByteTyID:
372 Result.SByteVal = getConstantValue(CE->getOperand(0)).SByteVal +
373 getConstantValue(CE->getOperand(1)).SByteVal;
374 break;
375 case Type::FloatTyID:
376 Result.FloatVal = getConstantValue(CE->getOperand(0)).FloatVal +
377 getConstantValue(CE->getOperand(1)).FloatVal;
378 break;
379 case Type::DoubleTyID:
380 Result.DoubleVal = getConstantValue(CE->getOperand(0)).DoubleVal +
381 getConstantValue(CE->getOperand(1)).DoubleVal;
382 break;
383 }
Chris Lattner9a231222003-05-14 17:51:49 +0000384 return Result;
Chris Lattner9a231222003-05-14 17:51:49 +0000385 default:
386 break;
387 }
388 std::cerr << "ConstantExpr not handled as global var init: " << *CE << "\n";
389 abort();
390 }
Misha Brukmanedf128a2005-04-21 22:36:52 +0000391
Chris Lattnerf70c22b2004-06-17 18:19:28 +0000392 switch (C->getType()->getTypeID()) {
Chris Lattner813c8152005-01-08 20:13:19 +0000393#define GET_CONST_VAL(TY, CTY, CLASS) \
394 case Type::TY##TyID: Result.TY##Val = (CTY)cast<CLASS>(C)->getValue(); break
395 GET_CONST_VAL(Bool , bool , ConstantBool);
396 GET_CONST_VAL(UByte , unsigned char , ConstantUInt);
397 GET_CONST_VAL(SByte , signed char , ConstantSInt);
398 GET_CONST_VAL(UShort , unsigned short, ConstantUInt);
399 GET_CONST_VAL(Short , signed short , ConstantSInt);
400 GET_CONST_VAL(UInt , unsigned int , ConstantUInt);
401 GET_CONST_VAL(Int , signed int , ConstantSInt);
Chris Lattner4b3141d2005-05-12 06:01:28 +0000402 GET_CONST_VAL(ULong , uint64_t , ConstantUInt);
403 GET_CONST_VAL(Long , int64_t , ConstantSInt);
Chris Lattner813c8152005-01-08 20:13:19 +0000404 GET_CONST_VAL(Float , float , ConstantFP);
405 GET_CONST_VAL(Double , double , ConstantFP);
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000406#undef GET_CONST_VAL
407 case Type::PointerTyID:
Reid Spencer40cf2f92004-07-18 00:41:27 +0000408 if (isa<ConstantPointerNull>(C))
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000409 Result.PointerVal = 0;
Reid Spencer40cf2f92004-07-18 00:41:27 +0000410 else if (const Function *F = dyn_cast<Function>(C))
411 Result = PTOGV(getPointerToFunctionOrStub(const_cast<Function*>(F)));
412 else if (const GlobalVariable* GV = dyn_cast<GlobalVariable>(C))
413 Result = PTOGV(getOrEmitGlobalVariable(const_cast<GlobalVariable*>(GV)));
414 else
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000415 assert(0 && "Unknown constant pointer type!");
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000416 break;
417 default:
Chris Lattner0a8e8e12004-07-15 02:51:31 +0000418 std::cout << "ERROR: Constant unimp for type: " << *C->getType() << "\n";
Chris Lattnerd8c03bf2003-04-23 19:01:49 +0000419 abort();
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000420 }
421 return Result;
422}
423
Nate Begeman37efe672006-04-22 18:53:45 +0000424/// StoreValueToMemory - Stores the data in Val of type Ty at address Ptr. Ptr
425/// is the address of the memory at which to store Val, cast to GenericValue *.
426/// It is not a pointer to a GenericValue containing the address at which to
427/// store Val.
Misha Brukman4afac182003-10-10 17:45:12 +0000428///
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000429void ExecutionEngine::StoreValueToMemory(GenericValue Val, GenericValue *Ptr,
Misha Brukman4afac182003-10-10 17:45:12 +0000430 const Type *Ty) {
Owen Andersona69571c2006-05-03 01:29:57 +0000431 if (getTargetData()->isLittleEndian()) {
Chris Lattnerf70c22b2004-06-17 18:19:28 +0000432 switch (Ty->getTypeID()) {
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000433 case Type::BoolTyID:
434 case Type::UByteTyID:
435 case Type::SByteTyID: Ptr->Untyped[0] = Val.UByteVal; break;
436 case Type::UShortTyID:
437 case Type::ShortTyID: Ptr->Untyped[0] = Val.UShortVal & 255;
438 Ptr->Untyped[1] = (Val.UShortVal >> 8) & 255;
439 break;
Chris Lattner2be50792003-04-23 20:41:01 +0000440 Store4BytesLittleEndian:
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000441 case Type::FloatTyID:
442 case Type::UIntTyID:
443 case Type::IntTyID: Ptr->Untyped[0] = Val.UIntVal & 255;
444 Ptr->Untyped[1] = (Val.UIntVal >> 8) & 255;
445 Ptr->Untyped[2] = (Val.UIntVal >> 16) & 255;
446 Ptr->Untyped[3] = (Val.UIntVal >> 24) & 255;
447 break;
Owen Andersona69571c2006-05-03 01:29:57 +0000448 case Type::PointerTyID: if (getTargetData()->getPointerSize() == 4)
Chris Lattner2be50792003-04-23 20:41:01 +0000449 goto Store4BytesLittleEndian;
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000450 case Type::DoubleTyID:
451 case Type::ULongTyID:
Chris Lattner813c8152005-01-08 20:13:19 +0000452 case Type::LongTyID:
453 Ptr->Untyped[0] = (unsigned char)(Val.ULongVal );
454 Ptr->Untyped[1] = (unsigned char)(Val.ULongVal >> 8);
455 Ptr->Untyped[2] = (unsigned char)(Val.ULongVal >> 16);
456 Ptr->Untyped[3] = (unsigned char)(Val.ULongVal >> 24);
457 Ptr->Untyped[4] = (unsigned char)(Val.ULongVal >> 32);
458 Ptr->Untyped[5] = (unsigned char)(Val.ULongVal >> 40);
459 Ptr->Untyped[6] = (unsigned char)(Val.ULongVal >> 48);
460 Ptr->Untyped[7] = (unsigned char)(Val.ULongVal >> 56);
461 break;
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000462 default:
Chris Lattner0a8e8e12004-07-15 02:51:31 +0000463 std::cout << "Cannot store value of type " << *Ty << "!\n";
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000464 }
465 } else {
Chris Lattnerf70c22b2004-06-17 18:19:28 +0000466 switch (Ty->getTypeID()) {
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000467 case Type::BoolTyID:
468 case Type::UByteTyID:
469 case Type::SByteTyID: Ptr->Untyped[0] = Val.UByteVal; break;
470 case Type::UShortTyID:
471 case Type::ShortTyID: Ptr->Untyped[1] = Val.UShortVal & 255;
472 Ptr->Untyped[0] = (Val.UShortVal >> 8) & 255;
473 break;
Chris Lattner2be50792003-04-23 20:41:01 +0000474 Store4BytesBigEndian:
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000475 case Type::FloatTyID:
476 case Type::UIntTyID:
477 case Type::IntTyID: Ptr->Untyped[3] = Val.UIntVal & 255;
478 Ptr->Untyped[2] = (Val.UIntVal >> 8) & 255;
479 Ptr->Untyped[1] = (Val.UIntVal >> 16) & 255;
480 Ptr->Untyped[0] = (Val.UIntVal >> 24) & 255;
481 break;
Owen Andersona69571c2006-05-03 01:29:57 +0000482 case Type::PointerTyID: if (getTargetData()->getPointerSize() == 4)
Chris Lattner2be50792003-04-23 20:41:01 +0000483 goto Store4BytesBigEndian;
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000484 case Type::DoubleTyID:
485 case Type::ULongTyID:
Chris Lattner813c8152005-01-08 20:13:19 +0000486 case Type::LongTyID:
Misha Brukmanedf128a2005-04-21 22:36:52 +0000487 Ptr->Untyped[7] = (unsigned char)(Val.ULongVal );
Chris Lattner813c8152005-01-08 20:13:19 +0000488 Ptr->Untyped[6] = (unsigned char)(Val.ULongVal >> 8);
489 Ptr->Untyped[5] = (unsigned char)(Val.ULongVal >> 16);
490 Ptr->Untyped[4] = (unsigned char)(Val.ULongVal >> 24);
491 Ptr->Untyped[3] = (unsigned char)(Val.ULongVal >> 32);
492 Ptr->Untyped[2] = (unsigned char)(Val.ULongVal >> 40);
493 Ptr->Untyped[1] = (unsigned char)(Val.ULongVal >> 48);
494 Ptr->Untyped[0] = (unsigned char)(Val.ULongVal >> 56);
495 break;
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000496 default:
Chris Lattner0a8e8e12004-07-15 02:51:31 +0000497 std::cout << "Cannot store value of type " << *Ty << "!\n";
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000498 }
499 }
500}
501
Misha Brukman4afac182003-10-10 17:45:12 +0000502/// FIXME: document
503///
Chris Lattnerf88b9a62003-05-08 16:52:16 +0000504GenericValue ExecutionEngine::LoadValueFromMemory(GenericValue *Ptr,
505 const Type *Ty) {
506 GenericValue Result;
Owen Andersona69571c2006-05-03 01:29:57 +0000507 if (getTargetData()->isLittleEndian()) {
Chris Lattnerf70c22b2004-06-17 18:19:28 +0000508 switch (Ty->getTypeID()) {
Chris Lattnerf88b9a62003-05-08 16:52:16 +0000509 case Type::BoolTyID:
510 case Type::UByteTyID:
511 case Type::SByteTyID: Result.UByteVal = Ptr->Untyped[0]; break;
512 case Type::UShortTyID:
513 case Type::ShortTyID: Result.UShortVal = (unsigned)Ptr->Untyped[0] |
514 ((unsigned)Ptr->Untyped[1] << 8);
515 break;
Misha Brukmanedf128a2005-04-21 22:36:52 +0000516 Load4BytesLittleEndian:
Chris Lattnerf88b9a62003-05-08 16:52:16 +0000517 case Type::FloatTyID:
518 case Type::UIntTyID:
519 case Type::IntTyID: Result.UIntVal = (unsigned)Ptr->Untyped[0] |
520 ((unsigned)Ptr->Untyped[1] << 8) |
521 ((unsigned)Ptr->Untyped[2] << 16) |
522 ((unsigned)Ptr->Untyped[3] << 24);
523 break;
Owen Andersona69571c2006-05-03 01:29:57 +0000524 case Type::PointerTyID: if (getTargetData()->getPointerSize() == 4)
Chris Lattnerf88b9a62003-05-08 16:52:16 +0000525 goto Load4BytesLittleEndian;
526 case Type::DoubleTyID:
527 case Type::ULongTyID:
528 case Type::LongTyID: Result.ULongVal = (uint64_t)Ptr->Untyped[0] |
529 ((uint64_t)Ptr->Untyped[1] << 8) |
530 ((uint64_t)Ptr->Untyped[2] << 16) |
531 ((uint64_t)Ptr->Untyped[3] << 24) |
532 ((uint64_t)Ptr->Untyped[4] << 32) |
533 ((uint64_t)Ptr->Untyped[5] << 40) |
534 ((uint64_t)Ptr->Untyped[6] << 48) |
535 ((uint64_t)Ptr->Untyped[7] << 56);
536 break;
537 default:
538 std::cout << "Cannot load value of type " << *Ty << "!\n";
539 abort();
540 }
541 } else {
Chris Lattnerf70c22b2004-06-17 18:19:28 +0000542 switch (Ty->getTypeID()) {
Chris Lattnerf88b9a62003-05-08 16:52:16 +0000543 case Type::BoolTyID:
544 case Type::UByteTyID:
545 case Type::SByteTyID: Result.UByteVal = Ptr->Untyped[0]; break;
546 case Type::UShortTyID:
547 case Type::ShortTyID: Result.UShortVal = (unsigned)Ptr->Untyped[1] |
548 ((unsigned)Ptr->Untyped[0] << 8);
549 break;
550 Load4BytesBigEndian:
551 case Type::FloatTyID:
552 case Type::UIntTyID:
553 case Type::IntTyID: Result.UIntVal = (unsigned)Ptr->Untyped[3] |
554 ((unsigned)Ptr->Untyped[2] << 8) |
555 ((unsigned)Ptr->Untyped[1] << 16) |
556 ((unsigned)Ptr->Untyped[0] << 24);
557 break;
Owen Andersona69571c2006-05-03 01:29:57 +0000558 case Type::PointerTyID: if (getTargetData()->getPointerSize() == 4)
Chris Lattnerf88b9a62003-05-08 16:52:16 +0000559 goto Load4BytesBigEndian;
560 case Type::DoubleTyID:
561 case Type::ULongTyID:
562 case Type::LongTyID: Result.ULongVal = (uint64_t)Ptr->Untyped[7] |
563 ((uint64_t)Ptr->Untyped[6] << 8) |
564 ((uint64_t)Ptr->Untyped[5] << 16) |
565 ((uint64_t)Ptr->Untyped[4] << 24) |
566 ((uint64_t)Ptr->Untyped[3] << 32) |
567 ((uint64_t)Ptr->Untyped[2] << 40) |
568 ((uint64_t)Ptr->Untyped[1] << 48) |
569 ((uint64_t)Ptr->Untyped[0] << 56);
570 break;
571 default:
572 std::cout << "Cannot load value of type " << *Ty << "!\n";
573 abort();
574 }
575 }
576 return Result;
577}
578
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000579// InitializeMemory - Recursive function to apply a Constant value into the
580// specified memory location...
581//
582void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) {
Chris Lattnerbd1d3822004-10-16 18:19:26 +0000583 if (isa<UndefValue>(Init)) {
584 return;
Robert Bocchino7c2b7c72006-01-20 18:18:40 +0000585 } else if (const ConstantPacked *CP = dyn_cast<ConstantPacked>(Init)) {
586 unsigned ElementSize =
Owen Andersona69571c2006-05-03 01:29:57 +0000587 getTargetData()->getTypeSize(CP->getType()->getElementType());
Robert Bocchino7c2b7c72006-01-20 18:18:40 +0000588 for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
589 InitializeMemory(CP->getOperand(i), (char*)Addr+i*ElementSize);
590 return;
Chris Lattnerbd1d3822004-10-16 18:19:26 +0000591 } else if (Init->getType()->isFirstClassType()) {
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000592 GenericValue Val = getConstantValue(Init);
593 StoreValueToMemory(Val, (GenericValue*)Addr, Init->getType());
594 return;
Chris Lattnerdd2c82a2004-02-15 05:54:06 +0000595 } else if (isa<ConstantAggregateZero>(Init)) {
Owen Andersona69571c2006-05-03 01:29:57 +0000596 memset(Addr, 0, (size_t)getTargetData()->getTypeSize(Init->getType()));
Chris Lattnerdd2c82a2004-02-15 05:54:06 +0000597 return;
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000598 }
599
Chris Lattnerf70c22b2004-06-17 18:19:28 +0000600 switch (Init->getType()->getTypeID()) {
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000601 case Type::ArrayTyID: {
602 const ConstantArray *CPA = cast<ConstantArray>(Init);
Misha Brukmanedf128a2005-04-21 22:36:52 +0000603 unsigned ElementSize =
Owen Andersona69571c2006-05-03 01:29:57 +0000604 getTargetData()->getTypeSize(CPA->getType()->getElementType());
Alkis Evlogimenos15876bb2004-08-04 08:44:43 +0000605 for (unsigned i = 0, e = CPA->getNumOperands(); i != e; ++i)
606 InitializeMemory(CPA->getOperand(i), (char*)Addr+i*ElementSize);
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000607 return;
608 }
609
610 case Type::StructTyID: {
611 const ConstantStruct *CPS = cast<ConstantStruct>(Init);
612 const StructLayout *SL =
Owen Andersona69571c2006-05-03 01:29:57 +0000613 getTargetData()->getStructLayout(cast<StructType>(CPS->getType()));
Alkis Evlogimenos15876bb2004-08-04 08:44:43 +0000614 for (unsigned i = 0, e = CPS->getNumOperands(); i != e; ++i)
615 InitializeMemory(CPS->getOperand(i), (char*)Addr+SL->MemberOffsets[i]);
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000616 return;
617 }
618
619 default:
Chris Lattner0a8e8e12004-07-15 02:51:31 +0000620 std::cerr << "Bad Type: " << *Init->getType() << "\n";
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000621 assert(0 && "Unknown constant type to initialize memory with!");
622 }
623}
624
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000625/// EmitGlobals - Emit all of the global variables to memory, storing their
626/// addresses into GlobalAddress. This must make sure to copy the contents of
627/// their initializers into the memory.
628///
629void ExecutionEngine::emitGlobals() {
Owen Andersona69571c2006-05-03 01:29:57 +0000630 const TargetData *TD = getTargetData();
Misha Brukmanedf128a2005-04-21 22:36:52 +0000631
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000632 // Loop over all of the global variables in the program, allocating the memory
Chris Lattnerfe854032006-08-16 01:24:12 +0000633 // to hold them. If there is more than one module, do a prepass over globals
634 // to figure out how the different modules should link together.
635 //
636 std::map<std::pair<std::string, const Type*>,
637 const GlobalValue*> LinkedGlobalsMap;
Misha Brukmanedf128a2005-04-21 22:36:52 +0000638
Chris Lattnerfe854032006-08-16 01:24:12 +0000639 if (Modules.size() != 1) {
640 for (unsigned m = 0, e = Modules.size(); m != e; ++m) {
641 Module &M = *Modules[m]->getModule();
642 for (Module::const_global_iterator I = M.global_begin(),
643 E = M.global_end(); I != E; ++I) {
644 const GlobalValue *GV = I;
645 if (GV->hasInternalLinkage() || GV->isExternal() ||
646 GV->hasAppendingLinkage() || !GV->hasName())
647 continue;// Ignore external globals and globals with internal linkage.
648
649 const GlobalValue *&GVEntry =
650 LinkedGlobalsMap[std::make_pair(GV->getName(), GV->getType())];
651
652 // If this is the first time we've seen this global, it is the canonical
653 // version.
654 if (!GVEntry) {
655 GVEntry = GV;
656 continue;
657 }
658
659 // If the existing global is strong, never replace it.
660 if (GVEntry->hasExternalLinkage())
661 continue;
662
663 // Otherwise, we know it's linkonce/weak, replace it if this is a strong
664 // symbol.
665 if (GV->hasExternalLinkage())
666 GVEntry = GV;
Chris Lattnerd8c03bf2003-04-23 19:01:49 +0000667 }
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000668 }
Chris Lattnerfe854032006-08-16 01:24:12 +0000669 }
670
671 std::vector<const GlobalValue*> NonCanonicalGlobals;
672 for (unsigned m = 0, e = Modules.size(); m != e; ++m) {
673 Module &M = *Modules[m]->getModule();
674 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
675 I != E; ++I) {
676 // In the multi-module case, see what this global maps to.
677 if (!LinkedGlobalsMap.empty()) {
678 if (const GlobalValue *GVEntry =
679 LinkedGlobalsMap[std::make_pair(I->getName(), I->getType())]) {
680 // If something else is the canonical global, ignore this one.
681 if (GVEntry != &*I) {
682 NonCanonicalGlobals.push_back(I);
683 continue;
684 }
685 }
686 }
687
688 if (!I->isExternal()) {
689 // Get the type of the global.
690 const Type *Ty = I->getType()->getElementType();
Misha Brukmanedf128a2005-04-21 22:36:52 +0000691
Chris Lattnerfe854032006-08-16 01:24:12 +0000692 // Allocate some memory for it!
693 unsigned Size = TD->getTypeSize(Ty);
694 addGlobalMapping(I, new char[Size]);
695 } else {
696 // External variable reference. Try to use the dynamic loader to
697 // get a pointer to it.
698 if (void *SymAddr =
699 sys::DynamicLibrary::SearchForAddressOfSymbol(I->getName().c_str()))
700 addGlobalMapping(I, SymAddr);
701 else {
702 std::cerr << "Could not resolve external global address: "
703 << I->getName() << "\n";
704 abort();
705 }
706 }
707 }
708
709 // If there are multiple modules, map the non-canonical globals to their
710 // canonical location.
711 if (!NonCanonicalGlobals.empty()) {
712 for (unsigned i = 0, e = NonCanonicalGlobals.size(); i != e; ++i) {
713 const GlobalValue *GV = NonCanonicalGlobals[i];
714 const GlobalValue *CGV =
715 LinkedGlobalsMap[std::make_pair(GV->getName(), GV->getType())];
716 void *Ptr = getPointerToGlobalIfAvailable(CGV);
717 assert(Ptr && "Canonical global wasn't codegen'd!");
718 addGlobalMapping(GV, getPointerToGlobalIfAvailable(CGV));
719 }
720 }
721
722 // Now that all of the globals are set up in memory, loop through them all and
723 // initialize their contents.
724 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
725 I != E; ++I) {
726 if (!I->isExternal()) {
727 if (!LinkedGlobalsMap.empty()) {
728 if (const GlobalValue *GVEntry =
729 LinkedGlobalsMap[std::make_pair(I->getName(), I->getType())])
730 if (GVEntry != &*I) // Not the canonical variable.
731 continue;
732 }
733 EmitGlobalVariable(I);
734 }
735 }
736 }
Chris Lattner24b0a182003-12-20 02:45:37 +0000737}
738
739// EmitGlobalVariable - This method emits the specified global variable to the
740// address specified in GlobalAddresses, or allocates new memory if it's not
741// already in the map.
Chris Lattnerc07ed132003-12-20 03:36:47 +0000742void ExecutionEngine::EmitGlobalVariable(const GlobalVariable *GV) {
Chris Lattner55d86482003-12-31 20:21:04 +0000743 void *GA = getPointerToGlobalIfAvailable(GV);
Chris Lattner23c47242004-02-08 19:33:23 +0000744 DEBUG(std::cerr << "Global '" << GV->getName() << "' -> " << GA << "\n");
745
Chris Lattnerc07ed132003-12-20 03:36:47 +0000746 const Type *ElTy = GV->getType()->getElementType();
Owen Andersona69571c2006-05-03 01:29:57 +0000747 size_t GVSize = (size_t)getTargetData()->getTypeSize(ElTy);
Chris Lattner24b0a182003-12-20 02:45:37 +0000748 if (GA == 0) {
749 // If it's not already specified, allocate memory for the global.
Chris Lattnera98c5452004-11-19 08:44:07 +0000750 GA = new char[GVSize];
Chris Lattner55d86482003-12-31 20:21:04 +0000751 addGlobalMapping(GV, GA);
Chris Lattner24b0a182003-12-20 02:45:37 +0000752 }
Chris Lattnerc07ed132003-12-20 03:36:47 +0000753
Chris Lattner24b0a182003-12-20 02:45:37 +0000754 InitializeMemory(GV->getInitializer(), GA);
Chris Lattner813c8152005-01-08 20:13:19 +0000755 NumInitBytes += (unsigned)GVSize;
Chris Lattner24b0a182003-12-20 02:45:37 +0000756 ++NumGlobals;
Chris Lattnerbd199fb2002-12-24 00:01:05 +0000757}