extensions
Volodymyr Shymanskyy 4 years ago
parent 0c756525db
commit 1b9eddf706

@ -14,7 +14,7 @@
//------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------
#define d_indent " | " #define d_indent " | %s"
// just want less letter and numbers to stare at down the way in the compiler table // just want less letter and numbers to stare at down the way in the compiler table
#define i_32 c_m3Type_i32 #define i_32 c_m3Type_i32
@ -101,8 +101,6 @@ bool IsRegisterLocation (i16 i_location) { return (i_location >= d_m3
bool IsFpRegisterLocation (i16 i_location) { return (i_location == d_m3Fp0SlotAlias); } bool IsFpRegisterLocation (i16 i_location) { return (i_location == d_m3Fp0SlotAlias); }
bool IsIntRegisterLocation (i16 i_location) { return (i_location == d_m3Reg0SlotAlias); } bool IsIntRegisterLocation (i16 i_location) { return (i_location == d_m3Reg0SlotAlias); }
u8 GetBlockType (IM3Compilation o) { return o->block.type; }
bool BlockHasType (IM3Compilation o) { return GetBlockType (o) != c_m3Type_none; }
i16 GetNumBlockValues (IM3Compilation o) { return o->stackIndex - o->block.initStackIndex; } i16 GetNumBlockValues (IM3Compilation o) { return o->stackIndex - o->block.initStackIndex; }
u16 GetTypeNumSlots (u8 i_type) u16 GetTypeNumSlots (u8 i_type)
@ -456,7 +454,7 @@ M3Result Push (IM3Compilation o, u8 i_type, u16 i_location)
} }
} }
m3logif (stack, dump_type_stack (o)) if (d_m3LogWasmStack) dump_type_stack (o);
} }
else result = m3Err_functionStackOverflow; else result = m3Err_functionStackOverflow;
@ -491,8 +489,6 @@ M3Result Pop (IM3Compilation o)
{ {
DeallocateSlot (o, slot, type); DeallocateSlot (o, slot, type);
} }
// m3logif (stack, dump_type_stack (o))
} }
else if (not IsStackPolymorphic (o)) else if (not IsStackPolymorphic (o))
result = m3Err_functionStackUnderrun; result = m3Err_functionStackUnderrun;
@ -919,7 +915,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 ")", get_indention_string (o), value); _ (PushConst (o, value, c_m3Type_i32)); m3log (compile, d_indent " (const i32 = %" PRIi32 ")", get_indention_string (o), value);
_catch: return result; _catch: return result;
} }
@ -930,7 +926,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 ")", get_indention_string (o), value); _ (PushConst (o, value, c_m3Type_i64)); m3log (compile, d_indent " (const i64 = %" PRIi64 ")", get_indention_string (o), value);
_catch: return result; _catch: return result;
} }
@ -942,7 +938,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 " (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;
@ -955,7 +951,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 " (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;
@ -971,7 +967,7 @@ M3Result Compile_ExtendedOpcode (IM3Compilation o, m3opcode_t i_opcode)
i32 value; i32 value;
u8 opcode; u8 opcode;
_ (Read_u8 (& opcode, & o->wasm, o->wasmEnd)); m3log (compile, d_indent "%s (FC: %" PRIi32 ")", get_indention_string (o), opcode); _ (Read_u8 (& opcode, & o->wasm, o->wasmEnd)); m3log (compile, d_indent " (FC: %" PRIi32 ")", get_indention_string (o), opcode);
i_opcode = (i_opcode << 8) | opcode; i_opcode = (i_opcode << 8) | opcode;
@ -995,9 +991,7 @@ M3Result Compile_Return (IM3Compilation o, m3opcode_t i_opcode)
{ {
M3Result result; M3Result result;
bool hasReturn = GetFunctionNumReturns (o->function); if (GetFunctionNumReturns (o->function))
if (hasReturn)
{ {
_ (ReturnStackTop (o)); _ (ReturnStackTop (o));
_ (Pop (o)); _ (Pop (o));
@ -1401,7 +1395,7 @@ _ (ReadLEB_u32 (& functionIndex, & o->wasm, o->wasmEnd));
IM3Function function = Module_GetFunction (o->module, functionIndex); IM3Function function = Module_GetFunction (o->module, functionIndex);
if (function) if (function)
{ m3log (compile, d_indent "%s (func= '%s'; args= %d)", { m3log (compile, d_indent " (func= '%s'; args= %d)",
get_indention_string (o), GetFunctionName (function), function->funcType->numArgs); get_indention_string (o), GetFunctionName (function), function->funcType->numArgs);
if (function->module) if (function->module)
{ {
@ -1504,7 +1498,7 @@ _ (PushRegister (o, c_m3Type_i32));
_catch: return result; _catch: return result;
} }
static
M3Result ReadBlockType (IM3Compilation o, u8 * o_blockType) M3Result ReadBlockType (IM3Compilation o, u8 * o_blockType)
{ {
M3Result result; d_m3Assert (o_blockType); M3Result result; d_m3Assert (o_blockType);
@ -1512,7 +1506,7 @@ M3Result ReadBlockType (IM3Compilation o, u8 * o_blockType)
i8 type; i8 type;
_ (ReadLEB_i7 (& type, & o->wasm, o->wasmEnd)); _ (ReadLEB_i7 (& type, & o->wasm, o->wasmEnd));
_ (NormalizeType (o_blockType, type)); if (* o_blockType) m3log (compile, d_indent "%s (type: %s)", _ (NormalizeType (o_blockType, type)); if (* o_blockType) m3log (compile, d_indent " (type: %s)",
get_indention_string (o), c_waTypes [(u32) * o_blockType]); get_indention_string (o), c_waTypes [(u32) * o_blockType]);
_catch: return result; _catch: return result;
} }
@ -1718,7 +1712,7 @@ _ (PushRegister (o, type));
M3Result Compile_Drop (IM3Compilation o, m3opcode_t i_opcode) M3Result Compile_Drop (IM3Compilation o, m3opcode_t i_opcode)
{ {
M3Result result = Pop (o); m3logif (stack, dump_type_stack (o)) M3Result result = Pop (o); if (d_m3LogWasmStack) dump_type_stack (o);
return result; return result;
} }
@ -1858,7 +1852,7 @@ _try {
_ (ReadLEB_u32 (& alignHint, & o->wasm, o->wasmEnd)); _ (ReadLEB_u32 (& alignHint, & o->wasm, o->wasmEnd));
_ (ReadLEB_u32 (& memoryOffset, & o->wasm, o->wasmEnd)); _ (ReadLEB_u32 (& memoryOffset, & o->wasm, o->wasmEnd));
m3log (compile, d_indent "%s (offset = %d)", get_indention_string (o), memoryOffset); m3log (compile, d_indent " (offset = %d)", get_indention_string (o), memoryOffset);
const M3OpInfo * op = GetOpInfo(i_opcode); const M3OpInfo * op = GetOpInfo(i_opcode);
if (IsFpType (op->type)) if (IsFpType (op->type))
@ -2113,6 +2107,7 @@ const M3OpInfo c_operations [] =
d_m3DebugOp (Entry), d_m3DebugOp (Compile), d_m3DebugOp (End), d_m3DebugOp (Entry), d_m3DebugOp (Compile), d_m3DebugOp (End),
d_m3DebugOp (Unsupported),
d_m3DebugOp (CallRawFunction), d_m3DebugOp (CallRawFunction),
d_m3DebugOp (GetGlobal_s32), d_m3DebugOp (GetGlobal_s64), d_m3DebugOp (ContinueLoop), d_m3DebugOp (ContinueLoopIf), d_m3DebugOp (GetGlobal_s32), d_m3DebugOp (GetGlobal_s64), d_m3DebugOp (ContinueLoop), d_m3DebugOp (ContinueLoopIf),

@ -10,7 +10,7 @@
#include "m3_core.h" #include "m3_core.h"
void m3Abort(const char* message) { void m3_Abort(const char* message) {
#if d_m3LogOutput #if d_m3LogOutput
fprintf(stderr, "Error: %s\n", message); fprintf(stderr, "Error: %s\n", message);
#endif #endif

@ -65,12 +65,6 @@ typedef m3slot_t * m3stack_t;
typedef typedef
const void * const cvptr_t; const void * const cvptr_t;
# define d_m3Log_parse d_m3LogParse // required for m3logif
# define d_m3Log_stack d_m3LogWasmStack
# define d_m3Log_runtime d_m3LogRuntime
# define d_m3Log_exec d_m3LogExec
# define d_m3Log_emit d_m3LogEmit
# if d_m3LogOutput && defined (DEBUG) # if d_m3LogOutput && defined (DEBUG)
# define d_m3Log(CATEGORY, FMT, ...) printf (" %8s | " FMT, #CATEGORY, ##__VA_ARGS__); # define d_m3Log(CATEGORY, FMT, ...) printf (" %8s | " FMT, #CATEGORY, ##__VA_ARGS__);
@ -124,10 +118,9 @@ const void * const cvptr_t;
# endif # endif
# define m3log(CATEGORY, FMT, ...) m3log_##CATEGORY (CATEGORY, FMT "\n", ##__VA_ARGS__) # define m3log(CATEGORY, FMT, ...) m3log_##CATEGORY (CATEGORY, FMT "\n", ##__VA_ARGS__)
# define m3logif(CATEGORY, STATEMENT) m3log_##CATEGORY (CATEGORY, ""); if (d_m3Log_##CATEGORY) { STATEMENT; printf ("\n"); }
# else # else
# define d_m3Log(CATEGORY, FMT, ...) {}
# define m3log(CATEGORY, FMT, ...) {} # define m3log(CATEGORY, FMT, ...) {}
# define m3logif(CATEGORY, STATEMENT) {}
# endif # endif
@ -207,8 +200,7 @@ size_t m3StackGetMax ();
#define m3StackGetMax() 0 #define m3StackGetMax() 0
#endif #endif
void m3Abort (const char* message); void m3_Abort (const char* message);
M3Result m3_Malloc (void ** o_ptr, size_t i_size); M3Result m3_Malloc (void ** o_ptr, size_t i_size);
M3Result m3_Realloc (void ** io_ptr, size_t i_newSize, size_t i_oldSize); M3Result m3_Realloc (void ** io_ptr, size_t i_newSize, size_t i_oldSize);
void m3_Free (void ** io_ptr); void m3_Free (void ** io_ptr);

@ -61,7 +61,7 @@ M3Result EmitOp (IM3Compilation o, IM3Operation i_operation)
result = BridgeToNewPageIfNecessary (o); result = BridgeToNewPageIfNecessary (o);
if (not result) if (not result)
{ m3logif (emit, log_emit (o, i_operation)) { if (d_m3LogEmit) log_emit (o, i_operation);
EmitWord (o->page, i_operation); EmitWord (o->page, i_operation);
} }
} }

@ -800,7 +800,7 @@ _ ((M3Result) Call (i_function->compiled, (m3stack_t) stack, runtime->memo
#if d_m3LogNativeStack #if d_m3LogNativeStack
size_t stackUsed = m3StackGetMax(); size_t stackUsed = m3StackGetMax();
fprintf (stderr, "Native stack used: %d\n", stackUsed); fprintf (stderr, "Native stack used: %zu\n", stackUsed);
#endif // d_m3LogNativeStack #endif // d_m3LogNativeStack
#endif // d_m3LogOutput #endif // d_m3LogOutput

@ -430,7 +430,7 @@ void ProfileHit (cstr_t i_operationName)
{ {
if (slot->opName != i_operationName) if (slot->opName != i_operationName)
{ {
m3Abort ("profiler slot collision; increase d_m3ProfilerSlotMask"); m3_Abort ("profiler slot collision; increase d_m3ProfilerSlotMask");
} }
} }

@ -660,6 +660,10 @@ d_m3Op (Const64)
nextOp (); nextOp ();
} }
d_m3Op (Unsupported)
{ m3log (exec, "*** unsupported ***");
return "unsupported instruction executed";
}
d_m3Op (Unreachable) d_m3Op (Unreachable)
{ m3log (exec, "*** trapping ***"); { m3log (exec, "*** trapping ***");

@ -319,7 +319,7 @@ void dump_type_stack (IM3Compilation o)
{ {
/* Reminders about how the stack works! :) /* Reminders about how the stack works! :)
-- args & locals remain on the type stack for duration of the function. Denoted with a constant 'A' and 'L' in this dump. -- args & locals remain on the type stack for duration of the function. Denoted with a constant 'A' and 'L' in this dump.
-- the intial stack dumps originate from the CompileLocals () function, so these identifiers won't/can't be -- the initial stack dumps originate from the CompileLocals () function, so these identifiers won't/can't be
applied until this compilation stage is finished applied until this compilation stage is finished
-- constants are not statically represented in the type stack (like args & constants) since they don't have/need -- constants are not statically represented in the type stack (like args & constants) since they don't have/need
write counts write counts
@ -336,6 +336,7 @@ void dump_type_stack (IM3Compilation o)
i32 regAllocated [2] = { (i32) IsRegisterAllocated (o, 0), (i32) IsRegisterAllocated (o, 1) }; i32 regAllocated [2] = { (i32) IsRegisterAllocated (o, 0), (i32) IsRegisterAllocated (o, 1) };
// display whether r0 or fp0 is allocated. these should then also be reflected somewhere in the stack too. // display whether r0 or fp0 is allocated. these should then also be reflected somewhere in the stack too.
d_m3Log(stack, "");
printf (" "); printf (" ");
printf ("%s %s ", regAllocated [0] ? "(r0)" : " ", regAllocated [1] ? "(fp0)" : " "); printf ("%s %s ", regAllocated [0] ? "(r0)" : " ", regAllocated [1] ? "(fp0)" : " ");
@ -369,6 +370,7 @@ void dump_type_stack (IM3Compilation o)
printf (" "); printf (" ");
} }
printf ("\n");
for (u32 r = 0; r < 2; ++r) for (u32 r = 0; r < 2; ++r)
d_m3Assert (regAllocated [r] == 0); // reg allocation & stack out of sync d_m3Assert (regAllocated [r] == 0); // reg allocation & stack out of sync
@ -433,11 +435,12 @@ void log_emit (IM3Compilation o, IM3Operation i_operation)
# ifdef DEBUG # ifdef DEBUG
OpInfo i = find_operation_info (i_operation); OpInfo i = find_operation_info (i_operation);
d_m3Log(emit, "");
if (i.info) if (i.info)
{ {
printf ("%p: %s", GetPC (o), i.info->name); printf ("%p: %s\n", GetPC (o), i.info->name);
} }
else printf ("not found: %p", i_operation); else printf ("not found: %p\n", i_operation);
# endif # endif
} }

Loading…
Cancel
Save