- // Handle alternate names of the program. If started as llp, enable profiling
- // if started as ldb, enable debugging...
- //
- if (argv[0] == "ldb") // TODO: Obviously incorrect, but you get the idea
- DebugMode = true;
- else if (argv[0] == "llp")
- ProfileMode = true;
-
- // If running with the profiler, enable it now...
- if (ProfileMode) I.enableProfiling();
- if (TraceMode) I.enableTracing();
-
- // Ensure that there is at least one argument... the name of the program.
- // This is only unavailable if the program was read from stdin, instead of a
- // file.
- //
- if (InputArgv.empty())
- InputArgv.push_back("from-stdin-prog");
+ // Get the module as the MP could go away once EE takes over.
+ Module *Mod = NoLazyCompilation
+ ? MP->materializeModule(&ErrorMsg) : MP->getModule();
+ if (!Mod) {
+ std::cerr << argv[0] << ": bitcode didn't read correctly.\n";
+ std::cerr << "Reason: " << ErrorMsg << "\n";
+ exit(1);
+ }
+
+ // If we are supposed to override the target triple, do so now.
+ if (!TargetTriple.empty())
+ Mod->setTargetTriple(TargetTriple);
+
+ EE = ExecutionEngine::create(MP, ForceInterpreter, &ErrorMsg);
+ if (!EE && !ErrorMsg.empty()) {
+ std::cerr << argv[0] << ":error creating EE: " << ErrorMsg << "\n";
+ exit(1);
+ }
+
+ if (NoLazyCompilation)
+ EE->DisableLazyCompilation();
+
+ // If the user specifically requested an argv[0] to pass into the program,
+ // do it now.
+ if (!FakeArgv0.empty()) {
+ InputFile = FakeArgv0;
+ } else {
+ // Otherwise, if there is a .bc suffix on the executable strip it off, it
+ // might confuse the program.
+ if (InputFile.rfind(".bc") == InputFile.length() - 3)
+ InputFile.erase(InputFile.length() - 3);
+ }
+
+ // Add the module's name to the start of the vector of arguments to main().
+ InputArgv.insert(InputArgv.begin(), InputFile);