diff options
author | John Hodge <tpg@ucc.asn.au> | 2019-06-22 15:46:07 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2019-06-22 15:46:07 +0800 |
commit | 2ac86edf6c9f9aa8559b265c2121581006f09eae (patch) | |
tree | c032e1a0a3a7aa00d440b08d0126396eae7b8f21 /src | |
parent | d896ae84c2a890bcb7b7700dd4b4a69620499642 (diff) | |
download | mrust-2ac86edf6c9f9aa8559b265c2121581006f09eae.tar.gz |
HIR Deserialise - Disable debug output
Diffstat (limited to 'src')
-rw-r--r-- | src/debug.cpp | 8 | ||||
-rw-r--r-- | src/hir/deserialise.cpp | 2 | ||||
-rw-r--r-- | src/include/debug.hpp | 13 |
3 files changed, 15 insertions, 8 deletions
diff --git a/src/debug.cpp b/src/debug.cpp index 43e2795e..8a0d1f3c 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -11,7 +11,7 @@ TraceLog::TraceLog(const char* tag, ::std::function<void(::std::ostream&)> info_ m_tag(tag), m_ret(ret) { - if(debug_enabled()) { + if(debug_enabled() && m_tag) { auto& os = debug_output(g_debug_indent_level, m_tag); os << ">> ("; info_cb(os); @@ -23,7 +23,7 @@ TraceLog::TraceLog(const char* tag, ::std::function<void(::std::ostream&)> info_ m_tag(tag), m_ret([](const auto&){}) { - if(debug_enabled()) { + if(debug_enabled() && m_tag) { auto& os = debug_output(g_debug_indent_level, m_tag); os << ">> ("; info_cb(os); @@ -35,7 +35,7 @@ TraceLog::TraceLog(const char* tag): m_tag(tag), m_ret([](const auto&){}) { - if(debug_enabled()) { + if(debug_enabled() && m_tag) { auto& os = debug_output(g_debug_indent_level, m_tag); os << ">>" << ::std::endl; } @@ -43,7 +43,7 @@ TraceLog::TraceLog(const char* tag): } TraceLog::~TraceLog() { UNINDENT(); - if(debug_enabled()) { + if(debug_enabled() && m_tag) { auto& os = debug_output(g_debug_indent_level, m_tag); os << "<< ("; m_ret(os); diff --git a/src/hir/deserialise.cpp b/src/hir/deserialise.cpp index 9a353986..75e08f16 100644 --- a/src/hir/deserialise.cpp +++ b/src/hir/deserialise.cpp @@ -5,6 +5,8 @@ * hir/serialise.cpp * - HIR (De)Serialisation for crate metadata */ +// TODO: Have an environment variable that controls if debug is enabled here. +#define DEBUG_EXTRA_ENABLE && false //#define DISABLE_DEBUG // Disable debug for this function - too hot #include "hir.hpp" #include "main_bindings.hpp" diff --git a/src/include/debug.hpp b/src/include/debug.hpp index 3f059301..534523c2 100644 --- a/src/include/debug.hpp +++ b/src/include/debug.hpp @@ -14,13 +14,18 @@ extern int g_debug_indent_level; +#ifndef DEBUG_EXTRA_ENABLE +# define DEBUG_EXTRA_ENABLE // Files can override this with their own flag if needed (e.g. `&& g_my_debug_on`) +#endif + #ifndef DISABLE_DEBUG +# define DEBUG_ENABLED (debug_enabled() DEBUG_EXTRA_ENABLE) # define INDENT() do { g_debug_indent_level += 1; assert(g_debug_indent_level<300); } while(0) # define UNINDENT() do { g_debug_indent_level -= 1; } while(0) -# define DEBUG(ss) do{ if(debug_enabled()) { debug_output(g_debug_indent_level, __FUNCTION__) << ss << ::std::endl; } } while(0) -# define TRACE_FUNCTION TraceLog _tf_(__func__) -# define TRACE_FUNCTION_F(ss) TraceLog _tf_(__func__, [&](::std::ostream&__os){ __os << ss; }) -# define TRACE_FUNCTION_FR(ss,ss2) TraceLog _tf_(__func__, [&](::std::ostream&__os){ __os << ss; }, [&](::std::ostream&__os){ __os << ss2;}) +# define DEBUG(ss) do{ if(DEBUG_ENABLED) { debug_output(g_debug_indent_level, __FUNCTION__) << ss << ::std::endl; } } while(0) +# define TRACE_FUNCTION TraceLog _tf_( DEBUG_ENABLED ? __func__ : nullptr) +# define TRACE_FUNCTION_F(ss) TraceLog _tf_(DEBUG_ENABLED ? __func__ : nullptr, [&](::std::ostream&__os){ __os << ss; }) +# define TRACE_FUNCTION_FR(ss,ss2) TraceLog _tf_(DEBUG_ENABLED ? __func__ : nullptr, [&](::std::ostream&__os){ __os << ss; }, [&](::std::ostream&__os){ __os << ss2;}) #else # define INDENT() do { } while(0) # define UNINDENT() do {} while(0) |