From b2abb5a586b50b0ac53618c181241d4c2e45b5f4 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 7 May 2003 20:31:37 +0000 Subject: [PATCH] Fix bug: Jello/2003-05-07-ArgumentTest.llx Also fixes yacr2/ks benchmarks git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6017 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ExecutionEngine/ExecutionEngine.cpp | 50 ++++++++++++++++--------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index a6f71266d78..dcfbde4985a 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -193,26 +193,42 @@ void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) { void *ExecutionEngine::CreateArgv(const std::vector &InputArgv) { - // Pointers are 64 bits... - // FIXME: Assumes 64 bit target - PointerTy *Result = new PointerTy[InputArgv.size()+1]; - DEBUG(std::cerr << "ARGV = " << (void*)Result << "\n"); - - for (unsigned i = 0; i < InputArgv.size(); ++i) { - unsigned Size = InputArgv[i].size()+1; - char *Dest = new char[Size]; - DEBUG(std::cerr << "ARGV[" << i << "] = " << (void*)Dest << "\n"); + if (getTargetData().getPointerSize() == 8) { // 64 bit target? + PointerTy *Result = new PointerTy[InputArgv.size()+1]; + DEBUG(std::cerr << "ARGV = " << (void*)Result << "\n"); + + for (unsigned i = 0; i < InputArgv.size(); ++i) { + unsigned Size = InputArgv[i].size()+1; + char *Dest = new char[Size]; + DEBUG(std::cerr << "ARGV[" << i << "] = " << (void*)Dest << "\n"); + + copy(InputArgv[i].begin(), InputArgv[i].end(), Dest); + Dest[Size-1] = 0; + + // Endian safe: Result[i] = (PointerTy)Dest; + StoreValueToMemory(PTOGV(Dest), (GenericValue*)(Result+i), Type::LongTy); + } + Result[InputArgv.size()] = 0; + return Result; - copy(InputArgv[i].begin(), InputArgv[i].end(), Dest); - Dest[Size-1] = 0; + } else { // 32 bit target? + int *Result = new int[InputArgv.size()+1]; + DEBUG(std::cerr << "ARGV = " << (void*)Result << "\n"); - // Endian safe: Result[i] = (PointerTy)Dest; - StoreValueToMemory(PTOGV(Dest), (GenericValue*)(Result+i), - Type::LongTy); // 64 bit assumption + for (unsigned i = 0; i < InputArgv.size(); ++i) { + unsigned Size = InputArgv[i].size()+1; + char *Dest = new char[Size]; + DEBUG(std::cerr << "ARGV[" << i << "] = " << (void*)Dest << "\n"); + + copy(InputArgv[i].begin(), InputArgv[i].end(), Dest); + Dest[Size-1] = 0; + + // Endian safe: Result[i] = (PointerTy)Dest; + StoreValueToMemory(PTOGV(Dest), (GenericValue*)(Result+i), Type::IntTy); + } + Result[InputArgv.size()] = 0; // null terminate it + return Result; } - - Result[InputArgv.size()] = 0; - return Result; } /// EmitGlobals - Emit all of the global variables to memory, storing their -- 2.40.0