summaryrefslogtreecommitdiff
path: root/tools/lli/lli.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-12-26 06:14:47 +0000
committerChris Lattner <sabre@nondot.org>2003-12-26 06:14:47 +0000
commitefec9669d90f90703e92e0a3851bc5fb9b0f8fd8 (patch)
tree55e9e356f264f476edac2cb1c04f14e807e994d5 /tools/lli/lli.cpp
parentff0f1bb32a439cf82cb09ee29544c894a2bfe877 (diff)
downloadllvm-efec9669d90f90703e92e0a3851bc5fb9b0f8fd8.tar.gz
llvm-efec9669d90f90703e92e0a3851bc5fb9b0f8fd8.tar.bz2
llvm-efec9669d90f90703e92e0a3851bc5fb9b0f8fd8.tar.xz
* eliminate the -f argument to lli, as it was silly and never useful anyway
* Inline callMain function * Remove hack from the ExecutionEngines where the 'run' method would automatically run atExit functions. Fixing this requires explicitly calling exit if main returns git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10611 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/lli/lli.cpp')
-rw-r--r--tools/lli/lli.cpp68
1 files changed, 32 insertions, 36 deletions
diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp
index 0f65d9d9b8..f061bea158 100644
--- a/tools/lli/lli.cpp
+++ b/tools/lli/lli.cpp
@@ -34,10 +34,6 @@ namespace {
cl::list<std::string>
InputArgv(cl::ConsumeAfter, cl::desc("<program arguments>..."));
- cl::opt<std::string>
- MainFunction("f", cl::desc("Function to execute"), cl::init("main"),
- cl::value_desc("function name"));
-
cl::opt<bool> ForceInterpreter("force-interpreter",
cl::desc("Force interpretation: disable JIT"),
cl::init(false));
@@ -96,32 +92,6 @@ static void *CreateArgv(ExecutionEngine *EE,
}
}
-/// callAsMain - Call the function named FnName from M as if its
-/// signature were int main (int argc, char **argv, const char
-/// **envp), using the contents of Args to determine argc & argv, and
-/// the contents of EnvVars to determine envp. Returns the result
-/// from calling FnName, or -1 and prints an error msg. if the named
-/// function cannot be found.
-///
-int callAsMain(ExecutionEngine *EE, ModuleProvider *MP,
- const std::string &FnName,
- const std::vector<std::string> &Args,
- const std::vector<std::string> &EnvVars) {
- Function *Fn = MP->getModule()->getNamedFunction(FnName);
- if (!Fn) {
- std::cerr << "Function '" << FnName << "' not found in module.\n";
- return -1;
- }
- std::vector<GenericValue> GVArgs;
- GenericValue GVArgc;
- GVArgc.IntVal = Args.size();
- GVArgs.push_back(GVArgc); // Arg #0 = argc.
- GVArgs.push_back(PTOGV(CreateArgv(EE, Args))); // Arg #1 = argv.
- assert(((char **)GVTOP(GVArgs[1]))[0] && "argv[0] was null after CreateArgv");
- GVArgs.push_back(PTOGV(CreateArgv(EE, EnvVars))); // Arg #2 = envp.
- return EE->run(Fn, GVArgs).IntVal;
-}
-
//===----------------------------------------------------------------------===//
// main Driver function
//
@@ -157,11 +127,37 @@ int main(int argc, char **argv, char * const *envp) {
// Add the module's name to the start of the vector of arguments to main().
InputArgv.insert(InputArgv.begin(), InputFile);
- // Run the main function!
- int ExitCode = callAsMain(EE, MP, MainFunction, InputArgv,
- makeStringVector(envp));
+ // Call the main function from M as if its signature were:
+ // int main (int argc, char **argv, const char **envp)
+ // using the contents of Args to determine argc & argv, and the contents of
+ // EnvVars to determine envp.
+ //
+ Function *Fn = MP->getModule()->getMainFunction();
+ if (!Fn) {
+ std::cerr << "'main' function not found in module.\n";
+ return -1;
+ }
+
+ std::vector<GenericValue> GVArgs;
+ GenericValue GVArgc;
+ GVArgc.IntVal = InputArgv.size();
+ GVArgs.push_back(GVArgc); // Arg #0 = argc.
+ GVArgs.push_back(PTOGV(CreateArgv(EE, InputArgv))); // Arg #1 = argv.
+ assert(((char **)GVTOP(GVArgs[1]))[0] && "argv[0] was null after CreateArgv");
- // Now that we are done executing the program, shut down the execution engine
- delete EE;
- return ExitCode;
+ std::vector<std::string> EnvVars = makeStringVector(envp);
+ GVArgs.push_back(PTOGV(CreateArgv(EE, EnvVars))); // Arg #2 = envp.
+ GenericValue Result = EE->runFunction(Fn, GVArgs);
+
+ // If the program didn't explicitly call exit, call exit now, for the program.
+ // This ensures that any atexit handlers get called correctly.
+ Function *Exit = MP->getModule()->getOrInsertFunction("exit", Type::VoidTy,
+ Type::IntTy, 0);
+
+ GVArgs.clear();
+ GVArgs.push_back(Result);
+ EE->runFunction(Exit, GVArgs);
+
+ std::cerr << "ERROR: exit(" << Result.IntVal << ") returned!\n";
+ abort();
}