mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-09-28 06:58:19 +00:00
No longer run atExit functions from run()
rename run to runFunction Genericize the runFunction code a little bit, though it still stinks git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10610 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
2cab55d7e1
commit
ff0f1bb32a
@ -28,7 +28,7 @@ static std::vector<void (*)()> AtExitHandlers;
|
|||||||
/// calls to atexit(3), which we intercept and store in
|
/// calls to atexit(3), which we intercept and store in
|
||||||
/// AtExitHandlers.
|
/// AtExitHandlers.
|
||||||
///
|
///
|
||||||
void JIT::runAtExitHandlers() {
|
static void runAtExitHandlers() {
|
||||||
while (!AtExitHandlers.empty()) {
|
while (!AtExitHandlers.empty()) {
|
||||||
void (*Fn)() = AtExitHandlers.back();
|
void (*Fn)() = AtExitHandlers.back();
|
||||||
AtExitHandlers.pop_back();
|
AtExitHandlers.pop_back();
|
||||||
@ -45,7 +45,7 @@ static void NoopFn() {}
|
|||||||
|
|
||||||
// jit_exit - Used to intercept the "exit" library call.
|
// jit_exit - Used to intercept the "exit" library call.
|
||||||
static void jit_exit(int Status) {
|
static void jit_exit(int Status) {
|
||||||
JIT::runAtExitHandlers(); // Run atexit handlers...
|
runAtExitHandlers(); // Run atexit handlers...
|
||||||
exit(Status);
|
exit(Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,22 +51,31 @@ JIT::~JIT() {
|
|||||||
|
|
||||||
/// run - Start execution with the specified function and arguments.
|
/// run - Start execution with the specified function and arguments.
|
||||||
///
|
///
|
||||||
GenericValue JIT::run(Function *F, const std::vector<GenericValue> &ArgValues) {
|
GenericValue JIT::runFunction(Function *F,
|
||||||
|
const std::vector<GenericValue> &ArgValues) {
|
||||||
assert (F && "Function *F was null at entry to run()");
|
assert (F && "Function *F was null at entry to run()");
|
||||||
|
GenericValue rv;
|
||||||
|
|
||||||
int (*PF)(int, char **, const char **) =
|
if (ArgValues.size() == 3) {
|
||||||
(int(*)(int, char **, const char **))getPointerToFunction(F);
|
int (*PF)(int, char **, const char **) =
|
||||||
assert(PF != 0 && "Pointer to fn's code was null after getPointerToFunction");
|
(int(*)(int, char **, const char **))getPointerToFunction(F);
|
||||||
|
assert(PF && "Pointer to fn's code was null after getPointerToFunction");
|
||||||
|
|
||||||
// Call the function.
|
// Call the function.
|
||||||
int ExitCode = PF(ArgValues[0].IntVal, (char **) GVTOP (ArgValues[1]),
|
int ExitCode = PF(ArgValues[0].IntVal, (char **) GVTOP (ArgValues[1]),
|
||||||
(const char **) GVTOP (ArgValues[2]));
|
(const char **) GVTOP (ArgValues[2]));
|
||||||
|
|
||||||
// Run any atexit handlers now!
|
rv.IntVal = ExitCode;
|
||||||
runAtExitHandlers();
|
} else {
|
||||||
|
// FIXME: This code should handle a couple of common cases efficiently, but
|
||||||
|
// it should also implement the general case by code-gening a new anonymous
|
||||||
|
// nullary function to call.
|
||||||
|
assert(ArgValues.size() == 1);
|
||||||
|
void (*PF)(int) = (void(*)(int))getPointerToFunction(F);
|
||||||
|
assert(PF && "Pointer to fn's code was null after getPointerToFunction");
|
||||||
|
PF(ArgValues[0].IntVal);
|
||||||
|
}
|
||||||
|
|
||||||
GenericValue rv;
|
|
||||||
rv.IntVal = ExitCode;
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +50,8 @@ public:
|
|||||||
|
|
||||||
/// run - Start execution with the specified function and arguments.
|
/// run - Start execution with the specified function and arguments.
|
||||||
///
|
///
|
||||||
virtual GenericValue run(Function *F,
|
virtual GenericValue runFunction(Function *F,
|
||||||
const std::vector<GenericValue> &ArgValues);
|
const std::vector<GenericValue> &ArgValues);
|
||||||
|
|
||||||
/// getPointerToNamedFunction - This method returns the address of the
|
/// getPointerToNamedFunction - This method returns the address of the
|
||||||
/// specified function by using the dlsym function call. As such it is only
|
/// specified function by using the dlsym function call. As such it is only
|
||||||
@ -64,11 +64,6 @@ public:
|
|||||||
//
|
//
|
||||||
static void CompilationCallback();
|
static void CompilationCallback();
|
||||||
|
|
||||||
/// runAtExitHandlers - Before exiting the program, at_exit functions must be
|
|
||||||
/// called. This method calls them.
|
|
||||||
///
|
|
||||||
static void runAtExitHandlers();
|
|
||||||
|
|
||||||
/// getPointerToFunction - This returns the address of the specified function,
|
/// getPointerToFunction - This returns the address of the specified function,
|
||||||
/// compiling it if necessary.
|
/// compiling it if necessary.
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user