diff --git a/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp index 08ca6e03a7af..1252ed5df8a8 100644 --- a/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp +++ b/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp @@ -37,6 +37,7 @@ #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SHA1.h" +#include "llvm/Support/WithColor.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; @@ -444,7 +445,7 @@ static std::map BlockIDStats; /// ReportError - All bitcode analysis errors go through this function, making this a /// good place to breakpoint if debugging. static bool ReportError(const Twine &Err) { - errs() << Err << "\n"; + WithColor::error() << Err << "\n"; return true; } diff --git a/llvm/tools/llvm-dis/llvm-dis.cpp b/llvm/tools/llvm-dis/llvm-dis.cpp index 0fe5257091a1..f254a761f873 100644 --- a/llvm/tools/llvm-dis/llvm-dis.cpp +++ b/llvm/tools/llvm-dis/llvm-dis.cpp @@ -32,6 +32,7 @@ #include "llvm/Support/InitLLVM.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/ToolOutputFile.h" +#include "llvm/Support/WithColor.h" #include using namespace llvm; @@ -127,10 +128,10 @@ struct LLVMDisDiagnosticHandler : public DiagnosticHandler { raw_ostream &OS = errs(); OS << Prefix << ": "; switch (DI.getSeverity()) { - case DS_Error: OS << "error: "; break; - case DS_Warning: OS << "warning: "; break; + case DS_Error: WithColor::error(OS); break; + case DS_Warning: WithColor::warning(OS); break; case DS_Remark: OS << "remark: "; break; - case DS_Note: OS << "note: "; break; + case DS_Note: WithColor::note(OS); break; } DiagnosticPrinterRawOStream DP(OS); diff --git a/llvm/tools/llvm-opt-report/OptReport.cpp b/llvm/tools/llvm-opt-report/OptReport.cpp index c247da4f55c6..c90fdb0ad019 100644 --- a/llvm/tools/llvm-opt-report/OptReport.cpp +++ b/llvm/tools/llvm-opt-report/OptReport.cpp @@ -25,6 +25,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/Program.h" +#include "llvm/Support/WithColor.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" #include @@ -273,8 +274,8 @@ static bool readLocationInfo(LocationInfoTy &LocationInfo) { ErrorOr> Buf = MemoryBuffer::getFileOrSTDIN(InputFileName); if (std::error_code EC = Buf.getError()) { - errs() << "error: Can't open file " << InputFileName << ": " << - EC.message() << "\n"; + WithColor::error() << "Can't open file " << InputFileName << ": " + << EC.message() << "\n"; return false; } @@ -282,7 +283,7 @@ static bool readLocationInfo(LocationInfoTy &LocationInfo) { yaml::Stream Stream(Buf.get()->getBuffer(), SM); collectLocationInfo(Stream, LocationInfo); - return true; + return true; } static bool writeReport(LocationInfoTy &LocationInfo) { @@ -290,8 +291,8 @@ static bool writeReport(LocationInfoTy &LocationInfo) { llvm::raw_fd_ostream OS(OutputFileName, EC, llvm::sys::fs::F_Text); if (EC) { - errs() << "error: Can't open file " << OutputFileName << ": " << - EC.message() << "\n"; + WithColor::error() << "Can't open file " << OutputFileName << ": " + << EC.message() << "\n"; return false; } @@ -300,8 +301,8 @@ static bool writeReport(LocationInfoTy &LocationInfo) { SmallString<128> FileName(FI.first); if (!InputRelDir.empty()) { if (std::error_code EC = sys::fs::make_absolute(InputRelDir, FileName)) { - errs() << "error: Can't resolve file path to " << FileName << ": " << - EC.message() << "\n"; + WithColor::error() << "Can't resolve file path to " << FileName << ": " + << EC.message() << "\n"; return false; } } @@ -311,8 +312,8 @@ static bool writeReport(LocationInfoTy &LocationInfo) { ErrorOr> Buf = MemoryBuffer::getFile(FileName); if (std::error_code EC = Buf.getError()) { - errs() << "error: Can't open file " << FileName << ": " << - EC.message() << "\n"; + WithColor::error() << "Can't open file " << FileName << ": " + << EC.message() << "\n"; return false; } @@ -396,7 +397,7 @@ static bool writeReport(LocationInfoTy &LocationInfo) { if (!Printed) OS << FuncName; - } + } OS << ":\n"; } @@ -522,8 +523,7 @@ int main(int argc, const char **argv) { if (!readLocationInfo(LocationInfo)) return 1; if (!writeReport(LocationInfo)) - return 1; + return 1; return 0; } - diff --git a/llvm/tools/yaml2obj/yaml2elf.cpp b/llvm/tools/yaml2obj/yaml2elf.cpp index 1267a26dac2a..fb23d1f7cf75 100644 --- a/llvm/tools/yaml2obj/yaml2elf.cpp +++ b/llvm/tools/yaml2obj/yaml2elf.cpp @@ -19,6 +19,7 @@ #include "llvm/Object/ELFObjectFile.h" #include "llvm/ObjectYAML/ELFYAML.h" #include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/WithColor.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Support/raw_ostream.h" @@ -243,8 +244,8 @@ bool ELFState::initSectionHeaders(std::vector &SHeaders, if (!Sec->Link.empty()) { unsigned Index; if (SN2I.lookup(Sec->Link, Index)) { - errs() << "error: Unknown section referenced: '" << Sec->Link - << "' at YAML section '" << Sec->Name << "'.\n"; + WithColor::error() << "Unknown section referenced: '" << Sec->Link + << "' at YAML section '" << Sec->Name << "'.\n"; return false; } SHeader.sh_link = Index; @@ -260,8 +261,8 @@ bool ELFState::initSectionHeaders(std::vector &SHeaders, unsigned Index; if (SN2I.lookup(S->Info, Index)) { if (S->Info.getAsInteger(0, Index)) { - errs() << "error: Unknown section referenced: '" << S->Info - << "' at YAML section '" << S->Name << "'.\n"; + WithColor::error() << "Unknown section referenced: '" << S->Info + << "' at YAML section '" << S->Name << "'.\n"; return false; } } @@ -272,8 +273,8 @@ bool ELFState::initSectionHeaders(std::vector &SHeaders, } else if (auto S = dyn_cast(Sec.get())) { unsigned SymIdx; if (SymN2I.lookup(S->Info, SymIdx)) { - errs() << "error: Unknown symbol referenced: '" << S->Info - << "' at YAML section '" << S->Name << "'.\n"; + WithColor::error() << "Unknown symbol referenced: '" << S->Info + << "' at YAML section '" << S->Name << "'.\n"; return false; } SHeader.sh_info = SymIdx; @@ -430,8 +431,8 @@ void ELFState::addSymbols(const std::vector &Symbols, if (!Sym.Section.empty()) { unsigned Index; if (SN2I.lookup(Sym.Section, Index)) { - errs() << "error: Unknown section referenced: '" << Sym.Section - << "' by YAML symbol " << Sym.Name << ".\n"; + WithColor::error() << "Unknown section referenced: '" << Sym.Section + << "' by YAML symbol " << Sym.Name << ".\n"; exit(1); } Symbol.st_shndx = Index; @@ -528,9 +529,9 @@ bool ELFState::writeSectionContent(Elf_Shdr &SHeader, if (member.sectionNameOrType == "GRP_COMDAT") sectionIndex = llvm::ELF::GRP_COMDAT; else if (SN2I.lookup(member.sectionNameOrType, sectionIndex)) { - errs() << "error: Unknown section referenced: '" - << member.sectionNameOrType << "' at YAML section' " - << Section.Name << "\n"; + WithColor::error() << "Unknown section referenced: '" + << member.sectionNameOrType << "' at YAML section' " + << Section.Name << "\n"; return false; } SIdx = sectionIndex; @@ -574,8 +575,8 @@ template bool ELFState::buildSectionIndex() { DotShStrtab.add(Name); // "+ 1" to take into account the SHT_NULL entry. if (SN2I.addName(Name, i + 1)) { - errs() << "error: Repeated section name: '" << Name - << "' at YAML section number " << i << ".\n"; + WithColor::error() << "Repeated section name: '" << Name + << "' at YAML section number " << i << ".\n"; return false; } } @@ -602,7 +603,7 @@ ELFState::buildSymbolIndex(std::size_t &StartIndex, if (Sym.Name.empty()) continue; if (SymN2I.addName(Sym.Name, StartIndex)) { - errs() << "error: Repeated symbol name: '" << Sym.Name << "'.\n"; + WithColor::error() << "Repeated symbol name: '" << Sym.Name << "'.\n"; return false; } }