[llvm] 24a8041 - [llvm][Support] Support bright colors in raw_ostream (#80017)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 31 02:14:06 PST 2024


Author: Timm Baeder
Date: 2024-01-31T11:14:02+01:00
New Revision: 24a804101b67676aa9fa7f1097043ddd9e2ac1b6

URL: https://github.com/llvm/llvm-project/commit/24a804101b67676aa9fa7f1097043ddd9e2ac1b6
DIFF: https://github.com/llvm/llvm-project/commit/24a804101b67676aa9fa7f1097043ddd9e2ac1b6.diff

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

Added: 
    

Modified: 
    llvm/include/llvm/Support/raw_ostream.h
    llvm/lib/Support/Process.cpp
    llvm/lib/Support/Unix/Process.inc
    llvm/lib/Support/Windows/Process.inc

Removed: 
    


################################################################################
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..54462f23c8424 100644
--- a/llvm/lib/Support/Process.cpp
+++ b/llvm/lib/Support/Process.cpp
@@ -67,24 +67,40 @@ Process::FindInEnvPath(StringRef EnvName, StringRef FileName,
   return FoundPath;
 }
 
-
+// clang-format off
 #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;")}
 };
+// clang-format on
 
 // A CMake option controls wheter we emit core dumps by default. An application
 // may disable core dumps by calling Process::PreventCoreFiles().

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;


        


More information about the llvm-commits mailing list