From 4e0e4b1f8b56fa2667f3d099986bdf198a2587b8 Mon Sep 17 00:00:00 2001 From: Steven Massey Date: Sun, 1 Dec 2019 12:57:13 -0700 Subject: [PATCH] i32 slot work + misc --- platforms/app/main.c | 7 ++++++- source/m3.h | 2 +- source/m3_compile.c | 30 ++++++++++++++++++++---------- source/m3_env.c | 12 +++++++++--- source/m3_exec.h | 15 +++------------ source/m3_info.c | 7 ++++--- test/run-spec-test.py | 2 +- 7 files changed, 44 insertions(+), 31 deletions(-) diff --git a/platforms/app/main.c b/platforms/app/main.c index 9ddb45f..f850633 100644 --- a/platforms/app/main.c +++ b/platforms/app/main.c @@ -10,8 +10,12 @@ int main (int i_argc, const char * i_argv []) { +// m3_PrintM3Info (); + M3Result result = c_m3Err_none; + IM3Runtime env = NULL; + if (i_argc < 3) FATAL("not enough arguments"); u8* wasm = NULL; @@ -40,7 +44,7 @@ int main (int i_argc, const char * i_argv []) if (result) FATAL("m3_ParseModule: %s", result); // TODO: Detect stack exhaustion - IM3Runtime env = m3_NewRuntime (8*1024); + env = m3_NewRuntime (8*1024); if (!env) FATAL("m3_NewRuntime"); result = m3_LoadModule (env, module); @@ -57,6 +61,7 @@ int main (int i_argc, const char * i_argv []) result = m3_Call (func); if (result) FATAL("__post_instantiate failed: %s", result); } + else m3_IgnoreErrorInfo (env); const char* fname = i_argv[2]; diff --git a/source/m3.h b/source/m3.h index 4405344..99f70e7 100644 --- a/source/m3.h +++ b/source/m3.h @@ -249,8 +249,8 @@ typedef int64_t (* M3Callback) (IM3Function i_currentFunction, void * i_ref); // IM3Functions are valid during the lifetime of the originating runtime - M3ErrorInfo m3_GetErrorInfo (IM3Runtime i_runtime); + void m3_IgnoreErrorInfo (IM3Runtime i_runtime); //-------------------------------------------------------------------------------------------------------------------------------------------- // debug info diff --git a/source/m3_compile.c b/source/m3_compile.c index 91581a2..56ced57 100644 --- a/source/m3_compile.c +++ b/source/m3_compile.c @@ -270,11 +270,11 @@ u16 GetMaxExecSlot (IM3Compilation o) } -M3Result PreserveRegisterIfOccupied (IM3Compilation o, u8 i_type) +M3Result PreserveRegisterIfOccupied (IM3Compilation o, u8 i_registerType) { M3Result result = c_m3Err_none; - u32 regSelect = IsFpType (i_type); + u32 regSelect = IsFpType (i_registerType); if (IsRegisterAllocated (o, regSelect)) { @@ -286,8 +286,10 @@ M3Result PreserveRegisterIfOccupied (IM3Compilation o, u8 i_type) if (AllocateExecSlot (o, & slot)) { o->wasmStack [stackIndex] = slot; + + u8 type = o->typeStack [stackIndex]; -_ (EmitOp (o, regSelect ? op_SetSlot_f64 : op_SetSlot_i64)); +_ (EmitOp (o, c_setSetOps [type])); EmitConstant (o, slot); } else _throw (c_m3Err_functionStackOverflow); @@ -794,6 +796,7 @@ _ (PushAllocatedSlotAndEmit (o, i_global->type)); } +// TODO: enforce mutability M3Result Compile_SetGlobal (IM3Compilation o, M3Global * i_global) { M3Result result = c_m3Err_none; @@ -1511,13 +1514,20 @@ const M3OpInfo c_operations [] = M3OP( "f64.reinterpret/i64", 0, f_64, d_unaryOpList(f64, Reinterpret_i64) ), // 0xbf # ifdef DEBUG // for code logging: - M3OP( "m3.const", 1, any, op_Const ), - M3OP( "m3.entry", 0, none, op_Entry ), - M3OP( "i32.m3.setslot", 0, none, op_SetSlot_i32), - M3OP( "i64.m3.setslot", 0, none, op_SetSlot_i64), - M3OP( "f32.m3.setslot", 0, none, op_SetSlot_f32), - M3OP( "f64.m3.setslot", 0, none, op_SetSlot_f64), - M3OP( "m3.end", 0, none, op_End ), + M3OP( "Const", 1, any, op_Const ), + M3OP( "Entry", 0, none, op_Entry ), + M3OP( "unreachable", 0, none, op_Unreachable ), + M3OP( "br", 0, none, op_Branch ), + M3OP( "br_table", 0, none, op_BranchTable ), + + M3OP( "SetGlobal_s", 0, none, op_SetGlobal_s), + + M3OP( "SetSlot_i32", 0, none, op_SetSlot_i32), + M3OP( "SetSlot_i64", 0, none, op_SetSlot_i64), + M3OP( "SetSlot_f32", 0, none, op_SetSlot_f32), + M3OP( "SetSlot_f64", 0, none, op_SetSlot_f64), + + M3OP( "End", 0, none, op_End ), # endif M3OP( "termination", 0, c_m3Type_void ) // termination for FindOperationInfo () diff --git a/source/m3_env.c b/source/m3_env.c index 1cc1c17..ebee403 100644 --- a/source/m3_env.c +++ b/source/m3_env.c @@ -643,16 +643,22 @@ M3Result m3Error (M3Result i_result, IM3Runtime i_runtime, IM3Module i_module, } #endif + M3ErrorInfo m3_GetErrorInfo (IM3Runtime i_runtime) { M3ErrorInfo info = i_runtime->error; + m3_IgnoreErrorInfo (i_runtime); + + return info; +} + + +void m3_IgnoreErrorInfo (IM3Runtime i_runtime) +{ M3ErrorInfo reset; M3_INIT(reset); i_runtime->error = reset; - - return info; } - diff --git a/source/m3_exec.h b/source/m3_exec.h index a6768c7..2f42cf3 100644 --- a/source/m3_exec.h +++ b/source/m3_exec.h @@ -527,11 +527,7 @@ d_m3Op (End) d_m3Op (GetGlobal) { i64 * global = immediate (i64 *); - -// printf ("get global: %p %" PRIi64 "\n", global, *global); - - i32 offset = immediate (i32); - * (_sp + offset) = * global; + slot (i64) = * global; // printf ("get global: %p %" PRIi64 "\n", global, *global); return nextOp (); } @@ -540,8 +536,7 @@ d_m3Op (GetGlobal) d_m3Op (SetGlobal_s) { i64 * global = immediate (i64 *); - i32 offset = immediate (i32); - * global = * (_sp + offset); + * global = slot (i64); return nextOp (); } @@ -550,9 +545,7 @@ d_m3Op (SetGlobal_s) d_m3Op (SetGlobal_i) { i64 * global = immediate (i64 *); - * global = _r0; - -// printf ("set global: %p %" PRIi64 "\n", global, _r0); + * global = _r0; // printf ("set global: %p %" PRIi64 "\n", global, _r0); return nextOp (); } @@ -600,8 +593,6 @@ d_m3Op (PreserveCopySlot) } - - //d_m3Op (SwapRegister_i) //{ // slot (u64) = _r0; diff --git a/source/m3_info.c b/source/m3_info.c index db6b184..0a5a25c 100644 --- a/source/m3_info.c +++ b/source/m3_info.c @@ -187,6 +187,8 @@ void DecodeOperation (char * o_string, u8 i_opcode, IM3OpInfo i_opInfo, pc_t * } +// WARNING/TODO: this isn't fully implemented. it blindly assumes each word is a Operation pointer +// and, if an operation happens to missing from the c_operations table it won't be recognized here void DumpCodePage (IM3CodePage i_codePage, pc_t i_startPC) { # if defined (DEBUG) && d_m3LogCodePages @@ -196,9 +198,8 @@ void DumpCodePage (IM3CodePage i_codePage, pc_t i_startPC) pc_t pc = i_startPC ? i_startPC : GetPageStartPC (i_codePage); pc_t end = GetPagePC (i_codePage); - m3log (code, "---------------------------------------------------"); + m3log (code, "---------------------------------------------------------------------------------------"); - // TODO: this isn't fully implemented. blindly assumes each word is a Operation pointer while (pc < end) { IM3Operation op = (IM3Operation) (* pc++); @@ -219,7 +220,7 @@ void DumpCodePage (IM3CodePage i_codePage, pc_t i_startPC) // else break; } - m3log (code, "---------------------------------------------------"); + m3log (code, "---------------------------------------------------------------------------------------"); # endif } diff --git a/test/run-spec-test.py b/test/run-spec-test.py index 4edfbc2..89581c3 100755 --- a/test/run-spec-test.py +++ b/test/run-spec-test.py @@ -308,9 +308,9 @@ else: "forward", "func_ptrs", "endianness", + "int_literals", #--- Almost ready --- - #"int_literals", -> stack underflow #"memory_trap", "address", -> init memory size + track memory bounds #"float_memory", #"memory_redundancy", "memory_grow",