[tools] Use WithColor for printing errors.
Use convenience helpers in WithColor to print errors, warnings and notes in a few more tools. llvm-svn: 330524
This commit is contained in:
parent
825ead950e
commit
2cd41eb058
|
@ -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<unsigned, PerBlockIDStats> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <system_error>
|
||||
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);
|
||||
|
|
|
@ -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 <cstdlib>
|
||||
|
@ -273,8 +274,8 @@ static bool readLocationInfo(LocationInfoTy &LocationInfo) {
|
|||
ErrorOr<std::unique_ptr<MemoryBuffer>> 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<std::unique_ptr<MemoryBuffer>> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &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<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &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<ELFT>::initSectionHeaders(std::vector<Elf_Shdr> &SHeaders,
|
|||
} else if (auto S = dyn_cast<ELFYAML::Group>(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<ELFT>::addSymbols(const std::vector<ELFYAML::Symbol> &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<ELFT>::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 <class ELFT> bool ELFState<ELFT>::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<ELFT>::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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue