summaryrefslogtreecommitdiffstats
path: root/llvm/tools
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2019-08-02 04:48:30 +0000
committerRui Ueyama <ruiu@google.com>2019-08-02 04:48:30 +0000
commita52f982f1cd98ebf94abb5deb5244f460ddad2d1 (patch)
tree61799d68dd515bda1a6bd6d7b70812e96dbe9ded /llvm/tools
parent9131e925fd6b5010a9e797342a09141306183ed6 (diff)
downloadbcm5719-llvm-a52f982f1cd98ebf94abb5deb5244f460ddad2d1.tar.gz
bcm5719-llvm-a52f982f1cd98ebf94abb5deb5244f460ddad2d1.zip
Improve raw_ostream so that you can "write" colors using operator<<
1. raw_ostream supports ANSI colors so that you can write messages to the termina with colors. Previously, in order to change and reset color, you had to call `changeColor` and `resetColor` functions, respectively. So, if you print out "error: " in red, for example, you had to do something like this: OS.changeColor(raw_ostream::RED); OS << "error: "; OS.resetColor(); With this patch, you can write the same code as follows: OS << raw_ostream::RED << "error: " << raw_ostream::RESET; 2. Add a boolean flag to raw_ostream so that you can disable colored output. If you disable colors, changeColor, operator<<(Color), resetColor and other color-related functions have no effect. Most LLVM tools automatically prints out messages using colors, and you can disable it by passing a flag such as `--disable-colors`. This new flag makes it easy to write code that works that way. Differential Revision: https://reviews.llvm.org/D65564 llvm-svn: 367649
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/llvm-cov/CoverageReport.cpp2
-rw-r--r--llvm/tools/llvm-cov/CoverageViewOptions.h2
-rw-r--r--llvm/tools/llvm-cov/RenderingSupport.h2
-rw-r--r--llvm/tools/llvm-cov/SourceCoverageViewText.cpp2
-rw-r--r--llvm/tools/llvm-cov/llvm-cov.cpp11
-rw-r--r--llvm/tools/llvm-mca/Views/TimelineView.cpp6
6 files changed, 11 insertions, 14 deletions
diff --git a/llvm/tools/llvm-cov/CoverageReport.cpp b/llvm/tools/llvm-cov/CoverageReport.cpp
index 82259542c59..1750d18d4e0 100644
--- a/llvm/tools/llvm-cov/CoverageReport.cpp
+++ b/llvm/tools/llvm-cov/CoverageReport.cpp
@@ -111,7 +111,7 @@ void renderDivider(ArrayRef<size_t> ColumnWidths, raw_ostream &OS) {
/// Return the color which correponds to the coverage percentage of a
/// certain metric.
template <typename T>
-raw_ostream::Colors determineCoveragePercentageColor(const T &Info) {
+raw_ostream::Color determineCoveragePercentageColor(const T &Info) {
if (Info.isFullyCovered())
return raw_ostream::GREEN;
return Info.getPercentCovered() >= 80.0 ? raw_ostream::YELLOW
diff --git a/llvm/tools/llvm-cov/CoverageViewOptions.h b/llvm/tools/llvm-cov/CoverageViewOptions.h
index dde0c692ab0..3dbb0131ddb 100644
--- a/llvm/tools/llvm-cov/CoverageViewOptions.h
+++ b/llvm/tools/llvm-cov/CoverageViewOptions.h
@@ -46,7 +46,7 @@ struct CoverageViewOptions {
/// Change the output's stream color if the colors are enabled.
ColoredRawOstream colored_ostream(raw_ostream &OS,
- raw_ostream::Colors Color) const {
+ raw_ostream::Color Color) const {
return llvm::colored_ostream(OS, Color, Colors);
}
diff --git a/llvm/tools/llvm-cov/RenderingSupport.h b/llvm/tools/llvm-cov/RenderingSupport.h
index 0674fbac9a3..b25792e2c4b 100644
--- a/llvm/tools/llvm-cov/RenderingSupport.h
+++ b/llvm/tools/llvm-cov/RenderingSupport.h
@@ -47,7 +47,7 @@ inline raw_ostream &operator<<(const ColoredRawOstream &OS, T &&Value) {
/// Change the color of the output stream if the `IsColorUsed` flag
/// is true. Returns an object that resets the color when destroyed.
inline ColoredRawOstream colored_ostream(raw_ostream &OS,
- raw_ostream::Colors Color,
+ raw_ostream::Color Color,
bool IsColorUsed = true,
bool Bold = false, bool BG = false) {
if (IsColorUsed)
diff --git a/llvm/tools/llvm-cov/SourceCoverageViewText.cpp b/llvm/tools/llvm-cov/SourceCoverageViewText.cpp
index fcabee2ee69..f73b91a8511 100644
--- a/llvm/tools/llvm-cov/SourceCoverageViewText.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageViewText.cpp
@@ -101,7 +101,7 @@ void SourceCoverageViewText::renderLine(raw_ostream &OS, LineRef L,
auto *WrappedSegment = LCS.getWrappedSegment();
CoverageSegmentArray Segments = LCS.getLineSegments();
- Optional<raw_ostream::Colors> Highlight;
+ Optional<raw_ostream::Color> Highlight;
SmallVector<std::pair<unsigned, unsigned>, 2> HighlightedRanges;
// The first segment overlaps from a previous line, so we treat it specially.
diff --git a/llvm/tools/llvm-cov/llvm-cov.cpp b/llvm/tools/llvm-cov/llvm-cov.cpp
index 172ec9f3ced..dabb8afedc8 100644
--- a/llvm/tools/llvm-cov/llvm-cov.cpp
+++ b/llvm/tools/llvm-cov/llvm-cov.cpp
@@ -83,13 +83,10 @@ int main(int argc, const char **argv) {
}
}
- if (argc > 1) {
- if (sys::Process::StandardErrHasColors())
- errs().changeColor(raw_ostream::RED);
- errs() << "Unrecognized command: " << argv[1] << ".\n\n";
- if (sys::Process::StandardErrHasColors())
- errs().resetColor();
- }
+ if (argc > 1)
+ errs() << raw_ostream::RED << "Unrecognized command: " << argv[1] << ".\n\n"
+ << raw_ostream::RESET;
+
helpMain(argc, argv);
return 1;
}
diff --git a/llvm/tools/llvm-mca/Views/TimelineView.cpp b/llvm/tools/llvm-mca/Views/TimelineView.cpp
index fe3f16ba344..09b6b2a3efe 100644
--- a/llvm/tools/llvm-mca/Views/TimelineView.cpp
+++ b/llvm/tools/llvm-mca/Views/TimelineView.cpp
@@ -103,8 +103,8 @@ void TimelineView::onEvent(const HWInstructionEvent &Event) {
LastCycle = std::max(LastCycle, CurrentCycle);
}
-static raw_ostream::Colors chooseColor(unsigned CumulativeCycles,
- unsigned Executions, int BufferSize) {
+static raw_ostream::Color chooseColor(unsigned CumulativeCycles,
+ unsigned Executions, int BufferSize) {
if (CumulativeCycles && BufferSize < 0)
return raw_ostream::MAGENTA;
unsigned Size = static_cast<unsigned>(BufferSize);
@@ -120,7 +120,7 @@ static void tryChangeColor(raw_ostream &OS, unsigned Cycles,
if (!OS.has_colors())
return;
- raw_ostream::Colors Color = chooseColor(Cycles, Executions, BufferSize);
+ raw_ostream::Color Color = chooseColor(Cycles, Executions, BufferSize);
if (Color == raw_ostream::SAVEDCOLOR) {
OS.resetColor();
return;
OpenPOWER on IntegriCloud