#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
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
#include "llvm/Support/Debug.h"
#include "llvm/Support/CommandLine.h"
+#include <iostream>
using namespace llvm;
bool llvm::DebugFlag; // DebugFlag - Exported boolean set by the -debug option
return false;
#endif
}
+
+// 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 llvm::getErrorOutputStream(const char *DebugType) {
+ if (DebugFlag && isCurrentDebugType(DebugType))
+ return llvm_ostream(std::cerr);
+ else
+ return llvm_ostream();
+}