From da8e6b2ec7ac75c400df7cc5563ce1aa6be27a5a Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Thu, 17 Nov 2016 22:58:13 +0000 Subject: [PATCH] [lli] Factor out error handling. NFCI. llvm-svn: 287276 --- llvm/tools/lli/lli.cpp | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp index 836a940..ecc90d7 100644 --- a/llvm/tools/lli/lli.cpp +++ b/llvm/tools/lli/lli.cpp @@ -357,6 +357,12 @@ CodeGenOpt::Level getOptLevel() { llvm_unreachable("Unrecognized opt level."); } +LLVM_ATTRIBUTE_NORETURN +static void reportError(SMDiagnostic Err, const char *ProgName) { + Err.print(ProgName, errs()); + exit(1); +} + //===----------------------------------------------------------------------===// // main Driver function // @@ -388,20 +394,16 @@ int main(int argc, char **argv, char * const *envp) { SMDiagnostic Err; std::unique_ptr Owner = parseIRFile(InputFile, Err, Context); Module *Mod = Owner.get(); - if (!Mod) { - Err.print(argv[0], errs()); - return 1; - } + if (!Mod) + reportError(Err, argv[0]); if (UseJITKind == JITKind::OrcLazy) { std::vector> Ms; Ms.push_back(std::move(Owner)); for (auto &ExtraMod : ExtraModules) { Ms.push_back(parseIRFile(ExtraMod, Err, Context)); - if (!Ms.back()) { - Err.print(argv[0], errs()); - return 1; - } + if (!Ms.back()) + reportError(Err, argv[0]); } std::vector Args; Args.push_back(InputFile); @@ -486,10 +488,8 @@ int main(int argc, char **argv, char * const *envp) { // Load any additional modules specified on the command line. for (unsigned i = 0, e = ExtraModules.size(); i != e; ++i) { std::unique_ptr XMod = parseIRFile(ExtraModules[i], Err, Context); - if (!XMod) { - Err.print(argv[0], errs()); - return 1; - } + if (!XMod) + reportError(Err, argv[0]); if (EnableCacheManager) { std::string CacheName("file:"); CacheName.append(ExtraModules[i]); @@ -504,8 +504,7 @@ int main(int argc, char **argv, char * const *envp) { if (!Obj) { // TODO: Actually report errors helpfully. consumeError(Obj.takeError()); - Err.print(argv[0], errs()); - return 1; + reportError(Err, argv[0]); } object::OwningBinary &O = Obj.get(); EE->addObjectFile(std::move(O)); @@ -514,10 +513,8 @@ int main(int argc, char **argv, char * const *envp) { for (unsigned i = 0, e = ExtraArchives.size(); i != e; ++i) { ErrorOr> ArBufOrErr = MemoryBuffer::getFileOrSTDIN(ExtraArchives[i]); - if (!ArBufOrErr) { - Err.print(argv[0], errs()); - return 1; - } + if (!ArBufOrErr) + reportError(Err, argv[0]); std::unique_ptr &ArBuf = ArBufOrErr.get(); Expected> ArOrErr = -- 2.7.4