[llvm] r330536 - [llvm-mc] Make error handling more consistent.

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


Author: jdevlieghere
Date: Sun Apr 22 01:01:35 2018
New Revision: 330536

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

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

Modified:
    llvm/trunk/test/MC/AsmParser/defsym_error2.s
    llvm/trunk/tools/llvm-mc/llvm-mc.cpp

Modified: llvm/trunk/test/MC/AsmParser/defsym_error2.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/defsym_error2.s?rev=330536&r1=330535&r2=330536&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/defsym_error2.s (original)
+++ llvm/trunk/test/MC/AsmParser/defsym_error2.s Sun Apr 22 01:01:35 2018
@@ -1,2 +1,2 @@
 # RUN: not llvm-mc -filetype=obj -triple=i386-unknown-elf -defsym a=a %s 2>&1 | FileCheck %s
-# CHECK: error: Value is not an integer: a
+# CHECK: error: value is not an integer: a

Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=330536&r1=330535&r2=330536&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Sun Apr 22 01:01:35 2018
@@ -37,6 +37,7 @@
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/ToolOutputFile.h"
+#include "llvm/Support/WithColor.h"
 
 using namespace llvm;
 
@@ -186,7 +187,7 @@ static const Target *GetTarget(const cha
   const Target *TheTarget = TargetRegistry::lookupTarget(ArchName, TheTriple,
                                                          Error);
   if (!TheTarget) {
-    errs() << ProgName << ": " << Error;
+    WithColor::error(errs(), ProgName) << Error;
     return nullptr;
   }
 
@@ -203,7 +204,7 @@ static std::unique_ptr<ToolOutputFile> G
   auto Out =
       llvm::make_unique<ToolOutputFile>(OutputFilename, EC, sys::fs::F_None);
   if (EC) {
-    errs() << EC.message() << '\n';
+    WithColor::error() << EC.message() << '\n';
     return nullptr;
   }
 
@@ -252,12 +253,13 @@ static int fillCommandLineSymbols(MCAsmP
     auto Val = Pair.second;
 
     if (Sym.empty() || Val.empty()) {
-      errs() << "error: defsym must be of the form: sym=value: " << I << "\n";
+      WithColor::error() << "defsym must be of the form: sym=value: " << I
+                         << "\n";
       return 1;
     }
     int64_t Value;
     if (Val.getAsInteger(0, Value)) {
-      errs() << "error: Value is not an integer: " << Val << "\n";
+      WithColor::error() << "value is not an integer: " << Val << "\n";
       return 1;
     }
     Parser.getContext().setSymbolValue(Parser.getStreamer(), Sym, Value);
@@ -275,8 +277,8 @@ static int AssembleInput(const char *Pro
       TheTarget->createMCAsmParser(STI, *Parser, MCII, MCOptions));
 
   if (!TAP) {
-    errs() << ProgName
-           << ": error: this target does not support assembly parsing.\n";
+    WithColor::error(errs(), ProgName)
+        << "this target does not support assembly parsing.\n";
     return 1;
   }
 
@@ -321,7 +323,8 @@ int main(int argc, char **argv) {
   ErrorOr<std::unique_ptr<MemoryBuffer>> BufferPtr =
       MemoryBuffer::getFileOrSTDIN(InputFilename);
   if (std::error_code EC = BufferPtr.getError()) {
-    errs() << InputFilename << ": " << EC.message() << '\n';
+    WithColor::error(errs(), ProgName)
+        << InputFilename << ": " << EC.message() << '\n';
     return 1;
   }
   MemoryBuffer *Buffer = BufferPtr->get();
@@ -345,8 +348,8 @@ int main(int argc, char **argv) {
 
   if (CompressDebugSections != DebugCompressionType::None) {
     if (!zlib::isAvailable()) {
-      errs() << ProgName
-             << ": build tools with zlib to enable -compress-debug-sections";
+      WithColor::error(errs(), ProgName)
+          << "build tools with zlib to enable -compress-debug-sections";
       return 1;
     }
     MAI->setCompressDebugSections(CompressDebugSections);
@@ -425,8 +428,8 @@ int main(int argc, char **argv) {
                                         *MAI, *MCII, *MRI);
 
     if (!IP) {
-      errs()
-          << "error: unable to create instruction printer for target triple '"
+      WithColor::error()
+          << "unable to create instruction printer for target triple '"
           << TheTriple.normalize() << "' with assembly variant "
           << OutputAsmVariant << ".\n";
       return 1;




More information about the llvm-commits mailing list