aboutsummaryrefslogtreecommitdiff
path: root/lib/ExecutionEngine/JIT/JIT.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ExecutionEngine/JIT/JIT.cpp')
-rw-r--r--lib/ExecutionEngine/JIT/JIT.cpp43
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;
}