The JIT now passes the environment pointer to the main() function when it
authorJohn Criswell <criswell@uiuc.edu>
Thu, 21 Aug 2003 21:12:30 +0000 (21:12 +0000)
committerJohn Criswell <criswell@uiuc.edu>
Thu, 21 Aug 2003 21:12:30 +0000 (21:12 +0000)
starts a program.  This allows the GNU env program to compile and JIT under
LLVM.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8022 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ExecutionEngine/ExecutionEngine.h
lib/ExecutionEngine/Interpreter/Interpreter.cpp
lib/ExecutionEngine/Interpreter/Interpreter.h
lib/ExecutionEngine/JIT/JIT.cpp
lib/ExecutionEngine/JIT/JIT.h
lib/ExecutionEngine/JIT/VM.h
tools/lli/lli.cpp

index 852e48eb88a35faee28bdd28698ddd87f4d58f43..45f7a274d00880afde743088f0b10f22e350f758 100644 (file)
@@ -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.
index 3453d831957b5bef88d541527c375c702b061b7b..4fdd6a1be7f4c3dc3422c16c74fa676364c67a15 100644 (file)
@@ -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) {
index 51675b5d67191a99aaa8cc728c7f92a0dde730cb..d3963ef26c318e058792df197b68ff1b708f562d 100644 (file)
@@ -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?
index 127c6579ca4ff3c1731c5d3cd2204f5a1850654c..d4726f0d35b5e442ed61178457cc5f8266ee9a36 100644 (file)
@@ -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();
index b4a1e0fa121e086af21c1c2dd2ec4821d39c5a95..e886a1941223ee5adfff88490d6f85b7c30895f5 100644 (file)
@@ -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
index b4a1e0fa121e086af21c1c2dd2ec4821d39c5a95..e886a1941223ee5adfff88490d6f85b7c30895f5 100644 (file)
@@ -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
index a69f53c98a720a15e1e028d6790dc3d49091f38f..7a0925deece388a8603aac89ca2e66f6f7908bde 100644 (file)
@@ -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;