From aa9bcfc6a2bbcda010c5bd453ca3c15ea9c0b2d4 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Sun, 22 Apr 2018 08:01:35 +0000 Subject: [PATCH] [llvm-mc] Make error handling more consistent. Makes error handling more consistent by using the helpers in support. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330536 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/MC/AsmParser/defsym_error2.s | 2 +- tools/llvm-mc/llvm-mc.cpp | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/test/MC/AsmParser/defsym_error2.s b/test/MC/AsmParser/defsym_error2.s index ec4cc79182f..e2d9fea0030 100644 --- a/test/MC/AsmParser/defsym_error2.s +++ b/test/MC/AsmParser/defsym_error2.s @@ -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 diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index 6b3c30fa923..c3ec9d495fa 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -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 char *ProgName) { 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 GetOutputStream() { auto Out = llvm::make_unique(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(MCAsmParser &Parser) { 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 *ProgName, const Target *TheTarget, 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> 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;