llvm.org GIT mirror llvm / ae6875e
[tools] Use WithColor for printing errors. Use convenience helpers in WithColor to print errors, warnings and notes in a few more tools. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330524 91177308-0d34-0410-b5e6-96231b3b80d8 Jonas Devlieghere 1 year, 3 months ago
4 changed file(s) with 33 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
3636 #include "llvm/Support/ManagedStatic.h"
3737 #include "llvm/Support/MemoryBuffer.h"
3838 #include "llvm/Support/SHA1.h"
39 #include "llvm/Support/WithColor.h"
3940 #include "llvm/Support/raw_ostream.h"
4041 using namespace llvm;
4142
443444 /// ReportError - All bitcode analysis errors go through this function, making this a
444445 /// good place to breakpoint if debugging.
445446 static bool ReportError(const Twine &Err) {
446 errs() << Err << "\n";
447 WithColor::error() << Err << "\n";
447448 return true;
448449 }
449450
3131 #include "llvm/Support/InitLLVM.h"
3232 #include "llvm/Support/MemoryBuffer.h"
3333 #include "llvm/Support/ToolOutputFile.h"
34 #include "llvm/Support/WithColor.h"
3435 #include
3536 using namespace llvm;
3637
126127 raw_ostream &OS = errs();
127128 OS << Prefix << ": ";
128129 switch (DI.getSeverity()) {
129 case DS_Error: OS << "error: "; break;
130 case DS_Warning: OS << "warning: "; break;
130 case DS_Error: WithColor::error(OS); break;
131 case DS_Warning: WithColor::warning(OS); break;
131132 case DS_Remark: OS << "remark: "; break;
132 case DS_Note: OS << "note: "; break;
133 case DS_Note: WithColor::note(OS); break;
133134 }
134135
135136 DiagnosticPrinterRawOStream DP(OS);
2424 #include "llvm/Support/MemoryBuffer.h"
2525 #include "llvm/Support/Path.h"
2626 #include "llvm/Support/Program.h"
27 #include "llvm/Support/WithColor.h"
2728 #include "llvm/Support/YAMLTraits.h"
2829 #include "llvm/Support/raw_ostream.h"
2930 #include
272273 ErrorOr> Buf =
273274 MemoryBuffer::getFileOrSTDIN(InputFileName);
274275 if (std::error_code EC = Buf.getError()) {
275 errs() << "error: Can't open file " << InputFileName << ": " <<
276 EC.message() << "\n";
276 WithColor::error() << "Can't open file " << InputFileName << ": "
277 << EC.message() << "\n";
277278 return false;
278279 }
279280
281282 yaml::Stream Stream(Buf.get()->getBuffer(), SM);
282283 collectLocationInfo(Stream, LocationInfo);
283284
284 return true;
285 return true;
285286 }
286287
287288 static bool writeReport(LocationInfoTy &LocationInfo) {
289290 llvm::raw_fd_ostream OS(OutputFileName, EC,
290291 llvm::sys::fs::F_Text);
291292 if (EC) {
292 errs() << "error: Can't open file " << OutputFileName << ": " <<
293 EC.message() << "\n";
293 WithColor::error() << "Can't open file " << OutputFileName << ": "
294 << EC.message() << "\n";
294295 return false;
295296 }
296297
299300 SmallString<128> FileName(FI.first);
300301 if (!InputRelDir.empty()) {
301302 if (std::error_code EC = sys::fs::make_absolute(InputRelDir, FileName)) {
302 errs() << "error: Can't resolve file path to " << FileName << ": " <<
303 EC.message() << "\n";
303 WithColor::error() << "Can't resolve file path to " << FileName << ": "
304 << EC.message() << "\n";
304305 return false;
305306 }
306307 }
310311 ErrorOr> Buf =
311312 MemoryBuffer::getFile(FileName);
312313 if (std::error_code EC = Buf.getError()) {
313 errs() << "error: Can't open file " << FileName << ": " <<
314 EC.message() << "\n";
314 WithColor::error() << "Can't open file " << FileName << ": "
315 << EC.message() << "\n";
315316 return false;
316317 }
317318
395396
396397 if (!Printed)
397398 OS << FuncName;
398 }
399 }
399400
400401 OS << ":\n";
401402 }
521522 if (!readLocationInfo(LocationInfo))
522523 return 1;
523524 if (!writeReport(LocationInfo))
524 return 1;
525 return 1;
525526
526527 return 0;
527528 }
528
1818 #include "llvm/Object/ELFObjectFile.h"
1919 #include "llvm/ObjectYAML/ELFYAML.h"
2020 #include "llvm/Support/MemoryBuffer.h"
21 #include "llvm/Support/WithColor.h"
2122 #include "llvm/Support/YAMLTraits.h"
2223 #include "llvm/Support/raw_ostream.h"
2324
242243 if (!Sec->Link.empty()) {
243244 unsigned Index;
244245 if (SN2I.lookup(Sec->Link, Index)) {
245 errs() << "error: Unknown section referenced: '" << Sec->Link
246 << "' at YAML section '" << Sec->Name << "'.\n";
246 WithColor::error() << "Unknown section referenced: '" << Sec->Link
247 << "' at YAML section '" << Sec->Name << "'.\n";
247248 return false;
248249 }
249250 SHeader.sh_link = Index;
259260 unsigned Index;
260261 if (SN2I.lookup(S->Info, Index)) {
261262 if (S->Info.getAsInteger(0, Index)) {
262 errs() << "error: Unknown section referenced: '" << S->Info
263 << "' at YAML section '" << S->Name << "'.\n";
263 WithColor::error() << "Unknown section referenced: '" << S->Info
264 << "' at YAML section '" << S->Name << "'.\n";
264265 return false;
265266 }
266267 }
271272 } else if (auto S = dyn_cast(Sec.get())) {
272273 unsigned SymIdx;
273274 if (SymN2I.lookup(S->Info, SymIdx)) {
274 errs() << "error: Unknown symbol referenced: '" << S->Info
275 << "' at YAML section '" << S->Name << "'.\n";
275 WithColor::error() << "Unknown symbol referenced: '" << S->Info
276 << "' at YAML section '" << S->Name << "'.\n";
276277 return false;
277278 }
278279 SHeader.sh_info = SymIdx;
429430 if (!Sym.Section.empty()) {
430431 unsigned Index;
431432 if (SN2I.lookup(Sym.Section, Index)) {
432 errs() << "error: Unknown section referenced: '" << Sym.Section
433 << "' by YAML symbol " << Sym.Name << ".\n";
433 WithColor::error() << "Unknown section referenced: '" << Sym.Section
434 << "' by YAML symbol " << Sym.Name << ".\n";
434435 exit(1);
435436 }
436437 Symbol.st_shndx = Index;
527528 if (member.sectionNameOrType == "GRP_COMDAT")
528529 sectionIndex = llvm::ELF::GRP_COMDAT;
529530 else if (SN2I.lookup(member.sectionNameOrType, sectionIndex)) {
530 errs() << "error: Unknown section referenced: '"
531 << member.sectionNameOrType << "' at YAML section' "
532 << Section.Name << "\n";
531 WithColor::error() << "Unknown section referenced: '"
532 << member.sectionNameOrType << "' at YAML section' "
533 << Section.Name << "\n";
533534 return false;
534535 }
535536 SIdx = sectionIndex;
573574 DotShStrtab.add(Name);
574575 // "+ 1" to take into account the SHT_NULL entry.
575576 if (SN2I.addName(Name, i + 1)) {
576 errs() << "error: Repeated section name: '" << Name
577 << "' at YAML section number " << i << ".\n";
577 WithColor::error() << "Repeated section name: '" << Name
578 << "' at YAML section number " << i << ".\n";
578579 return false;
579580 }
580581 }
601602 if (Sym.Name.empty())
602603 continue;
603604 if (SymN2I.addName(Sym.Name, StartIndex)) {
604 errs() << "error: Repeated symbol name: '" << Sym.Name << "'.\n";
605 WithColor::error() << "Repeated symbol name: '" << Sym.Name << "'.\n";
605606 return false;
606607 }
607608 }