76
76
#include " llvm/Support/Path.h"
77
77
#include " llvm/Support/TargetRegistry.h"
78
78
#include " llvm/Support/ToolOutputFile.h"
79
+ #include " llvm/Support/WithColor.h"
79
80
#include " llvm/Support/raw_ostream.h"
80
81
#include " llvm/Target/TargetMachine.h"
81
82
#include " llvm/Target/TargetOptions.h"
@@ -564,8 +565,32 @@ static bool inFunctionScope(CompileUnit &U, unsigned Idx) {
564
565
return false ;
565
566
}
566
567
568
+ static raw_ostream &error_ostream () {
569
+ return WithColor (errs (), HighlightColor::Error).get () << " error: " ;
570
+ }
571
+
572
+ static raw_ostream &warn_ostream () {
573
+ return WithColor (errs (), HighlightColor::Warning).get () << " warning: " ;
574
+ }
575
+
576
+ static raw_ostream ¬e_ostream () {
577
+ return WithColor (errs (), HighlightColor::Note).get () << " note: " ;
578
+ }
567
579
} // end anonymous namespace
568
580
581
+ void warn (Twine Warning, Twine Context) {
582
+ warn_ostream () << Warning + " \n " ;
583
+ if (!Context.isTriviallyEmpty ())
584
+ note_ostream () << Twine (" while processing " ) + Context + " :\n " ;
585
+ }
586
+
587
+ bool error (Twine Error, Twine Context) {
588
+ error_ostream () << Error + " \n " ;
589
+ if (!Context.isTriviallyEmpty ())
590
+ note_ostream () << Twine (" while processing " ) + Context + " :\n " ;
591
+ return false ;
592
+ }
593
+
569
594
void CompileUnit::markEverythingAsKept () {
570
595
unsigned Idx = 0 ;
571
596
@@ -2092,7 +2117,7 @@ void DwarfLinker::reportWarning(const Twine &Warning,
2092
2117
DumpOpts.RecurseDepth = 0 ;
2093
2118
DumpOpts.Verbose = Options.Verbose ;
2094
2119
2095
- errs () << " in DIE:\n " ;
2120
+ note_ostream () << " in DIE:\n " ;
2096
2121
DIE->dump (errs (), 6 /* Indent */ , DumpOpts);
2097
2122
}
2098
2123
@@ -3882,9 +3907,9 @@ Error DwarfLinker::loadClangModule(StringRef Filename, StringRef ModulePath,
3882
3907
// cache has expired and was pruned by clang. A more adventurous
3883
3908
// dsymutil would invoke clang to rebuild the module now.
3884
3909
if (!ModuleCacheHintDisplayed) {
3885
- errs () << " note: The clang module cache may have expired since this "
3886
- " object file was built. Rebuilding the object file will "
3887
- " rebuild the module cache.\n " ;
3910
+ note_ostream () << " The clang module cache may have expired since "
3911
+ " this object file was built. Rebuilding the "
3912
+ " object file will rebuild the module cache.\n " ;
3888
3913
ModuleCacheHintDisplayed = true ;
3889
3914
}
3890
3915
} else if (isArchive) {
@@ -3893,11 +3918,12 @@ Error DwarfLinker::loadClangModule(StringRef Filename, StringRef ModulePath,
3893
3918
// was built on a different machine. We don't want to discourage module
3894
3919
// debugging for convenience libraries within a project though.
3895
3920
if (!ArchiveHintDisplayed) {
3896
- errs () << " note: Linking a static library that was built with "
3897
- " -gmodules, but the module cache was not found. "
3898
- " Redistributable static libraries should never be built "
3899
- " with module debugging enabled. The debug experience will "
3900
- " be degraded due to incomplete debug information.\n " ;
3921
+ note_ostream () << " Linking a static library that was built with "
3922
+ " -gmodules, but the module cache was not found. "
3923
+ " Redistributable static libraries should never be "
3924
+ " built with module debugging enabled. The debug "
3925
+ " experience will be degraded due to incomplete "
3926
+ " debug information.\n " ;
3901
3927
ArchiveHintDisplayed = true ;
3902
3928
}
3903
3929
}
@@ -3921,7 +3947,7 @@ Error DwarfLinker::loadClangModule(StringRef Filename, StringRef ModulePath,
3921
3947
(Filename +
3922
3948
" : Clang modules are expected to have exactly 1 compile unit.\n " )
3923
3949
.str ();
3924
- errs () << Err;
3950
+ error ( Err) ;
3925
3951
return make_error<StringError>(Err, inconvertibleErrorCode ());
3926
3952
}
3927
3953
// FIXME: Until PR27449 (https://llvm.org/bugs/show_bug.cgi?id=27449) is
@@ -4034,15 +4060,16 @@ bool DwarfLinker::link(const DebugMap &Map) {
4034
4060
continue ;
4035
4061
}
4036
4062
sys::fs::file_status Stat;
4037
- if (auto errc = sys::fs::status (File, Stat)) {
4038
- errs () << " Warning: " << errc .message () << " \n " ;
4063
+ if (auto Err = sys::fs::status (File, Stat)) {
4064
+ warn (Err .message ()) ;
4039
4065
continue ;
4040
4066
}
4041
4067
if (!Options.NoTimestamp && Stat.getLastModificationTime () !=
4042
4068
sys::TimePoint<>(Obj->getTimestamp ())) {
4043
- errs () << " Warning: Timestamp mismatch for " << File << " : "
4044
- << Stat.getLastModificationTime () << " and "
4045
- << sys::TimePoint<>(Obj->getTimestamp ()) << " \n " ;
4069
+ // Not using the helper here as we can easily stream TimePoint<>.
4070
+ warn_ostream () << " Timestamp mismatch for " << File << " : "
4071
+ << Stat.getLastModificationTime () << " and "
4072
+ << sys::TimePoint<>(Obj->getTimestamp ()) << " \n " ;
4046
4073
continue ;
4047
4074
}
4048
4075
0 commit comments