diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-21 14:06:54 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-21 14:06:54 +0000 |
| commit | 899c2af576124df2918fd2ae976434df0ebbae5b (patch) | |
| tree | bb67a979eca30a6d447c2819576b81dc84741f17 /tools/driver/NativeCompiler.cc | |
| parent | b4ffb2d9498560557821714e2d4651279dd6817c (diff) | |
feat(driver): color diagnostics like gcc with -fdiagnostics-color
Add -fdiagnostics-color[=auto|always|never] and -fno-diagnostics-color.
The default auto mode colors only a terminal stderr (TERM set and not
dumb on Unix; a console that accepts VT sequences on Windows), so test
harnesses, the desktop bundle and other pipes stay plain.
Every diagnostic label now comes from cps::diagnosticPrefix, which emits
gcc's default GCC_COLORS bytes: bold locus, bold red error/fatal error,
bold magenta warning, bold cyan note. compilation terminated., runtime
messages of the compiled program and lld output are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tools/driver/NativeCompiler.cc')
| -rw-r--r-- | tools/driver/NativeCompiler.cc | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/tools/driver/NativeCompiler.cc b/tools/driver/NativeCompiler.cc index e09fe98..324785f 100644 --- a/tools/driver/NativeCompiler.cc +++ b/tools/driver/NativeCompiler.cc @@ -1,5 +1,6 @@ #include "NativeCompiler.h" #include "cps/CodeGen.h" +#include "cps/Diagnostics.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticOptions.h" #include "clang/Driver/Compilation.h" @@ -48,7 +49,7 @@ struct TemporaryDirectory { }; bool fail(const llvm::Twine &Message) { - llvm::errs() << "cpsc: fatal error: " << Message << "\n"; + llvm::errs() << cps::diagnosticPrefix(cps::Severity::Fatal) << Message << "\n"; return false; } @@ -58,8 +59,10 @@ class DriverDiagnostics : public clang::DiagnosticConsumer { clang::DiagnosticConsumer::HandleDiagnostic(Level, Info); llvm::SmallString<256> Message; Info.FormatDiagnostic(Message); - llvm::errs() << "cpsc: " << (Level >= clang::DiagnosticsEngine::Error - ? "error: " : "warning: ") << Message << "\n"; + llvm::errs() << cps::diagnosticPrefix(Level >= clang::DiagnosticsEngine::Error + ? cps::Severity::Error + : cps::Severity::Warning) + << Message << "\n"; } }; |
