From adba7ff4823a6cda8e79facea241b030690860b2 Mon Sep 17 00:00:00 2001 From: Steven Massey Date: Thu, 5 Dec 2019 14:26:18 -0800 Subject: [PATCH] int.select fix --- source/m3_compile.c | 5 ++--- source/m3_compile.h | 1 + source/m3_exec.c | 8 ++++---- source/m3_info.c | 30 ++++++++++++++++++++++++++++-- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/source/m3_compile.c b/source/m3_compile.c index c214f68..5c60ac5 100644 --- a/source/m3_compile.c +++ b/source/m3_compile.c @@ -1212,7 +1212,7 @@ _ (Pop (o)); _ (PreserveRegisterIfOccupied (o, type)); } - EmitOp (o, selectOps [type] [opIndex]); + EmitOp (o, selectOps [type - 1] [opIndex]); for (u32 i = 0; i < 3; i++) { @@ -1355,7 +1355,7 @@ const M3OpInfo c_operations [] = M3OP( "br_if", -1, none, d_emptyOpList(), Compile_Branch ), // 0x0d M3OP( "br_table", -1, none, d_singleOp (op_BranchTable), Compile_BranchTable ), // 0x0e M3OP( "return", 0, any, d_emptyOpList(), Compile_Return ), // 0x0f - M3OP( "call", 0, any, d_emptyOpList(), Compile_Call ), // 0x10 + M3OP( "call", 0, any, d_singleOp (op_Call), Compile_Call ), // 0x10 M3OP( "call_indirect", 0, any, d_emptyOpList(), Compile_CallIndirect ), // 0x11 M3OP( "return_call", 0, any, d_emptyOpList(), Compile_Call ), // 0x12 TODO: Optimize M3OP( "return_call_indirect",0, any, d_emptyOpList(), Compile_CallIndirect ), // 0x13 @@ -1558,7 +1558,6 @@ const M3OpInfo c_operations [] = M3OP( "Entry", 0, none, op_Entry ), M3OP( "unreachable", 0, none, op_Unreachable ), - M3OP( "Call", 0, none, op_Call), M3OP( "Compile", 0, none, op_Compile), M3OP( "SetGlobal_s", 0, none, op_SetGlobal_s), diff --git a/source/m3_compile.h b/source/m3_compile.h index faeaef7..97e0663 100644 --- a/source/m3_compile.h +++ b/source/m3_compile.h @@ -35,6 +35,7 @@ enum c_waOp_branch = 0x0c, c_waOp_branchTable = 0x0e, c_waOp_branchIf = 0x0d, + c_waOp_call = 0x10, c_waOp_getLocal = 0x20, c_waOp_setLocal = 0x21, c_waOp_teeLocal = 0x22, diff --git a/source/m3_exec.c b/source/m3_exec.c index d877e2b..32c57f0 100644 --- a/source/m3_exec.c +++ b/source/m3_exec.c @@ -38,10 +38,10 @@ d_m3OpDef (Call) m3ret_t r = Call (callPC, sp, _mem, d_m3OpDefaultArgs); - if (r != 0) + if (r == 0) + return nextOp (); + else return r; - - return nextOp (); } @@ -175,7 +175,7 @@ d_m3OpDef (Compile) d_m3OpDef (Entry) { IM3Function function = immediate (IM3Function); - function->hits++; m3log (exec, " enter > %s %s", function->name, SPrintFunctionArgList (function, _sp)); + function->hits++; m3log (exec, " enter %p > %s %s", _pc - 2, function->name, SPrintFunctionArgList (function, _sp)); u32 numLocals = function->numLocals; diff --git a/source/m3_info.c b/source/m3_info.c index 8e0cff0..1b611d5 100644 --- a/source/m3_info.c +++ b/source/m3_info.c @@ -160,12 +160,32 @@ OpInfo FindOperationInfo (IM3Operation i_operation) } +#define fetch2(TYPE) (*(TYPE *) ((*o_pc)++)) + +void Decode_Call (char * o_string, u8 i_opcode, IM3OpInfo i_opInfo, pc_t * o_pc) +{ + void * function = fetch2 (void *); + u16 stackOffset = fetch2 (u16); + + sprintf (o_string, "%p; stack-offset: %d", function, stackOffset); +} + + +void Decode_Entry (char * o_string, u8 i_opcode, IM3OpInfo i_opInfo, pc_t * o_pc) +{ + IM3Function function = fetch2 (IM3Function); + + sprintf (o_string, "%s", function->name); +} + + +#undef fetch +#define fetch(TYPE) (*(TYPE *) (pc++)) + void DecodeOperation (char * o_string, u8 i_opcode, IM3OpInfo i_opInfo, pc_t * o_pc) { pc_t pc = * o_pc; - #undef fetch - #define fetch(TYPE) (*(TYPE *) (pc++)) i32 offset; @@ -191,6 +211,12 @@ void DecodeOperation (char * o_string, u8 i_opcode, IM3OpInfo i_opInfo, pc_t * u64 value = fetch (u64); offset = fetch (i32); sprintf (o_string, " slot [%d] = %" PRIu64, offset, value); } + else if (i_opcode == 0xc1) // entry + { + Decode_Entry (o_string, i_opcode, i_opInfo, o_pc); + } + else if (i_opcode == c_waOp_call) + Decode_Call (o_string, i_opcode, i_opInfo, o_pc); #undef fetch