summaryrefslogtreecommitdiff
path: root/tools/lli
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-03-03 18:21:44 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-03-03 18:21:44 +0000
commitf70d67750102509d0192c58ab5ddf4e450b5f114 (patch)
tree9d929558b69c26f5df3d38a977120177b8a6c0c3 /tools/lli
parentd4c0e62413ac4c81467ce59025c81210ea431752 (diff)
downloadllvm-f70d67750102509d0192c58ab5ddf4e450b5f114.tar.gz
llvm-f70d67750102509d0192c58ab5ddf4e450b5f114.tar.bz2
llvm-f70d67750102509d0192c58ab5ddf4e450b5f114.tar.xz
1. Handle errors around the ModuleProvider. This is necessary since it is
reading bytecode. 2. The interpreter can delete the ModuleProvider and replace it with another so don't depend on it being around after the EE is created. 3. Don't just run llvm_shutdown on exit but actually delete the EE as well. This cleans up a vast amount of memory (but not all) that EE retained through exit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34888 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/lli')
-rw-r--r--tools/lli/lli.cpp34
1 files changed, 23 insertions, 11 deletions
diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp
index 0f96a4a2b1..c02d2a4419 100644
--- a/tools/lli/lli.cpp
+++ b/tools/lli/lli.cpp
@@ -54,11 +54,18 @@ namespace {
cl::desc("Disable emission of core files if possible"));
}
+static ExecutionEngine *EE = 0;
+
+static void do_shutdown() {
+ delete EE;
+ llvm_shutdown();
+}
+
//===----------------------------------------------------------------------===//
// main Driver function
//
int main(int argc, char **argv, char * const *envp) {
- atexit(llvm_shutdown); // Call llvm_shutdown() on exit.
+ atexit(do_shutdown); // Call llvm_shutdown() on exit.
try {
cl::ParseCommandLineOptions(argc, argv,
" llvm interpreter & dynamic compiler\n");
@@ -70,22 +77,27 @@ int main(int argc, char **argv, char * const *envp) {
// Load the bytecode...
std::string ErrorMsg;
- ModuleProvider *MP = 0;
- MP = getBytecodeModuleProvider(InputFile,
- Compressor::decompressToNewBuffer,
- &ErrorMsg);
+ ModuleProvider *MP = getBytecodeModuleProvider(InputFile,
+ Compressor::decompressToNewBuffer,
+ &ErrorMsg);
if (!MP) {
- std::cerr << "Error loading program '" << InputFile << "': "
+ std::cerr << argv[0] << ": error loading program '" << InputFile << "': "
<< ErrorMsg << "\n";
exit(1);
}
+ // Get the module as the MP could go away once EE takes over.
+ Module *Mod = MP->getModule();
+
// If we are supposed to override the target triple, do so now.
if (!TargetTriple.empty())
- MP->getModule()->setTargetTriple(TargetTriple);
+ Mod->setTargetTriple(TargetTriple);
- ExecutionEngine *EE = ExecutionEngine::create(MP, ForceInterpreter);
- assert(EE &&"Couldn't create an ExecutionEngine, not even an interpreter?");
+ EE = ExecutionEngine::create(MP, ForceInterpreter, &ErrorMsg);
+ if (!EE && !ErrorMsg.empty()) {
+ std::cerr << argv[0] << ":error creating EE: " << ErrorMsg << "\n";
+ exit(1);
+ }
// If the user specifically requested an argv[0] to pass into the program,
// do it now.
@@ -106,7 +118,7 @@ int main(int argc, char **argv, char * const *envp) {
// using the contents of Args to determine argc & argv, and the contents of
// EnvVars to determine envp.
//
- Function *Fn = MP->getModule()->getFunction("main");
+ Function *Fn = Mod->getFunction("main");
if (!Fn) {
std::cerr << "'main' function not found in module.\n";
return -1;
@@ -123,7 +135,7 @@ int main(int argc, char **argv, char * const *envp) {
// If the program didn't explicitly call exit, call exit now, for the
// program. This ensures that any atexit handlers get called correctly.
- Constant *Exit = MP->getModule()->getOrInsertFunction("exit", Type::VoidTy,
+ Constant *Exit = Mod->getOrInsertFunction("exit", Type::VoidTy,
Type::Int32Ty, NULL);
if (Function *ExitF = dyn_cast<Function>(Exit)) {
std::vector<GenericValue> Args;