diff options
| author | Lang Hames <lhames@gmail.com> | 2017-07-07 02:59:13 +0000 |
|---|---|---|
| committer | Lang Hames <lhames@gmail.com> | 2017-07-07 02:59:13 +0000 |
| commit | 4ce98662e7d109b4579c35945345db685ae5b3fb (patch) | |
| tree | 4538ca3c0131f3275286aac4347bf712ed0068e7 /llvm/tools/lli | |
| parent | b909f11a319ae62e683d1f9d82e28a05b360b8ae (diff) | |
| download | bcm5719-llvm-4ce98662e7d109b4579c35945345db685ae5b3fb.tar.gz bcm5719-llvm-4ce98662e7d109b4579c35945345db685ae5b3fb.zip | |
[ORC] Errorize the ORC APIs.
This patch updates the ORC layers and utilities to return and propagate
llvm::Errors where appropriate. This is necessary to allow ORC to safely handle
error cases in cross-process and remote JITing.
llvm-svn: 307350
Diffstat (limited to 'llvm/tools/lli')
| -rw-r--r-- | llvm/tools/lli/OrcLazyJIT.cpp | 25 | ||||
| -rw-r--r-- | llvm/tools/lli/OrcLazyJIT.h | 24 |
2 files changed, 31 insertions, 18 deletions
diff --git a/llvm/tools/lli/OrcLazyJIT.cpp b/llvm/tools/lli/OrcLazyJIT.cpp index 2e15894152f..f1a752e0790 100644 --- a/llvm/tools/lli/OrcLazyJIT.cpp +++ b/llvm/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; } diff --git a/llvm/tools/lli/OrcLazyJIT.h b/llvm/tools/lli/OrcLazyJIT.h index 5592fb65139..47a2acc4d7e 100644 --- a/llvm/tools/lli/OrcLazyJIT.h +++ b/llvm/tools/lli/OrcLazyJIT.h @@ -75,10 +75,14 @@ public: CXXRuntimeOverrides.runDestructors(); // Run any IR destructors. for (auto &DtorRunner : IRStaticDestructorRunners) - DtorRunner.runViaLayer(CODLayer); + if (auto Err = DtorRunner.runViaLayer(CODLayer)) { + // FIXME: OrcLazyJIT should probably take a "shutdownError" callback to + // report these errors on. + report_fatal_error(std::move(Err)); + } } - void addModule(std::shared_ptr<Module> M) { + Error addModule(std::shared_ptr<Module> M) { if (M->getDataLayout().isDefault()) M->setDataLayout(DL); @@ -125,19 +129,27 @@ public: ); // Add the module to the JIT. - ModulesHandle = - CODLayer.addModule(std::move(M), std::move(Resolver)); + if (auto ModulesHandleOrErr = + CODLayer.addModule(std::move(M), std::move(Resolver))) + ModulesHandle = std::move(*ModulesHandleOrErr); + else + return ModulesHandleOrErr.takeError(); + } else - CODLayer.addExtraModule(ModulesHandle, std::move(M)); + if (auto Err = CODLayer.addExtraModule(ModulesHandle, std::move(M))) + return Err; // Run the static constructors, and save the static destructor runner for // execution when the JIT is torn down. orc::CtorDtorRunner<CODLayerT> CtorRunner(std::move(CtorNames), ModulesHandle); - CtorRunner.runViaLayer(CODLayer); + if (auto Err = CtorRunner.runViaLayer(CODLayer)) + return Err; IRStaticDestructorRunners.emplace_back(std::move(DtorNames), ModulesHandle); + + return Error::success(); } JITSymbol findSymbol(const std::string &Name) { |

