diff options
-rw-r--r-- | src/debug.cpp | 12 | ||||
-rw-r--r-- | src/hir/deserialise.cpp | 1 | ||||
-rw-r--r-- | src/include/debug.hpp | 26 |
3 files changed, 23 insertions, 16 deletions
diff --git a/src/debug.cpp b/src/debug.cpp index a09fc648..d460c3cb 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -1,23 +1,27 @@ #include <debug.hpp> -TraceLog::TraceLog(const char* tag, ::std::string info, ::std::function<void(::std::ostream&)> ret): +TraceLog::TraceLog(const char* tag, ::std::function<void(::std::ostream&)> info_cb, ::std::function<void(::std::ostream&)> ret): m_tag(tag), m_ret(ret) { if(debug_enabled()) { auto& os = debug_output(g_debug_indent_level, m_tag); - os << ">> (" << info << ")" << ::std::endl; + os << ">> ("; + info_cb(os); + os << ")" << ::std::endl; } INDENT(); } -TraceLog::TraceLog(const char* tag, ::std::string info): +TraceLog::TraceLog(const char* tag, ::std::function<void(::std::ostream&)> info_cb): m_tag(tag), m_ret([](const auto&){}) { if(debug_enabled()) { auto& os = debug_output(g_debug_indent_level, m_tag); - os << ">> (" << info << ")" << ::std::endl; + os << ">> ("; + info_cb(os); + os << ")" << ::std::endl; } INDENT(); } diff --git a/src/hir/deserialise.cpp b/src/hir/deserialise.cpp index e40788d3..5230703e 100644 --- a/src/hir/deserialise.cpp +++ b/src/hir/deserialise.cpp @@ -5,6 +5,7 @@ * hir/serialise.cpp * - HIR (De)Serialisation for crate metadata */ +#define DISABLE_DEBUG // Disable debug for this function - too hot #include "hir.hpp" #include "main_bindings.hpp" #include <serialiser_texttree.hpp> diff --git a/src/include/debug.hpp b/src/include/debug.hpp index af8dcf10..21de5493 100644 --- a/src/include/debug.hpp +++ b/src/include/debug.hpp @@ -8,13 +8,19 @@ extern int g_debug_indent_level; #ifndef DISABLE_DEBUG -#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 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;}) #else -#define INDENT() do { } while(0) -#define UNINDENT() do {} while(0) -#define DEBUG(ss) do{ (void)(::NullSink() << ss); } while(0) +# define INDENT() do { } while(0) +# define UNINDENT() do {} while(0) +# define DEBUG(ss) do{ (void)(::NullSink() << ss); } while(0) +# define TRACE_FUNCTION do{} while(0) +# define TRACE_FUNCTION_F(ss) do{ (void)(::NullSink() << ss); } while(0) +# define TRACE_FUNCTION_FR(ss,ss2) do{ (void)(::NullSink() << ss); } while(0) #endif extern bool debug_enabled(); @@ -44,8 +50,8 @@ class TraceLog const char* m_tag; ::std::function<void(::std::ostream&)> m_ret; public: - TraceLog(const char* tag, ::std::string info, ::std::function<void(::std::ostream&)> ret); - TraceLog(const char* tag, ::std::string info); + TraceLog(const char* tag, ::std::function<void(::std::ostream&)> info_cb, ::std::function<void(::std::ostream&)> ret); + TraceLog(const char* tag, ::std::function<void(::std::ostream&)> info_cb); TraceLog(const char* tag); ~TraceLog(); }; @@ -60,8 +66,4 @@ struct FmtLambda }; #define FMT_CB(os, ...) ::FmtLambda { [&](auto& os) { __VA_ARGS__ } } -#define TRACE_FUNCTION TraceLog _tf_(__func__) -#define TRACE_FUNCTION_F(ss) TraceLog _tf_(__func__, FMT(ss)) -#define TRACE_FUNCTION_FR(ss,ss2) TraceLog _tf_(__func__, FMT(ss), [&](::std::ostream&__os){ __os << ss2;}) - |