summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Criswell <criswell@uiuc.edu>2003-08-21 21:12:30 +0000
committerJohn Criswell <criswell@uiuc.edu>2003-08-21 21:12:30 +0000
commit71c3e6236febeda842adbf411e05463fb021159d (patch)
treeb2c989e01108583b8f4aab194fad1ae7c27b046e
parente08478eb59028f370b6c7a0da6ccce45c090e3eb (diff)
downloadbcm5719-llvm-71c3e6236febeda842adbf411e05463fb021159d.tar.gz
bcm5719-llvm-71c3e6236febeda842adbf411e05463fb021159d.zip
The JIT now passes the environment pointer to the main() function when it
starts a program. This allows the GNU env program to compile and JIT under LLVM. llvm-svn: 8022
-rw-r--r--llvm/include/llvm/ExecutionEngine/ExecutionEngine.h6
-rw-r--r--llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp3
-rw-r--r--llvm/lib/ExecutionEngine/Interpreter/Interpreter.h3
-rw-r--r--llvm/lib/ExecutionEngine/JIT/JIT.cpp30
-rw-r--r--llvm/lib/ExecutionEngine/JIT/VM.h3
-rw-r--r--llvm/tools/lli/lli.cpp4
6 files changed, 39 insertions, 10 deletions
diff --git a/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h b/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h
index 852e48eb88a..45f7a274d00 100644
--- a/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h
+++ b/llvm/include/llvm/ExecutionEngine/ExecutionEngine.h
@@ -41,10 +41,12 @@ public:
Module &getModule() const { return CurMod; }
const TargetData &getTargetData() const { return *TD; }
- /// run - Start execution with the specified function and arguments.
+ /// run - Start execution with the specified function, arguments, and
+ /// environment.
///
virtual int run(const std::string &FnName,
- const std::vector<std::string> &Args) = 0;
+ const std::vector<std::string> &Args,
+ const char ** envp) = 0;
/// createJIT - Create an return a new JIT compiler if there is one available
/// for the current target. Otherwise it returns null.
diff --git a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp
index 3453d831957..4fdd6a1be7f 100644
--- a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp
+++ b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.cpp
@@ -40,7 +40,8 @@ Interpreter::Interpreter(Module *M, unsigned Config,
/// run - Start execution with the specified function and arguments.
///
int Interpreter::run(const std::string &MainFunction,
- const std::vector<std::string> &Args) {
+ const std::vector<std::string> &Args,
+ const char ** envp) {
// Start interpreter into the main function...
//
if (!callMainFunction(MainFunction, Args) && !Debug) {
diff --git a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h
index 51675b5d671..d3963ef26c3 100644
--- a/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h
+++ b/llvm/lib/ExecutionEngine/Interpreter/Interpreter.h
@@ -97,7 +97,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 std::vector<std::string> &Args,
+ const char ** envp);
// enableProfiling() - Turn profiling on, clear stats?
diff --git a/llvm/lib/ExecutionEngine/JIT/JIT.cpp b/llvm/lib/ExecutionEngine/JIT/JIT.cpp
index 127c6579ca4..d4726f0d35b 100644
--- a/llvm/lib/ExecutionEngine/JIT/JIT.cpp
+++ b/llvm/lib/ExecutionEngine/JIT/JIT.cpp
@@ -11,6 +11,8 @@
#include "llvm/Module.h"
#include "Support/CommandLine.h"
+#include "Config/stdlib.h"
+
// FIXME: REMOVE THIS
#include "llvm/PassManager.h"
@@ -101,21 +103,43 @@ VM::VM(Module *M, TargetMachine *tm) : ExecutionEngine(M), TM(*tm) {
emitGlobals();
}
-int VM::run(const std::string &FnName, const std::vector<std::string> &Args) {
+//
+// Method: run()
+//
+// Description:
+// 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()).
+//
+// 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.
+//
+// Outputs:
+// None.
+//
+// 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;
}
- int(*PF)(int, char**) = (int(*)(int, char**))getPointerToFunction(F);
+ int(*PF)(int, char**, const char**) = (int(*)(int, char**, const char**))getPointerToFunction(F);
assert(PF != 0 && "Null pointer to function?");
// Build an argv vector...
char **Argv = (char**)CreateArgv(Args);
// Call the main function...
- int Result = PF(Args.size(), Argv);
+ int Result = PF(Args.size(), Argv, envp);
// Run any atexit handlers now!
runAtExitHandlers();
diff --git a/llvm/lib/ExecutionEngine/JIT/VM.h b/llvm/lib/ExecutionEngine/JIT/VM.h
index b4a1e0fa121..e886a194122 100644
--- a/llvm/lib/ExecutionEngine/JIT/VM.h
+++ b/llvm/lib/ExecutionEngine/JIT/VM.h
@@ -29,7 +29,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 std::vector<std::string> &Args,
+ const char ** envp);
/// getPointerToNamedFunction - This method returns the address of the
/// specified function by using the dlsym function call. As such it is only
diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp
index a69f53c98a7..7a0925deece 100644
--- a/llvm/tools/lli/lli.cpp
+++ b/llvm/tools/lli/lli.cpp
@@ -46,7 +46,7 @@ ExecutionEngine::~ExecutionEngine() {
//===----------------------------------------------------------------------===//
// main Driver function
//
-int main(int argc, char** argv) {
+int main(int argc, char** argv, const char ** envp) {
cl::ParseCommandLineOptions(argc, argv,
" llvm interpreter & dynamic compiler\n");
@@ -98,7 +98,7 @@ int main(int argc, char** argv) {
InputArgv.insert(InputArgv.begin(), InputFile);
// Run the main function!
- int ExitCode = EE->run(MainFunction, InputArgv);
+ int ExitCode = EE->run(MainFunction, InputArgv, envp);
// Now that we are done executing the program, shut down the execution engine
delete EE;
OpenPOWER on IntegriCloud