[llvm-commits] CVS: llvm/tools/lli/lli.cpp
Chris Lattner
lattner at cs.uiuc.edu
Fri Dec 26 00:51:07 PST 2003
Changes in directory llvm/tools/lli:
lli.cpp updated: 1.39 -> 1.40
---
Log message:
Factor out code to ExecutionEngine
---
Diffs of the changes: (+10 -50)
Index: llvm/tools/lli/lli.cpp
diff -u llvm/tools/lli/lli.cpp:1.39 llvm/tools/lli/lli.cpp:1.40
--- llvm/tools/lli/lli.cpp:1.39 Fri Dec 26 00:36:20 2003
+++ llvm/tools/lli/lli.cpp Fri Dec 26 00:49:53 2003
@@ -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 @@
" 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 @@
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();
}
More information about the llvm-commits
mailing list