[llvm-commits] CVS: llvm/tools/lli/Interpreter/Execution.cpp ExternalFunctions.cpp Interpreter.cpp Interpreter.h UserInput.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed May 14 09:22:01 PDT 2003


Changes in directory llvm/tools/lli/Interpreter:

Execution.cpp updated: 1.89 -> 1.90
ExternalFunctions.cpp updated: 1.51 -> 1.52
Interpreter.cpp updated: 1.5 -> 1.6
Interpreter.h updated: 1.29 -> 1.30
UserInput.cpp updated: 1.25 -> 1.26

---
Log message:

Add support for atexit function, remove support for __main function


---
Diffs of the changes:

Index: llvm/tools/lli/Interpreter/Execution.cpp
diff -u llvm/tools/lli/Interpreter/Execution.cpp:1.89 llvm/tools/lli/Interpreter/Execution.cpp:1.90
--- llvm/tools/lli/Interpreter/Execution.cpp:1.89	Sat May 10 16:22:39 2003
+++ llvm/tools/lli/Interpreter/Execution.cpp	Wed May 14 09:21:30 2003
@@ -520,7 +520,9 @@
 //                     Terminator Instruction Implementations
 //===----------------------------------------------------------------------===//
 
-static void PerformExitStuff() {
+// PerformExitStuff - Print out counters and profiling information if
+// applicable...
+void Interpreter::PerformExitStuff() {
 #ifdef PROFILE_STRUCTURE_FIELDS
   // Print out structure field accounting information...
   if (!FieldAccessCounts.empty()) {
@@ -575,7 +577,6 @@
 
   ExitCode = GV.SByteVal;
   ECStack.clear();
-  PerformExitStuff();
 }
 
 void Interpreter::visitReturnInst(ReturnInst &I) {
@@ -609,8 +610,6 @@
     } else {
       ExitCode = 0;
     }
-
-    PerformExitStuff();
     return;
   }
 


Index: llvm/tools/lli/Interpreter/ExternalFunctions.cpp
diff -u llvm/tools/lli/Interpreter/ExternalFunctions.cpp:1.51 llvm/tools/lli/Interpreter/ExternalFunctions.cpp:1.52
--- llvm/tools/lli/Interpreter/ExternalFunctions.cpp:1.51	Thu May  8 11:52:43 2003
+++ llvm/tools/lli/Interpreter/ExternalFunctions.cpp	Wed May 14 09:21:30 2003
@@ -91,7 +91,7 @@
 }
 
 GenericValue Interpreter::callExternalFunction(Function *M,
-                                         const vector<GenericValue> &ArgVals) {
+                                     const std::vector<GenericValue> &ArgVals) {
   TheInterpreter = this;
 
   // Do a lookup to see if the function is in our cache... this should just be a
@@ -134,9 +134,13 @@
   return Args[0];
 }
 
-// void __main()
-GenericValue lle_V___main(FunctionType *M, const vector<GenericValue> &Args) {
-  return GenericValue();
+// void atexit(Function*)
+GenericValue lle_X_atexit(FunctionType *M, const vector<GenericValue> &Args) {
+  assert(Args.size() == 1);
+  TheInterpreter->addAtExitHandler((Function*)GVTOP(Args[0]));
+  GenericValue GV;
+  GV.IntVal = 0;
+  return GV;
 }
 
 // void exit(int)
@@ -731,7 +735,6 @@
   FuncNames["lle_Vb_putchar"]     = lle_Vb_putchar;
   FuncNames["lle_ii_putchar"]     = lle_ii_putchar;
   FuncNames["lle_VB_putchar"]     = lle_VB_putchar;
-  FuncNames["lle_V___main"]       = lle_V___main;
   FuncNames["lle_X_exit"]         = lle_X_exit;
   FuncNames["lle_X_abort"]        = lle_X_abort;
   FuncNames["lle_X_malloc"]       = lle_X_malloc;


Index: llvm/tools/lli/Interpreter/Interpreter.cpp
diff -u llvm/tools/lli/Interpreter/Interpreter.cpp:1.5 llvm/tools/lli/Interpreter/Interpreter.cpp:1.6
--- llvm/tools/lli/Interpreter/Interpreter.cpp:1.5	Sun May 11 21:14:30 2003
+++ llvm/tools/lli/Interpreter/Interpreter.cpp	Wed May 14 09:21:30 2003
@@ -48,10 +48,21 @@
     run();
   }
 
-  // If debug mode, allow the user to interact... also, if the user pressed 
-  // ctrl-c or execution hit an error, enter the event loop...
-  if (Debug || isStopped())
-    handleUserInput();
+  do {
+    // If debug mode, allow the user to interact... also, if the user pressed 
+    // ctrl-c or execution hit an error, enter the event loop...
+    if (Debug || isStopped())
+      handleUserInput();
+
+    // If the program has exited, run atexit handlers...
+    if (ECStack.empty() && !AtExitHandlers.empty()) {
+      callFunction(AtExitHandlers.back(), std::vector<GenericValue>());
+      AtExitHandlers.pop_back();
+      run();
+    }
+  } while (!ECStack.empty());
+
+  PerformExitStuff();
   return ExitCode;
 }
 


Index: llvm/tools/lli/Interpreter/Interpreter.h
diff -u llvm/tools/lli/Interpreter/Interpreter.h:1.29 llvm/tools/lli/Interpreter/Interpreter.h:1.30
--- llvm/tools/lli/Interpreter/Interpreter.h:1.29	Sat May 10 16:22:39 2003
+++ llvm/tools/lli/Interpreter/Interpreter.h	Wed May 14 09:21:30 2003
@@ -84,6 +84,8 @@
   // function record.
   std::vector<ExecutionContext> ECStack;
 
+  // AtExitHandlers - List of functions to call when the program exits.
+  std::vector<Function*> AtExitHandlers;
 public:
   Interpreter(Module *M, unsigned Config, bool DebugMode, bool TraceMode);
   inline ~Interpreter() { CW.setModule(0); }
@@ -164,6 +166,10 @@
   //
   inline bool isStopped() const { return !ECStack.empty(); }
 
+  void addAtExitHandler(Function *F) {
+    AtExitHandlers.push_back(F);
+  }
+
   //FIXME: private:
 public:
   GenericValue executeGEPOperation(Value *Ptr, User::op_iterator I,
@@ -207,6 +213,9 @@
   Value *ChooseOneOption(const std::string &Name,
                          const std::vector<Value*> &Opts);
 
+  // PerformExitStuff - Print out counters and profiling information if
+  // applicable...
+  void PerformExitStuff();
 
   void initializeExecutionEngine();
   void initializeExternalFunctions();


Index: llvm/tools/lli/Interpreter/UserInput.cpp
diff -u llvm/tools/lli/Interpreter/UserInput.cpp:1.25 llvm/tools/lli/Interpreter/UserInput.cpp:1.26
--- llvm/tools/lli/Interpreter/UserInput.cpp:1.25	Thu May  8 11:18:31 2003
+++ llvm/tools/lli/Interpreter/UserInput.cpp	Wed May 14 09:21:30 2003
@@ -115,7 +115,7 @@
     case Call:
       std::cin >> Command;
       callFunction(Command);    // Enter the specified function
-      finish();               // Run until it's complete
+      finish();                 // Run until it's complete
       break;
 
     case TraceOpt:
@@ -129,6 +129,7 @@
     }
 
   } while (!UserQuit);
+  AtExitHandlers.clear();
 }
 
 //===----------------------------------------------------------------------===//





More information about the llvm-commits mailing list