1 /* 2 * Debug.h -- OMP debug 3 */ 4 5 //===----------------------------------------------------------------------===// 6 // 7 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 8 // See https://llvm.org/LICENSE.txt for license information. 9 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include <iostream> 14 #include <ostream> 15 16 #ifndef GDB_DEBUG_H_ 17 #define GDB_DEBUG_H_ 18 19 namespace GdbColor { 20 enum Code { 21 FG_RED = 31, 22 FG_GREEN = 32, 23 FG_BLUE = 34, 24 FG_DEFAULT = 39, 25 BG_RED = 41, 26 BG_GREEN = 42, 27 BG_BLUE = 44, 28 BG_DEFAULT = 49 29 }; 30 inline std::ostream &operator<<(std::ostream &os, Code code) { 31 return os << "\033[" << static_cast<int>(code) << "m"; 32 } 33 } // namespace GdbColor 34 35 class ColorOut { 36 private: 37 std::ostream &out; 38 GdbColor::Code color; 39 40 public: ColorOut(std::ostream & _out,GdbColor::Code _color)41 ColorOut(std::ostream &_out, GdbColor::Code _color) 42 : out(_out), color(_color) {} 43 template <typename T> const ColorOut &operator<<(const T &val) const { 44 out << color << val << GdbColor::FG_DEFAULT; 45 return *this; 46 } 47 const ColorOut &operator<<(std::ostream &(*pf)(std::ostream &)) const { 48 out << color << pf << GdbColor::FG_DEFAULT; 49 return *this; 50 } 51 }; 52 53 static ColorOut dout(std::cout, GdbColor::FG_RED); 54 static ColorOut sout(std::cout, GdbColor::FG_GREEN); 55 static ColorOut hout(std::cout, GdbColor::FG_BLUE); 56 57 #endif /*GDB_DEBUG_H_*/ 58