From aaacae58fd3a2ff54f77cb72706f19121f328b39 Mon Sep 17 00:00:00 2001 From: Steven Massey Date: Wed, 21 Apr 2021 16:06:28 -0700 Subject: [PATCH] cleanup --- source/m3_compile.c | 37 +++++++++++-------------------------- source/m3_function.h | 7 ++----- source/m3_module.c | 4 ++-- 3 files changed, 15 insertions(+), 33 deletions(-) diff --git a/source/m3_compile.c b/source/m3_compile.c index 11bba8a..e090e0b 100644 --- a/source/m3_compile.c +++ b/source/m3_compile.c @@ -466,7 +466,7 @@ M3Result Push (IM3Compilation o, u8 i_type, u16 i_slot) AllocateRegister (o, regSelect, stackIndex); } - if (d_m3LogWasmStack) dump_type_stack (o); + if (d_m3LogWasmStack) dump_type_stack (o); } else result = m3Err_functionStackOverflow; @@ -1063,7 +1063,7 @@ _ (Pop (o)); } } - _catch: return result; + _catch: return result; } @@ -1751,8 +1751,7 @@ M3Result Compile_LoopOrBlock (IM3Compilation o, m3opcode_t i_opcode) { M3Result result; - // TODO: don't think these shouldn't be necessary for non-loop block - + // TODO: these shouldn't be necessary for non-loop blocks? _ (PreserveRegisters (o)); _ (PreserveArgsAndLocals (o)); @@ -2516,7 +2515,7 @@ _ (PushBlockResults (o)); M3Result CompileBlock (IM3Compilation o, IM3FuncType i_blockType, m3opcode_t i_blockOpcode) { - M3Result result; d_m3Assert (not IsRegisterAllocated (o, 0)); + M3Result result = m3Err_none; d_m3Assert (not IsRegisterAllocated (o, 0)); d_m3Assert (not IsRegisterAllocated (o, 1)); M3CompilationScope outerScope = o->block; M3CompilationScope * block = & o->block; @@ -2528,6 +2527,7 @@ M3Result CompileBlock (IM3Compilation o, IM3FuncType i_blockType, m3opcode_t i block->depth ++; block->opcode = i_blockOpcode; +_try { // validate and dealloc params ---------------------------- u16 stackIndex = o->stackIndex; @@ -2588,35 +2588,20 @@ _ (ValidateBlockEnd (o)); if (o->function) // skip for expressions { - if (IsStackPolymorphic (o)) -_ (UnwindBlockStack (o)) - else + if (not IsStackPolymorphic (o)) _ (ResolveBlockResults (o, & o->block, /* isBranch: */ false)); - if (o->previousOpcode == c_waOp_else) - { -_ (UnwindBlockStack (o)) -// o->stackIndex = o->block.exitStackIndex; - } - else - { -_ (UnwindBlockStack (o)); - - if (i_blockOpcode == c_waOp_if and numResults) - { -//_ (UnwindBlockStack (o)) -// o->stackIndex = o->block.exitStackIndex; - } - else -_ (CommitBlockResults (o)); - } +_ (UnwindBlockStack (o)) + + if (not ((i_blockOpcode == c_waOp_if and numResults) or o->previousOpcode == c_waOp_else)) +_ (CommitBlockResults (o)); } PatchBranches (o); o->block = outerScope; - _catch: return result; +} _catch: return result; } diff --git a/source/m3_function.h b/source/m3_function.h index 7173b8b..c4b2504 100644 --- a/source/m3_function.h +++ b/source/m3_function.h @@ -59,13 +59,10 @@ typedef struct M3Function u32 numCodePageRefs; #endif -#if defined(DEBUG) +#if defined (DEBUG) u32 hits; -#endif - -# if d_m3LogCompile u32 index; -# endif +#endif u16 maxStackSlots; diff --git a/source/m3_module.c b/source/m3_module.c index 0286409..d21b09e 100644 --- a/source/m3_module.c +++ b/source/m3_module.c @@ -81,9 +81,9 @@ _try { IM3Function func = Module_GetFunction (io_module, index); func->funcType = ft; -# if d_m3LogCompile +# ifdef DEBUG func->index = index; -# endif +# endif if (i_importInfo and func->numNames == 0) {