diff options
Diffstat (limited to 'tools/lli/OrcLazyJIT.cpp')
-rw-r--r-- | tools/lli/OrcLazyJIT.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/tools/lli/OrcLazyJIT.cpp b/tools/lli/OrcLazyJIT.cpp index 2e15894152f9..f1a752e0790d 100644 --- a/tools/lli/OrcLazyJIT.cpp +++ b/tools/lli/OrcLazyJIT.cpp @@ -148,18 +148,19 @@ int llvm::runOrcLazyJIT(std::vector<std::unique_ptr<Module>> Ms, // Add the module, look up main and run it. for (auto &M : Ms) - J.addModule(std::shared_ptr<Module>(std::move(M))); - auto MainSym = J.findSymbol("main"); - - if (!MainSym) { + cantFail(J.addModule(std::shared_ptr<Module>(std::move(M)))); + + if (auto MainSym = J.findSymbol("main")) { + typedef int (*MainFnPtr)(int, const char*[]); + std::vector<const char *> ArgV; + for (auto &Arg : Args) + ArgV.push_back(Arg.c_str()); + auto Main = fromTargetAddress<MainFnPtr>(cantFail(MainSym.getAddress())); + return Main(ArgV.size(), (const char**)ArgV.data()); + } else if (auto Err = MainSym.takeError()) + logAllUnhandledErrors(std::move(Err), llvm::errs(), ""); + else errs() << "Could not find main function.\n"; - return 1; - } - using MainFnPtr = int (*)(int, const char*[]); - std::vector<const char *> ArgV; - for (auto &Arg : Args) - ArgV.push_back(Arg.c_str()); - auto Main = fromTargetAddress<MainFnPtr>(MainSym.getAddress()); - return Main(ArgV.size(), (const char**)ArgV.data()); + return 1; } |