[llvm] r330537 - [lli] Make error handling more consistent.

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 22 01:02:11 PDT 2018


Author: jdevlieghere
Date: Sun Apr 22 01:02:11 2018
New Revision: 330537

URL: http://llvm.org/viewvc/llvm-project?rev=330537&view=rev
Log:
[lli] Make error handling more consistent.

Makes error handling more consistent by using the helpers in support.

Modified:
    llvm/trunk/tools/lli/lli.cpp

Modified: llvm/trunk/tools/lli/lli.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/lli.cpp?rev=330537&r1=330536&r2=330537&view=diff
==============================================================================
--- llvm/trunk/tools/lli/lli.cpp (original)
+++ llvm/trunk/tools/lli/lli.cpp Sun Apr 22 01:02:11 2018
@@ -51,6 +51,7 @@
 #include "llvm/Support/Program.h"
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/Support/WithColor.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Transforms/Instrumentation.h"
 #include <cerrno>
@@ -294,7 +295,7 @@ static void addCygMingExtraModule(Execut
 CodeGenOpt::Level getOptLevel() {
   switch (OptLevel) {
   default:
-    errs() << "lli: Invalid optimization level.\n";
+    WithColor::error(errs(), "lli") << "invalid optimization level.\n";
     exit(1);
   case '0': return CodeGenOpt::None;
   case '1': return CodeGenOpt::Less;
@@ -403,8 +404,8 @@ int main(int argc, char **argv, char * c
     builder.setMCJITMemoryManager(
       std::unique_ptr<RTDyldMemoryManager>(RTDyldMM));
   } else if (RemoteMCJIT) {
-    errs() << "error: Remote process execution does not work with the "
-              "interpreter.\n";
+    WithColor::error(errs(), argv[0])
+        << "remote process execution does not work with the interpreter.\n";
     exit(1);
   }
 
@@ -419,9 +420,10 @@ int main(int argc, char **argv, char * c
   std::unique_ptr<ExecutionEngine> EE(builder.create());
   if (!EE) {
     if (!ErrorMsg.empty())
-      errs() << argv[0] << ": error creating EE: " << ErrorMsg << "\n";
+      WithColor::error(errs(), argv[0])
+          << "error creating EE: " << ErrorMsg << "\n";
     else
-      errs() << argv[0] << ": unknown error creating EE!\n";
+      WithColor::error(errs(), argv[0]) << "unknown error creating EE!\n";
     exit(1);
   }
 
@@ -494,7 +496,8 @@ int main(int argc, char **argv, char * c
                 JITEventListener::createIntelJITEventListener());
 
   if (!NoLazyCompilation && RemoteMCJIT) {
-    errs() << "warning: remote mcjit does not support lazy compilation\n";
+    WithColor::warning(errs(), argv[0])
+        << "remote mcjit does not support lazy compilation\n";
     NoLazyCompilation = true;
   }
   EE->DisableLazyCompilation(NoLazyCompilation);
@@ -520,7 +523,8 @@ int main(int argc, char **argv, char * c
   //
   Function *EntryFn = Mod->getFunction(EntryFunc);
   if (!EntryFn) {
-    errs() << '\'' << EntryFunc << "\' function not found in module.\n";
+    WithColor::error(errs(), argv[0])
+        << '\'' << EntryFunc << "\' function not found in module.\n";
     return -1;
   }
 
@@ -533,16 +537,19 @@ int main(int argc, char **argv, char * c
   // remote JIT on Unix platforms.
   if (RemoteMCJIT) {
 #ifndef LLVM_ON_UNIX
-    errs() << "Warning: host does not support external remote targets.\n"
-           << "  Defaulting to local execution\n";
+    WithColor::warning(errs(), argv[0])
+        << "host does not support external remote targets.\n" WithColor::note()
+        << "defaulting to local execution\n";
     return -1;
 #else
     if (ChildExecPath.empty()) {
-      errs() << "-remote-mcjit requires -mcjit-remote-process.\n";
+      WithColor::error(errs(), argv[0])
+          << "-remote-mcjit requires -mcjit-remote-process.\n";
       exit(1);
     } else if (!sys::fs::can_execute(ChildExecPath)) {
-      errs() << "Unable to find usable child executable: '" << ChildExecPath
-             << "'\n";
+      WithColor::error(errs(), argv[0])
+          << "unable to find usable child executable: '" << ChildExecPath
+          << "'\n";
       return -1;
     }
 #endif
@@ -582,10 +589,11 @@ int main(int argc, char **argv, char * c
       ResultGV.IntVal = APInt(32, Result);
       Args.push_back(ResultGV);
       EE->runFunction(ExitF, Args);
-      errs() << "ERROR: exit(" << Result << ") returned!\n";
+      WithColor::error(errs(), argv[0]) << "exit(" << Result << ") returned!\n";
       abort();
     } else {
-      errs() << "ERROR: exit defined with wrong prototype!\n";
+      WithColor::error(errs(), argv[0])
+          << "exit defined with wrong prototype!\n";
       abort();
     }
   } else {
@@ -598,7 +606,7 @@ int main(int argc, char **argv, char * c
     // Lanch the remote process and get a channel to it.
     std::unique_ptr<FDRawChannel> C = launchRemote();
     if (!C) {
-      errs() << "Failed to launch remote JIT.\n";
+      WithColor::error(errs(), argv[0]) << "failed to launch remote JIT.\n";
       exit(1);
     }
 




More information about the llvm-commits mailing list