From 4c19660109617c34a4b755ab2ab7f3002ea498b2 Mon Sep 17 00:00:00 2001 From: Steven Massey Date: Thu, 15 Apr 2021 15:14:54 -0700 Subject: [PATCH] merge from 'multivalue' --- source/m3_compile.c | 8 ++++++-- source/m3_core.h | 3 ++- source/m3_env.c | 4 ++-- source/m3_exception.h | 8 ++------ source/m3_info.c | 26 +++++++++++++++++++++----- test/internal/m3_test.c | 34 +++++++++++++++++++++++++++++++++- 6 files changed, 66 insertions(+), 17 deletions(-) diff --git a/source/m3_compile.c b/source/m3_compile.c index eaeba33..a02f338 100644 --- a/source/m3_compile.c +++ b/source/m3_compile.c @@ -110,6 +110,10 @@ i16 GetStackTopIndex (IM3Compilation o) return o->stackIndex - 1; } +u16 GetStackHeight (IM3Compilation o) +{ + return o->stackIndex - o->stackFirstDynamicIndex; +} u8 GetStackTopTypeAtOffset (IM3Compilation o, u16 i_offset) { @@ -2177,8 +2181,8 @@ const M3OpInfo c_operations [] = d_m3DebugOp (GetGlobal_s32), d_m3DebugOp (GetGlobal_s64), d_m3DebugOp (ContinueLoop), d_m3DebugOp (ContinueLoopIf), - d_m3DebugOp (CopySlot_32), d_m3DebugOp (PreserveCopySlot_32), d_m3DebugOp (BranchIfPrologue_s), - d_m3DebugOp (CopySlot_64), d_m3DebugOp (PreserveCopySlot_64), d_m3DebugOp (BranchIfPrologue_r), + d_m3DebugOp (CopySlot_32), d_m3DebugOp (PreserveCopySlot_32), d_m3DebugOp (If_s), d_m3DebugOp (BranchIfPrologue_s), + d_m3DebugOp (CopySlot_64), d_m3DebugOp (PreserveCopySlot_64), d_m3DebugOp (If_r), d_m3DebugOp (BranchIfPrologue_r), d_m3DebugOp (Select_i32_rss), d_m3DebugOp (Select_i32_srs), d_m3DebugOp (Select_i32_ssr), d_m3DebugOp (Select_i32_sss), d_m3DebugOp (Select_i64_rss), d_m3DebugOp (Select_i64_srs), d_m3DebugOp (Select_i64_ssr), d_m3DebugOp (Select_i64_sss), diff --git a/source/m3_core.h b/source/m3_core.h index fdf0754..5853c2f 100644 --- a/source/m3_core.h +++ b/source/m3_core.h @@ -240,7 +240,8 @@ M3Result ReadLEB_i32 (i32 * o_value, bytes_t * io_bytes, cbytes_t M3Result ReadLEB_i64 (i64 * o_value, bytes_t * io_bytes, cbytes_t i_end); M3Result Read_utf8 (cstr_t * o_utf8, bytes_t * io_bytes, cbytes_t i_end); -size_t SPrintArg (char * o_string, size_t i_n, m3stack_t i_sp, u8 i_type); +cstr_t SPrintValue (void * i_value, u8 i_type); +size_t SPrintArg (char * o_string, size_t i_stringBufferSize, m3stack_t i_sp, u8 i_type); void ReportError (IM3Runtime io_runtime, IM3Module i_module, IM3Function i_function, ccstr_t i_errorMessage, ccstr_t i_file, u32 i_lineNum); diff --git a/source/m3_env.c b/source/m3_env.c index d201d60..d648c2c 100644 --- a/source/m3_env.c +++ b/source/m3_env.c @@ -291,8 +291,8 @@ M3Result EvaluateExpression (IM3Module i_module, void * o_expressed, u8 i_type m3ret_t r = Call (m3code, stack, NULL, d_m3OpDefaultArgs); if (r == 0) - { - if (SizeOfType (i_type) == sizeof (u32)) + { m3log (runtime, "expression result: %s", SPrintValue (stack, i_type)); + if (SizeOfType (i_type) == sizeof (u32)) { * (u32 *) o_expressed = * ((u32 *) stack); } diff --git a/source/m3_exception.h b/source/m3_exception.h index 34f002c..fa49e4e 100644 --- a/source/m3_exception.h +++ b/source/m3_exception.h @@ -13,12 +13,8 @@ # if d_m3EnableExceptionBreakpoint -// a central function you can be breakpoint: -static void ExceptionBreakpoint (cstr_t i_exception, cstr_t i_message) -{ - printf ("\nexception: '%s' @ %s\n", i_exception, i_message); - return; -} +// declared in m3_info.c +void ExceptionBreakpoint (cstr_t i_exception, cstr_t i_message); # define EXCEPTION_PRINT(ERROR) ExceptionBreakpoint (ERROR, (__FILE__ ":" M3_STR(__LINE__))) diff --git a/source/m3_info.c b/source/m3_info.c index 56cc40a..b746f02 100644 --- a/source/m3_info.c +++ b/source/m3_info.c @@ -13,6 +13,14 @@ #ifdef DEBUG +// a central function you can be breakpoint: +void ExceptionBreakpoint (cstr_t i_exception, cstr_t i_message) +{ + printf ("\nexception: '%s' @ %s\n", i_exception, i_message); + return; +} + + typedef struct OpInfo { IM3OpInfo info; @@ -89,21 +97,21 @@ cstr_t SPrintFuncTypeSignature (IM3FuncType i_funcType) } -size_t SPrintArg (char * o_string, size_t i_n, m3stack_t i_sp, u8 i_type) +size_t SPrintArg (char * o_string, size_t i_stringBufferSize, m3stack_t i_sp, u8 i_type) { int len = 0; * o_string = 0; if (i_type == c_m3Type_i32) - len = snprintf (o_string, i_n, "%" PRIi32, * (i32 *) i_sp); + len = snprintf (o_string, i_stringBufferSize, "%" PRIi32, * (i32 *) i_sp); else if (i_type == c_m3Type_i64) - len = snprintf (o_string, i_n, "%" PRIi64, * (i64 *) i_sp); + len = snprintf (o_string, i_stringBufferSize, "%" PRIi64, * (i64 *) i_sp); #if d_m3HasFloat else if (i_type == c_m3Type_f32) - len = snprintf (o_string, i_n, "%" PRIf32, * (f32 *) i_sp); + len = snprintf (o_string, i_stringBufferSize, "%" PRIf32, * (f32 *) i_sp); else if (i_type == c_m3Type_f64) - len = snprintf (o_string, i_n, "%" PRIf64, * (f64 *) i_sp); + len = snprintf (o_string, i_stringBufferSize, "%" PRIf64, * (f64 *) i_sp); #endif len = M3_MAX (0, len); @@ -112,6 +120,14 @@ size_t SPrintArg (char * o_string, size_t i_n, m3stack_t i_sp, u8 i_type) } +cstr_t SPrintValue (void * i_value, u8 i_type) +{ + static char string [100]; + SPrintArg (string, 100, (m3stack_t) i_value, i_type); + return string; +} + + cstr_t SPrintFunctionArgList (IM3Function i_function, m3stack_t i_sp) { int ret; diff --git a/test/internal/m3_test.c b/test/internal/m3_test.c index 222dee4..40787c5 100644 --- a/test/internal/m3_test.c +++ b/test/internal/m3_test.c @@ -222,10 +222,42 @@ int main (int argc, const char * argv []) i32 ret0 = 0; f32 ret1 = 0.; - m3_GetResultsV (function, & ret0, & ret1); + m3_GetResultsV (function, & ret0, & ret1); + + printf ("%d %f\n", ret0, ret1); } + } + Test (multireturn.branch) + { +# if 0 + (module + (func (param i32) (result i32 i32) + + i32.const 123 + i32.const 456 + i32.const 789 + + block (param i32 i32) (result i32 i32 i32) + + local.get 0 + local.get 0 + + local.get 0 + br_if 0 + + drop + + end + + drop + drop + ) + + (export "main" (func 0)) + ) +# endif } return 0;