From 2113505d5a51d20f9d58ad688d5ecfe8577c8012 Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Thu, 16 Apr 2020 18:46:33 +0300 Subject: [PATCH] Logging improvements --- source/m3_compile.c | 14 ++++++-------- source/m3_config.h | 5 +++++ source/m3_env.h | 2 +- source/m3_exec.c | 6 ++---- source/m3_info.c | 20 +++++++------------- 5 files changed, 21 insertions(+), 26 deletions(-) diff --git a/source/m3_compile.c b/source/m3_compile.c index 70eede1..7b92e98 100644 --- a/source/m3_compile.c +++ b/source/m3_compile.c @@ -168,7 +168,7 @@ bool IsStackTopInSlot (IM3Compilation o) u16 GetStackTopSlotIndex (IM3Compilation o) { - i16 i = GetStackTopIndex (o); d_m3Assert (i >= 0 or IsStackPolymorphic (o)); + i16 i = GetStackTopIndex (o); u16 slot = c_slotUnused; @@ -540,7 +540,7 @@ M3Result PushConst (IM3Compilation o, u64 i_word, u8 i_type) { if (IsSlotAllocated (o, slot) and IsSlotAllocated (o, slot + 1)) { - u64 * constant = (u64 *) & o->constants [slot - o->firstConstSlotIndex]; + m3slot_t * constant = & o->constants [slot - o->firstConstSlotIndex]; if (* constant == i_word) { @@ -874,8 +874,7 @@ M3Result Compile_Const_i32 (IM3Compilation o, m3opcode_t i_opcode) i32 value; _ (ReadLEB_i32 (& value, & o->wasm, o->wasmEnd)); -_ (PushConst (o, value, c_m3Type_i32)); m3log (compile, d_indent "%s (const i32 = %" PRIi32 "; slot: %d)", - get_indention_string (o), value, GetStackTopSlotIndex (o)); +_ (PushConst (o, value, c_m3Type_i32)); m3log (compile, d_indent "%s (const i32 = %" PRIi32 ")", get_indention_string (o), value); _catch: return result; } @@ -886,8 +885,7 @@ M3Result Compile_Const_i64 (IM3Compilation o, m3opcode_t i_opcode) i64 value; _ (ReadLEB_i64 (& value, & o->wasm, o->wasmEnd)); -_ (PushConst (o, value, c_m3Type_i64)); m3log (compile, d_indent "%s (const i64 = %" PRIi64 "; slot: %d)", - get_indention_string (o), value, GetStackTopSlotIndex (o)); +_ (PushConst (o, value, c_m3Type_i64)); m3log (compile, d_indent "%s (const i64 = %" PRIi64 ")", get_indention_string (o), value); _catch: return result; } @@ -898,7 +896,7 @@ M3Result Compile_Const_f32 (IM3Compilation o, m3opcode_t i_opcode) union { u32 u; f32 f; } value = { 0 }; -_ (Read_f32 (& value.f, & o->wasm, o->wasmEnd)); m3log (compile, d_indent "%s (const f32 = %f)", get_indention_string (o), value.f); +_ (Read_f32 (& value.f, & o->wasm, o->wasmEnd)); m3log (compile, d_indent "%s (const f32 = %f)", get_indention_string (o), value.f); _ (PushConst (o, value.u, c_m3Type_f32)); _catch: return result; @@ -911,7 +909,7 @@ M3Result Compile_Const_f64 (IM3Compilation o, m3opcode_t i_opcode) union { u64 u; f64 f; } value = { 0 }; -_ (Read_f64 (& value.f, & o->wasm, o->wasmEnd)); m3log (compile, d_indent "%s (const f64 = %lf)", get_indention_string (o), value.f); +_ (Read_f64 (& value.f, & o->wasm, o->wasmEnd)); m3log (compile, d_indent "%s (const f64 = %lf)", get_indention_string (o), value.f); _ (PushConst (o, value.u, c_m3Type_f64)); _catch: return result; diff --git a/source/m3_config.h b/source/m3_config.h index ac32814..c22ca17 100644 --- a/source/m3_config.h +++ b/source/m3_config.h @@ -10,6 +10,8 @@ #include "m3_config_platforms.h" +// general -------------------------------------------------------------------- + # ifndef d_m3CodePageAlignSize # define d_m3CodePageAlignSize 4096 # endif @@ -51,6 +53,9 @@ # endif // logging -------------------------------------------------------------------- +// d_m3LogsDefined allows setting logging options through the compiler flags, +// i.e. -DDEBUG -Dd_m3LogsDefined -Dd_m3EnableOpTracing=1 + #ifndef d_m3LogsDefined # define d_m3EnableOpProfiling 0 // profiling or tracing can be used diff --git a/source/m3_env.h b/source/m3_env.h index 5ccafda..0ab6d9a 100644 --- a/source/m3_env.h +++ b/source/m3_env.h @@ -249,7 +249,7 @@ typedef struct M3Runtime u32 memoryLimit; M3ErrorInfo error; -#if defined(d_m3VerboseLogs) +#if d_m3VerboseLogs char error_message[256]; #endif i32 exit_code; diff --git a/source/m3_exec.c b/source/m3_exec.c index 2159600..a02709b 100644 --- a/source/m3_exec.c +++ b/source/m3_exec.c @@ -416,17 +416,15 @@ d_m3OpDef (DumpStack) printf (" %4d ", opcodeIndex); printf (" %-25s r0: 0x%016" PRIx64 " i:%" PRIi64 " u:%" PRIu64 "\n", funcName, _r0, _r0, _r0); - printf (" fp0: %lf \n", _fp0); + printf (" fp0: %lf\n", _fp0); m3stack_t sp = _sp; for (u32 i = 0; i < stackHeight; ++i) { - printf ("%016llx ", (u64) sp); - cstr_t kind = ""; - printf ("%5s %2d: 0x%" PRIx64 " %" PRIi64 "\n", kind, i, (u64) *(sp), (i64) *sp); + printf ("%p %5s %2d: 0x%" PRIx64 " i:%" PRIi64 "\n", sp, kind, i, (u64) *(sp), (i64) *(sp)); ++sp; } diff --git a/source/m3_info.c b/source/m3_info.c index 7049a79..22a4207 100644 --- a/source/m3_info.c +++ b/source/m3_info.c @@ -373,9 +373,9 @@ void dump_type_stack (IM3Compilation o) } -const char * GetOpcodeIndentionString (IM3Compilation o) +static const char * GetOpcodeIndentionString (i32 blockDepth) { - i32 blockDepth = o->block.depth + 1; + blockDepth += 1; if (blockDepth < 0) blockDepth = 0; @@ -392,27 +392,21 @@ const char * GetOpcodeIndentionString (IM3Compilation o) const char * get_indention_string (IM3Compilation o) { - o->block.depth += 4; - const char *indent = GetOpcodeIndentionString (o); - o->block.depth -= 4; - - return indent; + return GetOpcodeIndentionString (o->block.depth+4); } void log_opcode (IM3Compilation o, u8 i_opcode) { + i32 depth = o->block.depth; if (i_opcode == c_waOp_end or i_opcode == c_waOp_else) - o->block.depth--; + depth--; # ifdef DEBUG - m3log (compile, "%4d | 0x%02x %s %s", o->numOpcodes++, i_opcode, GetOpcodeIndentionString (o), c_operations [i_opcode].name); + m3log (compile, "%4d | 0x%02x %s %s", o->numOpcodes++, i_opcode, GetOpcodeIndentionString (depth), c_operations [i_opcode].name); # else - m3log (compile, "%4d | 0x%02x %s", o->numOpcodes++, i_opcode, GetOpcodeIndentionString (o)); + m3log (compile, "%4d | 0x%02x %s", o->numOpcodes++, i_opcode, GetOpcodeIndentionString (depth)); # endif - - if (i_opcode == c_waOp_end or i_opcode == c_waOp_else) - o->block.depth++; }