aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ExecutionEngine
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-05-14 14:21:30 +0000
committerChris Lattner <sabre@nondot.org>2003-05-14 14:21:30 +0000
commit44edb6bdd2edc48eb31ed160a09006b610cead67 (patch)
tree15e78604c92945363480b2b80937f38a9f934816 /lib/ExecutionEngine
parent22080f9f168b0129d0ed3a2a29a145e17723c3ba (diff)
downloadexternal_llvm-44edb6bdd2edc48eb31ed160a09006b610cead67.zip
external_llvm-44edb6bdd2edc48eb31ed160a09006b610cead67.tar.gz
external_llvm-44edb6bdd2edc48eb31ed160a09006b610cead67.tar.bz2
Add support for atexit function, remove support for __main function
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6194 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r--lib/ExecutionEngine/Interpreter/Execution.cpp7
-rw-r--r--lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp13
-rw-r--r--lib/ExecutionEngine/Interpreter/Interpreter.cpp19
-rw-r--r--lib/ExecutionEngine/Interpreter/Interpreter.h9
-rw-r--r--lib/ExecutionEngine/Interpreter/UserInput.cpp3
5 files changed, 37 insertions, 14 deletions
diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp
index f03514d..44c1e48 100644
--- a/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -520,7 +520,9 @@ void Interpreter::visitBinaryOperator(BinaryOperator &I) {
// 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 @@ void Interpreter::exitCalled(GenericValue GV) {
ExitCode = GV.SByteVal;
ECStack.clear();
- PerformExitStuff();
}
void Interpreter::visitReturnInst(ReturnInst &I) {
@@ -609,8 +610,6 @@ void Interpreter::visitReturnInst(ReturnInst &I) {
} else {
ExitCode = 0;
}
-
- PerformExitStuff();
return;
}
diff --git a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
index 88b994c..8eaae50 100644
--- a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
+++ b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
@@ -91,7 +91,7 @@ static ExFunc lookupFunction(const Function *M) {
}
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 @@ GenericValue lle_VB_putchar(FunctionType *M, const vector<GenericValue> &Args) {
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 @@ void Interpreter::initializeExternalFunctions() {
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;
diff --git a/lib/ExecutionEngine/Interpreter/Interpreter.cpp b/lib/ExecutionEngine/Interpreter/Interpreter.cpp
index 4582a6f..3453d83 100644
--- a/lib/ExecutionEngine/Interpreter/Interpreter.cpp
+++ b/lib/ExecutionEngine/Interpreter/Interpreter.cpp
@@ -48,10 +48,21 @@ int Interpreter::run(const std::string &MainFunction,
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;
}
diff --git a/lib/ExecutionEngine/Interpreter/Interpreter.h b/lib/ExecutionEngine/Interpreter/Interpreter.h
index 6481cb7..5076581 100644
--- a/lib/ExecutionEngine/Interpreter/Interpreter.h
+++ b/lib/ExecutionEngine/Interpreter/Interpreter.h
@@ -84,6 +84,8 @@ class Interpreter : public ExecutionEngine, public InstVisitor<Interpreter> {
// 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 @@ public:
//
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 @@ private: // Helper functions
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();
diff --git a/lib/ExecutionEngine/Interpreter/UserInput.cpp b/lib/ExecutionEngine/Interpreter/UserInput.cpp
index 0ed0f04..3f4493d 100644
--- a/lib/ExecutionEngine/Interpreter/UserInput.cpp
+++ b/lib/ExecutionEngine/Interpreter/UserInput.cpp
@@ -115,7 +115,7 @@ void Interpreter::handleUserInput() {
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 @@ void Interpreter::handleUserInput() {
}
} while (!UserQuit);
+ AtExitHandlers.clear();
}
//===----------------------------------------------------------------------===//