diff options
author | Brian Gaeke <gaeke@uiuc.edu> | 2003-09-05 18:42:01 +0000 |
---|---|---|
committer | Brian Gaeke <gaeke@uiuc.edu> | 2003-09-05 18:42:01 +0000 |
commit | 70975eef572b9e132bbaade16ba9edb76f15f287 (patch) | |
tree | edbaec8a92e10f18d1195cdb5d0fc1b59b4520d2 /lib/ExecutionEngine/JIT/JIT.cpp | |
parent | 5bea411ad288ea6f25ac296ae2d75a4bfab8bf98 (diff) |
Make CreateArgv part of lli rather than part of ExecutionEngine.
Switch Interpreter and JIT's "run" methods to take a Function and a vector of
GenericValues.
Move (almost all of) the stuff that constructs a canonical call to main()
into lli (new methods "callAsMain", "makeStringVector").
Nuke getCurrentExecutablePath(), enableTracing(), getCurrentFunction(),
isStopped(), and many dead decls from interpreter.
Add linux strdup() support to interpreter.
Make interpreter's atexit handler runner and JIT's runAtExitHandlers() look
more alike, in preparation for refactoring.
atexit() is spelled "atexit", not "at_exit".
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8366 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/JIT/JIT.cpp')
-rw-r--r-- | lib/ExecutionEngine/JIT/JIT.cpp | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp index 9a2dc1aacb..4c4c2221e3 100644 --- a/lib/ExecutionEngine/JIT/JIT.cpp +++ b/lib/ExecutionEngine/JIT/JIT.cpp @@ -6,6 +6,7 @@ //===----------------------------------------------------------------------===// #include "VM.h" +#include "../GenericValue.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachineImpls.h" #include "llvm/Module.h" @@ -100,38 +101,24 @@ VM::VM(Module *M, TargetMachine *tm) : ExecutionEngine(M), TM(*tm) { emitGlobals(); } -/// VM::run - This method begins the execution of a program beginning at the -/// specified function name. The function is called with the specified -/// arguments and array of environment variables (a la main()). +/// run - Start execution with the specified function and arguments. /// -/// Inputs: -/// FnName - The name of the function as a C++ string. -/// Args - A vector of C++ strings containing the arguments. -/// envp - An array of C strings containing the environment. -/// -/// Return value: -/// 1 - An error occurred. -/// Otherwise, the return value from the specified function is returned. -/// -int VM::run(const std::string &FnName, const std::vector<std::string> &Args, - const char **envp) { - Function *F = getModule().getNamedFunction(FnName); - if (F == 0) { - std::cerr << "Could not find function '" << FnName << "' in module!\n"; - return 1; - } +GenericValue VM::run(Function *F, const std::vector<GenericValue> &ArgValues) +{ + assert (F && "Function *F was null at entry to run()"); - int (*PF)(int, char**, const char**) = - (int(*)(int, char**, const char**))getPointerToFunction(F); - assert(PF != 0 && "Null pointer to function?"); + int (*PF)(int, char **, const char **) = + (int(*)(int, char **, const char **))getPointerToFunction(F); + assert(PF != 0 && "Pointer to fn's code was null after getPointerToFunction"); - // Build an argv vector... - char **Argv = (char**)CreateArgv(Args); - - // Call the main function... - int Result = PF(Args.size(), Argv, envp); + // Call the function. + int ExitCode = PF(ArgValues[0].IntVal, (char **) GVTOP (ArgValues[1]), + (const char **) GVTOP (ArgValues[2])); // Run any atexit handlers now! runAtExitHandlers(); - return Result; + + GenericValue rv; + rv.IntVal = ExitCode; + return rv; } |