- // Add the module's name to the start of the vector of arguments to main().
- InputArgv.insert(InputArgv.begin(), InputFile);
-
- // 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;
+ 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);
+
+ // 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 *MainFn = Mod->getFunction("main");
+ if (!MainFn) {
+ std::cerr << "'main' function not found in module.\n";
+ return -1;
+ }
+
+ // If the program doesn't explicitly call exit, we will need the Exit
+ // function later on to make an explicit call, so get the function now.
+ Constant *Exit = Mod->getOrInsertFunction("exit", Type::VoidTy,
+ Type::Int32Ty, NULL);
+
+ // Reset errno to zero on entry to main.
+ errno = 0;
+
+ // Run static constructors.
+ EE->runStaticConstructorsDestructors(false);
+
+ if (NoLazyCompilation) {
+ for (Module::iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) {
+ Function *Fn = &*I;
+ if (Fn != MainFn && !Fn->isDeclaration())
+ EE->getPointerToFunction(Fn);