From 269a42811bf20f17a69600905cc5c03f68773043 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 26 Dec 2003 06:49:53 +0000 Subject: [PATCH] Factor out code to ExecutionEngine git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10614 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lli/lli.cpp | 60 ++++++++--------------------------------------- 1 file changed, 10 insertions(+), 50 deletions(-) diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp index c212abd2342..518c1a1d6ec 100644 --- a/tools/lli/lli.cpp +++ b/tools/lli/lli.cpp @@ -13,17 +13,13 @@ // //===----------------------------------------------------------------------===// -#include "llvm/DerivedTypes.h" #include "llvm/Module.h" #include "llvm/ModuleProvider.h" +#include "llvm/Type.h" #include "llvm/Bytecode/Reader.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/GenericValue.h" -#include "llvm/Target/TargetMachineImpls.h" -#include "llvm/Target/TargetData.h" #include "Support/CommandLine.h" -#include "Support/Debug.h" -#include "Support/SystemUtils.h" using namespace llvm; @@ -44,34 +40,6 @@ namespace { " program"), cl::value_desc("executable")); } -static void *CreateArgv(ExecutionEngine *EE, - const std::vector &InputArgv) { - unsigned PtrSize = EE->getTargetData().getPointerSize(); - char *Result = new char[(InputArgv.size()+1)*PtrSize]; - - DEBUG(std::cerr << "ARGV = " << (void*)Result << "\n"); - const Type *SBytePtr = PointerType::get(Type::SByteTy); - - 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"); - - std::copy(InputArgv[i].begin(), InputArgv[i].end(), Dest); - Dest[Size-1] = 0; - - // Endian safe: Result[i] = (PointerTy)Dest; - EE->StoreValueToMemory(PTOGV(Dest), (GenericValue*)(Result+i*PtrSize), - SBytePtr); - } - - // Null terminate it - EE->StoreValueToMemory(PTOGV(0), - (GenericValue*)(Result+InputArgv.size()*PtrSize), - SBytePtr); - return Result; -} - //===----------------------------------------------------------------------===// // main Driver function // @@ -118,28 +86,20 @@ int main(int argc, char **argv, char * const *envp) { return -1; } - std::vector GVArgs; - GenericValue GVArgc; - GVArgc.IntVal = InputArgv.size(); - GVArgs.push_back(GVArgc); // Arg #0 = argc. - GVArgs.push_back(PTOGV(CreateArgv(EE, InputArgv))); // Arg #1 = argv. - assert(((char **)GVTOP(GVArgs[1]))[0] && "argv[0] was null after CreateArgv"); - - std::vector EnvVars; - for (unsigned i = 0; envp[i]; ++i) - EnvVars.push_back(envp[i]); - GVArgs.push_back(PTOGV(CreateArgv(EE, EnvVars))); // Arg #2 = envp. - GenericValue Result = EE->runFunction(Fn, GVArgs); + // Run main... + int Result = EE->runFunctionAsMain(Fn, InputArgv, envp); // If the program didn't explicitly call exit, call exit now, for the program. // This ensures that any atexit handlers get called correctly. Function *Exit = MP->getModule()->getOrInsertFunction("exit", Type::VoidTy, Type::IntTy, 0); - - GVArgs.clear(); - GVArgs.push_back(Result); - EE->runFunction(Exit, GVArgs); - std::cerr << "ERROR: exit(" << Result.IntVal << ") returned!\n"; + std::vector Args; + GenericValue ResultGV; + ResultGV.IntVal = Result; + Args.push_back(ResultGV); + EE->runFunction(Exit, Args); + + std::cerr << "ERROR: exit(" << Result << ") returned!\n"; abort(); } -- 2.34.1