[llvm] [llvm][Support] Support bright colors in raw_ostream (PR #80017)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 30 07:01:47 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-platform-windows

@llvm/pr-subscribers-llvm-support

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/80017.diff


4 Files Affected:

- (modified) llvm/include/llvm/Support/raw_ostream.h (+16) 
- (modified) llvm/lib/Support/Process.cpp (+27-12) 
- (modified) llvm/lib/Support/Unix/Process.inc (+1-1) 
- (modified) llvm/lib/Support/Windows/Process.inc (+1-1) 


``````````diff
diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
index 42663a9adf2e5..696290a5d99cf 100644
--- a/llvm/include/llvm/Support/raw_ostream.h
+++ b/llvm/include/llvm/Support/raw_ostream.h
@@ -102,6 +102,14 @@ class raw_ostream {
     MAGENTA,
     CYAN,
     WHITE,
+    BRIGHT_BLACK,
+    BRIGHT_RED,
+    BRIGHT_GREEN,
+    BRIGHT_YELLOW,
+    BRIGHT_BLUE,
+    BRIGHT_MAGENTA,
+    BRIGHT_CYAN,
+    BRIGHT_WHITE,
     SAVEDCOLOR,
     RESET,
   };
@@ -114,6 +122,14 @@ class raw_ostream {
   static constexpr Colors MAGENTA = Colors::MAGENTA;
   static constexpr Colors CYAN = Colors::CYAN;
   static constexpr Colors WHITE = Colors::WHITE;
+  static constexpr Colors BRIGHT_BLACK = Colors::BRIGHT_BLACK;
+  static constexpr Colors BRIGHT_RED = Colors::BRIGHT_RED;
+  static constexpr Colors BRIGHT_GREEN = Colors::BRIGHT_GREEN;
+  static constexpr Colors BRIGHT_YELLOW = Colors::BRIGHT_YELLOW;
+  static constexpr Colors BRIGHT_BLUE = Colors::BRIGHT_BLUE;
+  static constexpr Colors BRIGHT_MAGENTA = Colors::BRIGHT_MAGENTA;
+  static constexpr Colors BRIGHT_CYAN = Colors::BRIGHT_CYAN;
+  static constexpr Colors BRIGHT_WHITE = Colors::BRIGHT_WHITE;
   static constexpr Colors SAVEDCOLOR = Colors::SAVEDCOLOR;
   static constexpr Colors RESET = Colors::RESET;
 
diff --git a/llvm/lib/Support/Process.cpp b/llvm/lib/Support/Process.cpp
index f81c13970d521..f1ab8c7b9ebd8 100644
--- a/llvm/lib/Support/Process.cpp
+++ b/llvm/lib/Support/Process.cpp
@@ -70,20 +70,35 @@ Process::FindInEnvPath(StringRef EnvName, StringRef FileName,
 
 #define COLOR(FGBG, CODE, BOLD) "\033[0;" BOLD FGBG CODE "m"
 
-#define ALLCOLORS(FGBG,BOLD) {\
-    COLOR(FGBG, "0", BOLD),\
-    COLOR(FGBG, "1", BOLD),\
-    COLOR(FGBG, "2", BOLD),\
-    COLOR(FGBG, "3", BOLD),\
-    COLOR(FGBG, "4", BOLD),\
-    COLOR(FGBG, "5", BOLD),\
-    COLOR(FGBG, "6", BOLD),\
-    COLOR(FGBG, "7", BOLD)\
+#define ALLCOLORS(FGBG, BRIGHT, BOLD) \
+  {                           \
+    COLOR(FGBG, "0", BOLD),   \
+    COLOR(FGBG, "1", BOLD),   \
+    COLOR(FGBG, "2", BOLD),   \
+    COLOR(FGBG, "3", BOLD),   \
+    COLOR(FGBG, "4", BOLD),   \
+    COLOR(FGBG, "5", BOLD),   \
+    COLOR(FGBG, "6", BOLD),   \
+    COLOR(FGBG, "7", BOLD),   \
+    COLOR(BRIGHT, "0", BOLD), \
+    COLOR(BRIGHT, "1", BOLD), \
+    COLOR(BRIGHT, "2", BOLD), \
+    COLOR(BRIGHT, "3", BOLD), \
+    COLOR(BRIGHT, "4", BOLD), \
+    COLOR(BRIGHT, "5", BOLD), \
+    COLOR(BRIGHT, "6", BOLD), \
+    COLOR(BRIGHT, "7", BOLD), \
   }
 
-static const char colorcodes[2][2][8][10] = {
- { ALLCOLORS("3",""), ALLCOLORS("3","1;") },
- { ALLCOLORS("4",""), ALLCOLORS("4","1;") }
+//                           bg
+//                           |  bold
+//                           |  |
+//                           |  |   codes
+//                           |  |   |
+//                           |  |   |
+static const char colorcodes[2][2][16][11] = {
+    { ALLCOLORS("3", "9", ""), ALLCOLORS("3", "9", "1;"),},
+    { ALLCOLORS("4", "10", ""), ALLCOLORS("4", "10", "1;")}
 };
 
 // A CMake option controls wheter we emit core dumps by default. An application
diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index 551f0d7f0f029..f94eec6963c18 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -417,7 +417,7 @@ bool Process::ColorNeedsFlush() {
 }
 
 const char *Process::OutputColor(char code, bool bold, bool bg) {
-  return colorcodes[bg ? 1 : 0][bold ? 1 : 0][code & 7];
+  return colorcodes[bg ? 1 : 0][bold ? 1 : 0][code & 15];
 }
 
 const char *Process::OutputBold(bool bg) { return "\033[1m"; }
diff --git a/llvm/lib/Support/Windows/Process.inc b/llvm/lib/Support/Windows/Process.inc
index a54c06d46870b..6b4b723d4744a 100644
--- a/llvm/lib/Support/Windows/Process.inc
+++ b/llvm/lib/Support/Windows/Process.inc
@@ -376,7 +376,7 @@ const char *Process::OutputBold(bool bg) {
 
 const char *Process::OutputColor(char code, bool bold, bool bg) {
   if (UseANSI)
-    return colorcodes[bg ? 1 : 0][bold ? 1 : 0][code & 7];
+    return colorcodes[bg ? 1 : 0][bold ? 1 : 0][code & 15];
 
   WORD current = DefaultColors::GetCurrentColor();
   WORD colors;

``````````

</details>


https://github.com/llvm/llvm-project/pull/80017


More information about the llvm-commits mailing list