[llvm-commits] CVS: llvm/include/llvm/Support/Debug.h

Bill Wendling isanbard at gmail.com
Thu Nov 16 16:49:30 PST 2006



Changes in directory llvm/include/llvm/Support:

Debug.h updated: 1.7 -> 1.8
---
Log message:

Added "DOUT" macro. This is used as a replacement for the std::cerr
stream. It centralizes the use of std::cerr so that static c'tor/d'tors
aren't scattered around all over the place. The way to use it is like this:

       DOUT << "This is a status line: " << Var << "\n";

If "-debug" is specified, it will print. Otherwise, it'll not print. If
NDEBUG is defined, the DOUT does nothing.


---
Diffs of the changes:  (+30 -0)

 Debug.h |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+)


Index: llvm/include/llvm/Support/Debug.h
diff -u llvm/include/llvm/Support/Debug.h:1.7 llvm/include/llvm/Support/Debug.h:1.8
--- llvm/include/llvm/Support/Debug.h:1.7	Sun Jan 22 16:54:51 2006
+++ llvm/include/llvm/Support/Debug.h	Thu Nov 16 18:49:12 2006
@@ -26,6 +26,8 @@
 #ifndef LLVM_SUPPORT_DEBUG_H
 #define LLVM_SUPPORT_DEBUG_H
 
+#include <ostream>              // Doesn't have static d'tors!!
+
 namespace llvm {
 
 // DebugFlag - This boolean is set to true if the '-debug' command line option
@@ -59,6 +61,34 @@
   do { if (DebugFlag && isCurrentDebugType(DEBUG_TYPE)) { X; } } while (0)
 #endif
 
+// llvm_ostream - Acts like an ostream. However, it doesn't print things out if
+// an ostream isn't specified.
+// 
+class llvm_ostream {
+  std::ostream* Stream;
+public:
+  llvm_ostream() : Stream(0) {}
+  llvm_ostream(std::ostream& OStream) : Stream(&OStream) {}
+
+  template <typename Ty>
+  llvm_ostream& operator << (const Ty& Thing) {
+    if (Stream) *Stream << Thing;
+    return *this;
+  }
+};
+
+// getErrorOutputStream - Returns the error output stream (std::cerr). This
+// places the std::c* I/O streams into one .cpp file and relieves the whole
+// program from having to have hundreds of static c'tor/d'tors for them.
+// 
+llvm_ostream getErrorOutputStream(const char *DebugType);
+
+#ifdef NDEBUG
+#define DOUT llvm_ostream()
+#else
+#define DOUT getErrorOutputStream(DEBUG_TYPE)
+#endif
+
 } // End llvm namespace
 
 #endif






More information about the llvm-commits mailing list