X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FDebug.cpp;h=a09cddf9022a5fc2086465ce8504c44b28749b92;hb=73b43b9b549a75fb0015c825df68abd95705a67c;hp=f1713429497fd5635f2b83f0f9a78a4857d4860e;hpb=2cdd21c2e4d855500dfb53f77aa74da53ccf9de6;p=oota-llvm.git diff --git a/lib/Support/Debug.cpp b/lib/Support/Debug.cpp index f1713429497..a09cddf9022 100644 --- a/lib/Support/Debug.cpp +++ b/lib/Support/Debug.cpp @@ -1,10 +1,10 @@ //===-- Debug.cpp - An easy way to add debug output to your code ----------===// -// +// // The LLVM Compiler Infrastructure // -// This file was developed by the LLVM research group and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. -// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// //===----------------------------------------------------------------------===// // // This file implements a handle way of adding debugging information to your @@ -23,8 +23,8 @@ // //===----------------------------------------------------------------------===// -#include "Support/Debug.h" -#include "Support/CommandLine.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Debug.h" using namespace llvm; bool llvm::DebugFlag; // DebugFlag - Exported boolean set by the -debug option @@ -33,19 +33,19 @@ namespace { #ifndef NDEBUG // -debug - Command line option to enable the DEBUG statements in the passes. // This flag may only be enabled in debug builds. - cl::opt + static cl::opt Debug("debug", cl::desc("Enable debug output"), cl::Hidden, cl::location(DebugFlag)); - std::string CurrentDebugType; - struct DebugOnlyOpt { + static std::string CurrentDebugType; + static struct DebugOnlyOpt { void operator=(const std::string &Val) const { DebugFlag |= !Val.empty(); CurrentDebugType = Val; } } DebugOnlyOptLoc; - cl::opt > + static cl::opt > DebugOnly("debug-only", cl::desc("Enable a specific type of debug output"), cl::Hidden, cl::value_desc("debug string"), cl::location(DebugOnlyOptLoc), cl::ValueRequired); @@ -63,3 +63,15 @@ bool llvm::isCurrentDebugType(const char *DebugType) { 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. +// +OStream &llvm::getErrorOutputStream(const char *DebugType) { + static OStream cnoout(0); + if (DebugFlag && isCurrentDebugType(DebugType)) + return cerr; + else + return cnoout; +}