Logging improvements

extensions
Volodymyr Shymanskyy 4 years ago
parent 0f7162568c
commit 2113505d5a

@ -168,7 +168,7 @@ bool IsStackTopInSlot (IM3Compilation o)
u16 GetStackTopSlotIndex (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; 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)) 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) if (* constant == i_word)
{ {
@ -874,8 +874,7 @@ M3Result Compile_Const_i32 (IM3Compilation o, m3opcode_t i_opcode)
i32 value; i32 value;
_ (ReadLEB_i32 (& value, & o->wasm, o->wasmEnd)); _ (ReadLEB_i32 (& value, & o->wasm, o->wasmEnd));
_ (PushConst (o, value, c_m3Type_i32)); m3log (compile, d_indent "%s (const i32 = %" PRIi32 "; slot: %d)", _ (PushConst (o, value, c_m3Type_i32)); m3log (compile, d_indent "%s (const i32 = %" PRIi32 ")", get_indention_string (o), value);
get_indention_string (o), value, GetStackTopSlotIndex (o));
_catch: return result; _catch: return result;
} }
@ -886,8 +885,7 @@ M3Result Compile_Const_i64 (IM3Compilation o, m3opcode_t i_opcode)
i64 value; i64 value;
_ (ReadLEB_i64 (& value, & o->wasm, o->wasmEnd)); _ (ReadLEB_i64 (& value, & o->wasm, o->wasmEnd));
_ (PushConst (o, value, c_m3Type_i64)); m3log (compile, d_indent "%s (const i64 = %" PRIi64 "; slot: %d)", _ (PushConst (o, value, c_m3Type_i64)); m3log (compile, d_indent "%s (const i64 = %" PRIi64 ")", get_indention_string (o), value);
get_indention_string (o), value, GetStackTopSlotIndex (o));
_catch: return result; _catch: return result;
} }
@ -898,7 +896,7 @@ M3Result Compile_Const_f32 (IM3Compilation o, m3opcode_t i_opcode)
union { u32 u; f32 f; } value = { 0 }; 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)); _ (PushConst (o, value.u, c_m3Type_f32));
_catch: return result; _catch: return result;
@ -911,7 +909,7 @@ M3Result Compile_Const_f64 (IM3Compilation o, m3opcode_t i_opcode)
union { u64 u; f64 f; } value = { 0 }; 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)); _ (PushConst (o, value.u, c_m3Type_f64));
_catch: return result; _catch: return result;

@ -10,6 +10,8 @@
#include "m3_config_platforms.h" #include "m3_config_platforms.h"
// general --------------------------------------------------------------------
# ifndef d_m3CodePageAlignSize # ifndef d_m3CodePageAlignSize
# define d_m3CodePageAlignSize 4096 # define d_m3CodePageAlignSize 4096
# endif # endif
@ -51,6 +53,9 @@
# endif # endif
// logging -------------------------------------------------------------------- // logging --------------------------------------------------------------------
// d_m3LogsDefined allows setting logging options through the compiler flags,
// i.e. -DDEBUG -Dd_m3LogsDefined -Dd_m3EnableOpTracing=1
#ifndef d_m3LogsDefined #ifndef d_m3LogsDefined
# define d_m3EnableOpProfiling 0 // profiling or tracing can be used # define d_m3EnableOpProfiling 0 // profiling or tracing can be used

@ -249,7 +249,7 @@ typedef struct M3Runtime
u32 memoryLimit; u32 memoryLimit;
M3ErrorInfo error; M3ErrorInfo error;
#if defined(d_m3VerboseLogs) #if d_m3VerboseLogs
char error_message[256]; char error_message[256];
#endif #endif
i32 exit_code; i32 exit_code;

@ -416,17 +416,15 @@ d_m3OpDef (DumpStack)
printf (" %4d ", opcodeIndex); printf (" %4d ", opcodeIndex);
printf (" %-25s r0: 0x%016" PRIx64 " i:%" PRIi64 " u:%" PRIu64 "\n", funcName, _r0, _r0, _r0); 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; m3stack_t sp = _sp;
for (u32 i = 0; i < stackHeight; ++i) for (u32 i = 0; i < stackHeight; ++i)
{ {
printf ("%016llx ", (u64) sp);
cstr_t kind = ""; 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; ++sp;
} }

@ -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) if (blockDepth < 0)
blockDepth = 0; blockDepth = 0;
@ -392,27 +392,21 @@ const char * GetOpcodeIndentionString (IM3Compilation o)
const char * get_indention_string (IM3Compilation o) const char * get_indention_string (IM3Compilation o)
{ {
o->block.depth += 4; return GetOpcodeIndentionString (o->block.depth+4);
const char *indent = GetOpcodeIndentionString (o);
o->block.depth -= 4;
return indent;
} }
void log_opcode (IM3Compilation o, u8 i_opcode) 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) if (i_opcode == c_waOp_end or i_opcode == c_waOp_else)
o->block.depth--; depth--;
# ifdef DEBUG # 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 # 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 # endif
if (i_opcode == c_waOp_end or i_opcode == c_waOp_else)
o->block.depth++;
} }

Loading…
Cancel
Save