aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Support/Debug.h
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2006-11-17 00:49:12 +0000
committerBill Wendling <isanbard@gmail.com>2006-11-17 00:49:12 +0000
commit1ea783f13a83ce9402f543fbc2367d125dc26f91 (patch)
tree3bde233e2cdf48097b3d860b2d6e3f1d1f83dff9 /include/llvm/Support/Debug.h
parente28a12a3b8d42543bb291d5aacf0b65a95dd3653 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31798 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/Debug.h')
-rw-r--r--include/llvm/Support/Debug.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/include/llvm/Support/Debug.h b/include/llvm/Support/Debug.h
index 472364ba2f..f14da843d7 100644
--- a/include/llvm/Support/Debug.h
+++ b/include/llvm/Support/Debug.h
@@ -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 @@ bool isCurrentDebugType(const char *Type);
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