summaryrefslogtreecommitdiff
path: root/tools/minicargo/debug.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2017-12-09 14:25:35 +0800
committerJohn Hodge <tpg@ucc.asn.au>2017-12-09 14:25:35 +0800
commit79318f8896fad735225938fc130f3a450565a162 (patch)
treec78505bd238475aa60257a0e154c56b965c77719 /tools/minicargo/debug.cpp
parent73c5e1cebe1a9b0dbd9e98846b5a11a1c75a1be6 (diff)
downloadmrust-79318f8896fad735225938fc130f3a450565a162.tar.gz
minicargo - Cleaner debug
Diffstat (limited to 'tools/minicargo/debug.cpp')
-rw-r--r--tools/minicargo/debug.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/tools/minicargo/debug.cpp b/tools/minicargo/debug.cpp
new file mode 100644
index 00000000..64d80209
--- /dev/null
+++ b/tools/minicargo/debug.cpp
@@ -0,0 +1,60 @@
+/*
+ * MiniCargo - mrustc's minimal clone of cargo
+ * - By John Hodge (Mutabah/thePowersGang)
+ *
+ * debug.cpp
+ * - Debugging helpers
+ */
+#include <set>
+#include <iostream>
+#include "debug.h"
+
+static int giIndentLevel = 0;
+static const char* gsDebugPhase = "";
+static ::std::set<::std::string> gmDisabledDebug;
+void Debug_SetPhase(const char* phase_name)
+{
+ gsDebugPhase = phase_name;
+}
+bool Debug_IsEnabled()
+{
+ if( gmDisabledDebug.find(gsDebugPhase) != gmDisabledDebug.end() )
+ return false;
+ return true;
+}
+void Debug_DisablePhase(const char* phase_name)
+{
+ gmDisabledDebug.insert( ::std::string(phase_name) );
+}
+void Debug_Print(::std::function<void(::std::ostream& os)> cb)
+{
+ if( !Debug_IsEnabled() )
+ return ;
+ ::std::cout << gsDebugPhase << "- ";
+ for(auto i = giIndentLevel; i --; )
+ ::std::cout << " ";
+ cb(::std::cout);
+ ::std::cout << ::std::endl;
+}
+void Debug_EnterScope(const char* name, dbg_cb_t cb)
+{
+ if( !Debug_IsEnabled() )
+ return ;
+ ::std::cout << gsDebugPhase << "- ";
+ for(auto i = giIndentLevel; i --; )
+ ::std::cout << " ";
+ ::std::cout << ">>> " << name << "(";
+ cb(::std::cout);
+ ::std::cout << ")" << ::std::endl;
+ giIndentLevel ++;
+}
+void Debug_LeaveScope(const char* name, dbg_cb_t cb)
+{
+ if( !Debug_IsEnabled() )
+ return ;
+ ::std::cout << gsDebugPhase << "- ";
+ giIndentLevel --;
+ for(auto i = giIndentLevel; i --; )
+ ::std::cout << " ";
+ ::std::cout << "<<< " << name << ::std::endl;
+}