From: Brendan Hansen Date: Mon, 15 Feb 2021 22:49:54 +0000 (-0600) Subject: abstracted pointer operations in WASM generation X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=b98ccfac2f901eb353f24c0d03e6718b135301bb;p=onyx.git abstracted pointer operations in WASM generation --- diff --git a/bin/onyx b/bin/onyx index 979752ea..277b9852 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/include/onyxwasm.h b/include/onyxwasm.h index 2bd9816b..2c81d93b 100644 --- a/include/onyxwasm.h +++ b/include/onyxwasm.h @@ -224,7 +224,15 @@ typedef enum WasmInstructionType { WI_I64_EXTEND_16_S = 0xC3, WI_I64_EXTEND_32_S = 0xC4, - + // Pointer stuff; this will make it easier to switch to 64-bit + // pointers, whenever WebAssembly standarizes that. + WI_PTR_CONST = WI_I32_CONST, + WI_PTR_LOAD = WI_I32_LOAD, + WI_PTR_STORE = WI_I32_STORE, + WI_PTR_ADD = WI_I32_ADD, + WI_PTR_SUB = WI_I32_SUB, + WI_PTR_MUL = WI_I32_MUL, + WI_PTR_GE = WI_I32_GE_U, WI_V128_LOAD = SIMD_INSTR_MASK | 0, WI_V128_STORE = SIMD_INSTR_MASK | 11, diff --git a/misc/onyx.vim b/misc/onyx.vim index 119dbf8d..6fe43732 100644 --- a/misc/onyx.vim +++ b/misc/onyx.vim @@ -38,7 +38,7 @@ syn keyword onyxCommentStart contained TODO NOTE BUG HACK syn region onyxComment start="//" end="$" keepend contains=onyxCommentStart syn region onyxComment start="/\*" end="\*/" contains=onyxCommentStart -syn match onyxDefinitionGroup "\<[a-zA-Z_][a-zA-Z0-9_]*\> *:" contains=onyxDefinition +syn match onyxDefinitionGroup "\<[a-zA-Z_][a-zA-Z0-9_]*\> *::" contains=onyxDefinition syn match onyxDefinition "\<[a-zA-Z_][a-zA-Z0-9_]*\>" contained syn match onyxCallGroup "\<[a-zA-Z_][a-zA-Z0-9_\.]*\> *(" contains=onyxCall diff --git a/src/onyxwasm.c b/src/onyxwasm.c index a55cf9c5..e19f1a3d 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -2,22 +2,13 @@ #include "onyxwasm.h" #include "onyxutils.h" -// NOTE: Allows easier testing of types since most of the characters -// corresponding to these values are not printable -#if 1 #define WASM_TYPE_INT32 0x7F #define WASM_TYPE_INT64 0x7E #define WASM_TYPE_FLOAT32 0x7D #define WASM_TYPE_FLOAT64 0x7C #define WASM_TYPE_VAR128 0x7B +#define WASM_TYPE_PTR WASM_TYPE_INT32 #define WASM_TYPE_VOID 0x00 -#else -#define WASM_TYPE_INT32 'A' -#define WASM_TYPE_INT64 'B' -#define WASM_TYPE_FLOAT32 'C' -#define WASM_TYPE_FLOAT64 'D' -#define WASM_TYPE_VOID 'E' -#endif static WasmType onyx_type_to_wasm_type(Type* type) { if (type->kind == Type_Kind_Struct) { @@ -33,11 +24,11 @@ static WasmType onyx_type_to_wasm_type(Type* type) { } if (type->kind == Type_Kind_Pointer) { - return WASM_TYPE_INT32; + return WASM_TYPE_PTR; } if (type->kind == Type_Kind_Array) { - return WASM_TYPE_INT32; + return WASM_TYPE_PTR; } if (type->kind == Type_Kind_Function) { @@ -451,8 +442,7 @@ EMIT_FUNC(assignment_of_array, AstTyped* left, AstTyped* right) { } u32 elem_size = type_size_of(elem_type); - // :32BitPointers - u64 lptr_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); + u64 lptr_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_PTR); emit_location(mod, &code, left); WIL(WI_LOCAL_SET, lptr_local); @@ -464,7 +454,7 @@ EMIT_FUNC(assignment_of_array, AstTyped* left, AstTyped* right) { emit_store_instruction(mod, &code, elem_type, i * elem_size); } - local_raw_free(mod->local_alloc, WASM_TYPE_INT32); + local_raw_free(mod->local_alloc, WASM_TYPE_PTR); } else { u64 offset = 0; @@ -566,9 +556,8 @@ EMIT_FUNC(load_instruction, Type* type, u32 offset) { if (type->kind == Type_Kind_Array) { if (offset != 0) { - // :32BitPointers - WID(WI_I32_CONST, offset); - WI(WI_I32_ADD); + WID(WI_PTR_CONST, offset); + WI(WI_PTR_ADD); } *pcode = code; @@ -758,12 +747,12 @@ EMIT_FUNC(for_array, AstFor* for_node, u64 iter_local) { bh_arr(WasmInstruction) code = *pcode; u64 end_ptr_local, ptr_local; - end_ptr_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); + end_ptr_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_PTR); if (for_node->by_pointer) { ptr_local = iter_local; } else { - ptr_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); + ptr_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_PTR); } AstLocal* var = for_node->var; @@ -774,20 +763,18 @@ EMIT_FUNC(for_array, AstFor* for_node, u64 iter_local) { if (for_node->by_pointer) elem_size = type_size_of(var->type->Pointer.elem); else elem_size = type_size_of(var->type); - // :32BitPointers WIL(WI_LOCAL_TEE, ptr_local); - WIL(WI_I32_CONST, for_node->iter->type->Array.count * elem_size); - WI(WI_I32_ADD); + WIL(WI_PTR_CONST, for_node->iter->type->Array.count * elem_size); + WI(WI_PTR_ADD); WIL(WI_LOCAL_SET, end_ptr_local); emit_enter_structured_block(mod, &code, SBT_Breakable_Block); emit_enter_structured_block(mod, &code, SBT_Basic_Loop); emit_enter_structured_block(mod, &code, SBT_Continue_Block); - // :32BitPointers WIL(WI_LOCAL_GET, ptr_local); WIL(WI_LOCAL_GET, end_ptr_local); - WI(WI_I32_GE_U); + WI(WI_PTR_GE); WID(WI_COND_JUMP, 0x02); if (!for_node->by_pointer) { @@ -804,10 +791,9 @@ EMIT_FUNC(for_array, AstFor* for_node, u64 iter_local) { emit_leave_structured_block(mod, &code); - // :32BitPointers WIL(WI_LOCAL_GET, ptr_local); - WIL(WI_I32_CONST, elem_size); - WI(WI_I32_ADD); + WIL(WI_PTR_CONST, elem_size); + WI(WI_PTR_ADD); WIL(WI_LOCAL_SET, ptr_local); if (bh_arr_last(code).type != WI_JUMP) @@ -816,8 +802,8 @@ EMIT_FUNC(for_array, AstFor* for_node, u64 iter_local) { emit_leave_structured_block(mod, &code); emit_leave_structured_block(mod, &code); - local_raw_free(mod->local_alloc, WASM_TYPE_INT32); - if (!for_node->by_pointer) local_raw_free(mod->local_alloc, WASM_TYPE_INT32); + local_raw_free(mod->local_alloc, WASM_TYPE_PTR); + if (!for_node->by_pointer) local_raw_free(mod->local_alloc, WASM_TYPE_PTR); *pcode = code; } @@ -826,12 +812,12 @@ EMIT_FUNC(for_slice, AstFor* for_node, u64 iter_local) { bh_arr(WasmInstruction) code = *pcode; u64 end_ptr_local, ptr_local; - end_ptr_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); + end_ptr_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_PTR); if (for_node->by_pointer) { ptr_local = iter_local; } else { - ptr_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); + ptr_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_PTR); } AstLocal* var = for_node->var; @@ -842,25 +828,23 @@ EMIT_FUNC(for_slice, AstFor* for_node, u64 iter_local) { if (for_node->by_pointer) elem_size = type_size_of(var->type->Pointer.elem); else elem_size = type_size_of(var->type); - // :32BitPointers WIL(WI_LOCAL_SET, end_ptr_local); WIL(WI_LOCAL_TEE, ptr_local); WIL(WI_LOCAL_GET, end_ptr_local); if (elem_size != 1) { - WID(WI_I32_CONST, elem_size); - WI(WI_I32_MUL); + WID(WI_PTR_CONST, elem_size); + WI(WI_PTR_MUL); } - WI(WI_I32_ADD); + WI(WI_PTR_ADD); WIL(WI_LOCAL_SET, end_ptr_local); emit_enter_structured_block(mod, &code, SBT_Breakable_Block); emit_enter_structured_block(mod, &code, SBT_Basic_Loop); emit_enter_structured_block(mod, &code, SBT_Continue_Block); - // :32BitPointers WIL(WI_LOCAL_GET, ptr_local); WIL(WI_LOCAL_GET, end_ptr_local); - WI(WI_I32_GE_U); + WI(WI_PTR_GE); WID(WI_COND_JUMP, 0x02); if (!for_node->by_pointer) { @@ -877,10 +861,9 @@ EMIT_FUNC(for_slice, AstFor* for_node, u64 iter_local) { emit_leave_structured_block(mod, &code); - // :32BitPointers WIL(WI_LOCAL_GET, ptr_local); - WIL(WI_I32_CONST, elem_size); - WI(WI_I32_ADD); + WIL(WI_PTR_CONST, elem_size); + WI(WI_PTR_ADD); WIL(WI_LOCAL_SET, ptr_local); if (bh_arr_last(code).type != WI_JUMP) @@ -889,8 +872,8 @@ EMIT_FUNC(for_slice, AstFor* for_node, u64 iter_local) { emit_leave_structured_block(mod, &code); emit_leave_structured_block(mod, &code); - local_raw_free(mod->local_alloc, WASM_TYPE_INT32); - if (!for_node->by_pointer) local_raw_free(mod->local_alloc, WASM_TYPE_INT32); + local_raw_free(mod->local_alloc, WASM_TYPE_PTR); + if (!for_node->by_pointer) local_raw_free(mod->local_alloc, WASM_TYPE_PTR); *pcode = code; } @@ -1206,14 +1189,13 @@ EMIT_FUNC(call, AstCall* call) { if (place_on_stack) WID(WI_GLOBAL_GET, stack_top_idx); if (stack_grow_amm != 0) { - stack_top_store_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); + stack_top_store_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_PTR); WID(WI_GLOBAL_GET, stack_top_idx); WIL(WI_LOCAL_SET, stack_top_store_local); - // :32BitPointers WID(WI_GLOBAL_GET, stack_top_idx); - WID(WI_I32_CONST, stack_grow_amm); - WI(WI_I32_ADD); + WID(WI_PTR_CONST, stack_grow_amm); + WI(WI_PTR_ADD); WID(WI_GLOBAL_SET, stack_top_idx); } @@ -1223,7 +1205,7 @@ EMIT_FUNC(call, AstCall* call) { WIL(WI_LOCAL_GET, stack_top_store_local); WID(WI_GLOBAL_SET, stack_top_idx); - local_raw_free(mod->local_alloc, WASM_TYPE_INT32); + local_raw_free(mod->local_alloc, WASM_TYPE_PTR); } if (place_on_stack) { @@ -1231,10 +1213,9 @@ EMIT_FUNC(call, AstCall* call) { if (arg->va_kind != VA_Kind_Not_VA) vararg_count += 1; else { - // :32BitPointers WID(WI_GLOBAL_GET, stack_top_idx); - WID(WI_I32_CONST, stack_grow_amm); - WI(WI_I32_ADD); + WID(WI_PTR_CONST, stack_grow_amm); + WI(WI_PTR_ADD); } stack_grow_amm += type_size_of(arg->value->type); @@ -1243,20 +1224,18 @@ EMIT_FUNC(call, AstCall* call) { switch (call->va_kind) { case VA_Kind_Typed: { - // :32BitPointers WID(WI_GLOBAL_GET, stack_top_idx); - WID(WI_I32_CONST, vararg_offset); - WI(WI_I32_ADD); + WID(WI_PTR_CONST, vararg_offset); + WI(WI_PTR_ADD); WID(WI_I32_CONST, vararg_count); break; } case VA_Kind_Untyped: { - // :32BitPointers WID(WI_GLOBAL_GET, stack_top_idx); WID(WI_GLOBAL_GET, stack_top_idx); - WID(WI_I32_CONST, vararg_offset); - WI(WI_I32_ADD); + WID(WI_PTR_CONST, vararg_offset); + WI(WI_PTR_ADD); emit_store_instruction(mod, &code, &basic_types[Basic_Kind_Rawptr], stack_grow_amm); // NOTE: There will be 4 uninitialized bytes here, because pointers are only 4 bytes in WASM. @@ -1266,8 +1245,8 @@ EMIT_FUNC(call, AstCall* call) { emit_store_instruction(mod, &code, &basic_types[Basic_Kind_I32], stack_grow_amm + 8); WID(WI_GLOBAL_GET, stack_top_idx); - WID(WI_I32_CONST, stack_grow_amm); - WI(WI_I32_ADD); + WID(WI_PTR_CONST, stack_grow_amm); + WI(WI_PTR_ADD); stack_grow_amm += 12; break; @@ -1294,10 +1273,9 @@ EMIT_FUNC(call, AstCall* call) { bh_align(stack_grow_amm, 16); if (needs_stack) { - // :32BitPointers WID(WI_GLOBAL_GET, stack_top_idx); - WID(WI_I32_CONST, stack_grow_amm); - WI(WI_I32_ADD); + WID(WI_PTR_CONST, stack_grow_amm); + WI(WI_PTR_ADD); WID(WI_GLOBAL_SET, stack_top_idx); } @@ -1313,10 +1291,9 @@ EMIT_FUNC(call, AstCall* call) { } if (needs_stack) { - // :32BitPointers WID(WI_GLOBAL_GET, stack_top_idx); - WID(WI_I32_CONST, stack_grow_amm); - WI(WI_I32_SUB); + WID(WI_PTR_CONST, stack_grow_amm); + WI(WI_PTR_SUB); WID(WI_GLOBAL_SET, stack_top_idx); } @@ -1712,9 +1689,8 @@ EMIT_FUNC(array_access_location, AstArrayAccess* aa, u64* offset_return) { emit_expression(mod, &code, aa->expr); if (aa->elem_size != 1) { - // :32BitPointers - WID(WI_I32_CONST, aa->elem_size); - WI(WI_I32_MUL); + WID(WI_PTR_CONST, aa->elem_size); + WI(WI_PTR_MUL); } u64 offset = 0; @@ -1734,8 +1710,7 @@ EMIT_FUNC(array_access_location, AstArrayAccess* aa, u64* offset_return) { emit_expression(mod, &code, aa->addr); } - // :32BitPointers - WI(WI_I32_ADD); + WI(WI_PTR_ADD); *offset_return += offset; @@ -1781,8 +1756,7 @@ EMIT_FUNC(field_access_location, AstFieldAccess* field, u64* offset_return) { EMIT_FUNC(memory_reservation_location, AstMemRes* memres) { bh_arr(WasmInstruction) code = *pcode; - // :32BitPointers - WID(WI_I32_CONST, memres->addr); + WID(WI_PTR_CONST, memres->addr); *pcode = code; } @@ -1828,7 +1802,7 @@ EMIT_FUNC(compound_load, Type* type, u64 offset) { type_linear_member_lookup(type, 0, &two); emit_load_instruction(mod, &code, two.type, offset + two.offset); // two.offset should be 0 } else { - u64 tmp_idx = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); + u64 tmp_idx = local_raw_allocate(mod->local_alloc, WASM_TYPE_PTR); WIL(WI_LOCAL_TEE, tmp_idx); fori (i, 0, mem_count) { @@ -1837,7 +1811,7 @@ EMIT_FUNC(compound_load, Type* type, u64 offset) { emit_load_instruction(mod, &code, two.type, offset + two.offset); } - local_raw_free(mod->local_alloc, WASM_TYPE_INT32); + local_raw_free(mod->local_alloc, WASM_TYPE_PTR); } *pcode = code; @@ -1851,7 +1825,7 @@ EMIT_FUNC(compound_store, Type* type, u64 offset, b32 location_first) { TypeWithOffset two; - u64 loc_idx = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); + u64 loc_idx = local_raw_allocate(mod->local_alloc, WASM_TYPE_PTR); if (location_first) WIL(WI_LOCAL_SET, loc_idx); i32 elem_count = type_linear_member_count(type); @@ -1880,7 +1854,7 @@ EMIT_FUNC(compound_store, Type* type, u64 offset, b32 location_first) { } bh_arr_free(temp_locals); - local_raw_free(mod->local_alloc, WASM_TYPE_INT32); + local_raw_free(mod->local_alloc, WASM_TYPE_PTR); *pcode = code; } @@ -1907,8 +1881,8 @@ EMIT_FUNC(array_store, Type* type, u32 offset) { } u32 elem_size = type_size_of(elem_type); - u64 lptr_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); - u64 rptr_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); + u64 lptr_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_PTR); + u64 rptr_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_PTR); WIL(WI_LOCAL_SET, rptr_local); WIL(WI_LOCAL_SET, lptr_local); @@ -1928,8 +1902,8 @@ EMIT_FUNC(array_store, Type* type, u32 offset) { emit_store_instruction(mod, &code, elem_type, i * elem_size + offset); } - local_raw_free(mod->local_alloc, WASM_TYPE_INT32); - local_raw_free(mod->local_alloc, WASM_TYPE_INT32); + local_raw_free(mod->local_alloc, WASM_TYPE_PTR); + local_raw_free(mod->local_alloc, WASM_TYPE_PTR); *pcode = code; return; @@ -1952,9 +1926,8 @@ EMIT_FUNC(array_literal, AstArrayLiteral* al) { } WIL(WI_LOCAL_GET, mod->stack_base_idx); - // :32BitPointers - WIL(WI_I32_CONST, local_offset); - WI(WI_I32_ADD); + WIL(WI_PTR_CONST, local_offset); + WI(WI_PTR_ADD); *pcode = code; } @@ -1999,8 +1972,7 @@ EMIT_FUNC(location_return_offset, AstTyped* expr, u64* offset_return) { case Ast_Kind_Memres: { AstMemRes* memres = (AstMemRes *) expr; - // :32BitPointers - WID(WI_I32_CONST, memres->addr); + WID(WI_PTR_CONST, memres->addr); *offset_return = 0; break; } @@ -2020,9 +1992,8 @@ EMIT_FUNC(location, AstTyped* expr) { u64 offset = 0; emit_location_return_offset(mod, &code, expr, &offset); if (offset != 0) { - // :32BitPointers - WID(WI_I32_CONST, offset); - WI(WI_I32_ADD); + WID(WI_PTR_CONST, offset); + WI(WI_PTR_ADD); } *pcode = code; @@ -2077,9 +2048,8 @@ EMIT_FUNC(expression, AstTyped* expr) { if (expr->type->kind != Type_Kind_Array) { emit_load_instruction(mod, &code, expr->type, offset); } else if (offset != 0) { - // :32BitPointers - WID(WI_I32_CONST, offset); - WI(WI_I32_ADD); + WID(WI_PTR_CONST, offset); + WI(WI_PTR_ADD); } } @@ -2117,8 +2087,7 @@ EMIT_FUNC(expression, AstTyped* expr) { } case Ast_Kind_StrLit: { - // :32BitPointers - WID(WI_I32_CONST, ((AstStrLit *) expr)->addr); + WID(WI_PTR_CONST, ((AstStrLit *) expr)->addr); WID(WI_I32_CONST, ((AstStrLit *) expr)->length); break; } @@ -2141,7 +2110,6 @@ EMIT_FUNC(expression, AstTyped* expr) { case Ast_Kind_Function: { i32 elemidx = get_element_idx(mod, (AstFunction *) expr); - // :32BitPointers WID(WI_I32_CONST, elemidx); break; } @@ -2286,8 +2254,7 @@ EMIT_FUNC(expression, AstTyped* expr) { case Ast_Kind_File_Contents: { AstFileContents* fc = (AstFileContents *) expr; - // :32BitPointers - WID(WI_I32_CONST, fc->addr); + WID(WI_PTR_CONST, fc->addr); WID(WI_I32_CONST, fc->size); break; } @@ -2644,7 +2611,7 @@ static void emit_function(OnyxWasmModule* mod, AstFunction* fd) { // NOTE: '5' needs to match the number of instructions it takes // to setup a stack frame bh_arr_insert_end(wasm_func.code, 5); - mod->stack_base_idx = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); + mod->stack_base_idx = local_raw_allocate(mod->local_alloc, WASM_TYPE_PTR); } // Generate code @@ -3118,4 +3085,4 @@ void onyx_wasm_module_free(OnyxWasmModule* module) { } -#include "onyxwasm_output.c" \ No newline at end of file +#include "onyxwasm_output.c" diff --git a/src/onyxwasm_intrinsics.c b/src/onyxwasm_intrinsics.c index fa88c15d..c65a3e8a 100644 --- a/src/onyxwasm_intrinsics.c +++ b/src/onyxwasm_intrinsics.c @@ -16,8 +16,8 @@ EMIT_FUNC_NO_ARGS(intrinsic_memory_copy) { // u64 count_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); - u64 source_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); - u64 dest_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); + u64 source_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_PTR); + u64 dest_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_PTR); WIL(WI_LOCAL_SET, count_local); WIL(WI_LOCAL_SET, source_local); @@ -38,11 +38,11 @@ EMIT_FUNC_NO_ARGS(intrinsic_memory_copy) { WIL(WI_LOCAL_GET, dest_local); WIL(WI_LOCAL_GET, count_local); - WI(WI_I32_ADD); + WI(WI_PTR_ADD); WIL(WI_LOCAL_GET, source_local); WIL(WI_LOCAL_GET, count_local); - WI(WI_I32_ADD); + WI(WI_PTR_ADD); WID(WI_I32_LOAD_8_U, ((WasmInstructionData) { 0, 0 })); WID(WI_I32_STORE_8, ((WasmInstructionData) { 0, 0 })); @@ -56,8 +56,8 @@ EMIT_FUNC_NO_ARGS(intrinsic_memory_copy) { WI(WI_IF_END); local_raw_free(mod->local_alloc, WASM_TYPE_INT32); - local_raw_free(mod->local_alloc, WASM_TYPE_INT32); - local_raw_free(mod->local_alloc, WASM_TYPE_INT32); + local_raw_free(mod->local_alloc, WASM_TYPE_PTR); + local_raw_free(mod->local_alloc, WASM_TYPE_PTR); *pcode = code; } @@ -72,7 +72,7 @@ EMIT_FUNC_NO_ARGS(intrinsic_memory_fill) { u64 count_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); u64 byte_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); - u64 dest_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_INT32); + u64 dest_local = local_raw_allocate(mod->local_alloc, WASM_TYPE_PTR); WIL(WI_LOCAL_SET, count_local); WIL(WI_LOCAL_SET, byte_local); @@ -93,7 +93,7 @@ EMIT_FUNC_NO_ARGS(intrinsic_memory_fill) { WIL(WI_LOCAL_GET, dest_local); WIL(WI_LOCAL_GET, count_local); - WI(WI_I32_ADD); + WI(WI_PTR_ADD); WIL(WI_LOCAL_GET, byte_local); WID(WI_I32_STORE_8, ((WasmInstructionData) { 0, 0 })); @@ -108,7 +108,7 @@ EMIT_FUNC_NO_ARGS(intrinsic_memory_fill) { local_raw_free(mod->local_alloc, WASM_TYPE_INT32); local_raw_free(mod->local_alloc, WASM_TYPE_INT32); - local_raw_free(mod->local_alloc, WASM_TYPE_INT32); + local_raw_free(mod->local_alloc, WASM_TYPE_PTR); *pcode = code; -} \ No newline at end of file +}