summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ExecutionEngine/JIT
diff options
context:
space:
mode:
authorBrian Gaeke <gaeke@uiuc.edu>2003-09-05 18:42:01 +0000
committerBrian Gaeke <gaeke@uiuc.edu>2003-09-05 18:42:01 +0000
commita7669038fc8ab1447bc1f68108b30996adf50ef4 (patch)
treebb30cf4fc477b9d52f92be78b6b89e6c6b47e978 /llvm/lib/ExecutionEngine/JIT
parent15ad3f07db8df51636369c51d9aae83550fcd1bc (diff)
downloadbcm5719-llvm-a7669038fc8ab1447bc1f68108b30996adf50ef4.tar.gz
bcm5719-llvm-a7669038fc8ab1447bc1f68108b30996adf50ef4.zip
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". llvm-svn: 8366
Diffstat (limited to 'llvm/lib/ExecutionEngine/JIT')
-rw-r--r--llvm/lib/ExecutionEngine/JIT/Intercept.cpp25
-rw-r--r--llvm/lib/ExecutionEngine/JIT/JIT.cpp43
-rw-r--r--llvm/lib/ExecutionEngine/JIT/VM.h5
3 files changed, 32 insertions, 41 deletions
diff --git a/llvm/lib/ExecutionEngine/JIT/Intercept.cpp b/llvm/lib/ExecutionEngine/JIT/Intercept.cpp
index 10fd97015f2..09cbe28740a 100644
--- a/llvm/lib/ExecutionEngine/JIT/Intercept.cpp
+++ b/llvm/lib/ExecutionEngine/JIT/Intercept.cpp
@@ -12,33 +12,38 @@
#include "Config/dlfcn.h" // dlsym access
#include <iostream>
-// AtExitList - List of functions registered with the at_exit function
-static std::vector<void (*)()> AtExitList;
+// AtExitHandlers - List of functions to call when the program exits,
+// registered with the atexit() library function.
+static std::vector<void (*)()> AtExitHandlers;
+/// runAtExitHandlers - Run any functions registered by the program's
+/// calls to atexit(3), which we intercept and store in
+/// AtExitHandlers.
+///
void VM::runAtExitHandlers() {
- while (!AtExitList.empty()) {
- void (*Fn)() = AtExitList.back();
- AtExitList.pop_back();
+ while (!AtExitHandlers.empty()) {
+ void (*Fn)() = AtExitHandlers.back();
+ AtExitHandlers.pop_back();
Fn();
}
}
//===----------------------------------------------------------------------===//
-// Function stubs that are invoked instead of raw system calls
+// Function stubs that are invoked instead of certain library calls
//===----------------------------------------------------------------------===//
// NoopFn - Used if we have nothing else to call...
static void NoopFn() {}
-// jit_exit - Used to intercept the "exit" system call.
+// jit_exit - Used to intercept the "exit" library call.
static void jit_exit(int Status) {
- VM::runAtExitHandlers(); // Run at_exit handlers...
+ VM::runAtExitHandlers(); // Run atexit handlers...
exit(Status);
}
-// jit_atexit - Used to intercept the "at_exit" system call.
+// jit_atexit - Used to intercept the "atexit" library call.
static int jit_atexit(void (*Fn)(void)) {
- AtExitList.push_back(Fn); // Take note of at_exit handler...
+ AtExitHandlers.push_back(Fn); // Take note of atexit handler...
return 0; // Always successful
}
diff --git a/llvm/lib/ExecutionEngine/JIT/JIT.cpp b/llvm/lib/ExecutionEngine/JIT/JIT.cpp
index 9a2dc1aacb7..4c4c2221e32 100644
--- a/llvm/lib/ExecutionEngine/JIT/JIT.cpp
+++ b/llvm/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;
}
diff --git a/llvm/lib/ExecutionEngine/JIT/VM.h b/llvm/lib/ExecutionEngine/JIT/VM.h
index 764afcf66fe..9a7a645a4ee 100644
--- a/llvm/lib/ExecutionEngine/JIT/VM.h
+++ b/llvm/lib/ExecutionEngine/JIT/VM.h
@@ -33,9 +33,8 @@ public:
/// run - Start execution with the specified function and arguments.
///
- virtual int run(const std::string &FnName,
- const std::vector<std::string> &Args,
- const char ** envp);
+ virtual GenericValue run(Function *F,
+ const std::vector<GenericValue> &ArgValues);
/// getPointerToNamedFunction - This method returns the address of the
/// specified function by using the dlsym function call. As such it is only
OpenPOWER on IntegriCloud