aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lli
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-12-26 06:49:53 +0000
committerChris Lattner <sabre@nondot.org>2003-12-26 06:49:53 +0000
commit269a42811bf20f17a69600905cc5c03f68773043 (patch)
treeab7c32109dbb35405b0b418439c2a24c254b8b5c /tools/lli
parent3ef3dd36fe12103e643f3a5a2f9b3287fa1c2f40 (diff)
downloadexternal_llvm-269a42811bf20f17a69600905cc5c03f68773043.zip
external_llvm-269a42811bf20f17a69600905cc5c03f68773043.tar.gz
external_llvm-269a42811bf20f17a69600905cc5c03f68773043.tar.bz2
Factor out code to ExecutionEngine
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10614 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/lli')
-rw-r--r--tools/lli/lli.cpp60
1 files changed, 10 insertions, 50 deletions
diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp
index c212abd..518c1a1 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<std::string> &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<GenericValue> 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<std::string> 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<GenericValue> Args;
+ GenericValue ResultGV;
+ ResultGV.IntVal = Result;
+ Args.push_back(ResultGV);
+ EE->runFunction(Exit, Args);
+
+ std::cerr << "ERROR: exit(" << Result << ") returned!\n";
abort();
}