diff options
author | Brian Gaeke <gaeke@uiuc.edu> | 2003-09-05 18:42:01 +0000 |
---|---|---|
committer | Brian Gaeke <gaeke@uiuc.edu> | 2003-09-05 18:42:01 +0000 |
commit | 70975eef572b9e132bbaade16ba9edb76f15f287 (patch) | |
tree | edbaec8a92e10f18d1195cdb5d0fc1b59b4520d2 /lib/ExecutionEngine/Interpreter/Interpreter.cpp | |
parent | 5bea411ad288ea6f25ac296ae2d75a4bfab8bf98 (diff) |
Make CreateArgv part of lli rather than part of ExecutionEngine.
Switch Interpreter and JIT's "run" methods to take a Function and a vector of
GenericValues.
Move (almost all of) the stuff that constructs a canonical call to main()
into lli (new methods "callAsMain", "makeStringVector").
Nuke getCurrentExecutablePath(), enableTracing(), getCurrentFunction(),
isStopped(), and many dead decls from interpreter.
Add linux strdup() support to interpreter.
Make interpreter's atexit handler runner and JIT's runAtExitHandlers() look
more alike, in preparation for refactoring.
atexit() is spelled "atexit", not "at_exit".
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8366 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/Interpreter/Interpreter.cpp')
-rw-r--r-- | lib/ExecutionEngine/Interpreter/Interpreter.cpp | 89 |
1 files changed, 33 insertions, 56 deletions
diff --git a/lib/ExecutionEngine/Interpreter/Interpreter.cpp b/lib/ExecutionEngine/Interpreter/Interpreter.cpp index 6b82dada33..518290a9f7 100644 --- a/lib/ExecutionEngine/Interpreter/Interpreter.cpp +++ b/lib/ExecutionEngine/Interpreter/Interpreter.cpp @@ -54,69 +54,46 @@ Interpreter::Interpreter(Module *M, bool isLittleEndian, bool isLongPointer, emitGlobals(); } -/// run - Start execution with the specified function and arguments. -/// -int Interpreter::run(const std::string &MainFunction, - const std::vector<std::string> &Args, - const char ** envp) { - // Start interpreter into the main function... - // - if (!callMainFunction(MainFunction, Args)) { - // If the call succeeded, run the code now... +void Interpreter::runAtExitHandlers () { + while (!AtExitHandlers.empty()) { + callFunction(AtExitHandlers.back(), std::vector<GenericValue>()); + AtExitHandlers.pop_back(); run(); } - - do { - // 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()); - - return ExitCode; } - -// callMainFunction - Construct call to typical C main() function and -// call it using callFunction(). -// -bool Interpreter::callMainFunction(const std::string &Name, - const std::vector<std::string> &InputArgv) { - Function *M = getModule().getNamedFunction(Name); - if (M == 0) { - std::cerr << "Could not find function '" << Name << "' in module!\n"; - return 1; - } - const FunctionType *MT = M->getFunctionType(); - - std::vector<GenericValue> Args; - if (MT->getParamTypes().size() >= 2) { - PointerType *SPP = PointerType::get(PointerType::get(Type::SByteTy)); - if (MT->getParamTypes()[1] != SPP) { - CW << "Second argument of '" << Name << "' should have type: '" - << SPP << "'!\n"; - return true; - } - Args.push_back(PTOGV(CreateArgv(InputArgv))); - } - - if (MT->getParamTypes().size() >= 1) { - if (!MT->getParamTypes()[0]->isInteger()) { - std::cout << "First argument of '" << Name - << "' should be an integer!\n"; - return true; - } else { - GenericValue GV; GV.UIntVal = InputArgv.size(); - Args.insert(Args.begin(), GV); - } +/// run - Start execution with the specified function and arguments. +/// +GenericValue Interpreter::run(Function *F, + const std::vector<GenericValue> &ArgValues) { + assert (F && "Function *F was null at entry to run()"); + + // Try extra hard not to pass extra args to a function that isn't + // expecting them. C programmers frequently bend the rules and + // declare main() with fewer parameters than it actually gets + // passed, and the interpreter barfs if you pass a function more + // parameters than it is declared to take. This does not attempt to + // take into account gratuitous differences in declared types, + // though. + std::vector<GenericValue> ActualArgs; + const unsigned ArgCount = F->getFunctionType()->getParamTypes().size(); + for (unsigned i = 0; i < ArgCount; ++i) { + ActualArgs.push_back (ArgValues[i]); } - - callFunction(M, Args); // Start executing it... + + // Set up the function call. + callFunction(F, ActualArgs); // Reset the current frame location to the top of stack CurFrame = ECStack.size()-1; - return false; + // Start executing the function. + run(); + + // Run any atexit handlers now! + runAtExitHandlers(); + + GenericValue rv; + rv.IntVal = ExitCode; + return rv; } |