/* * nanowasm, a tiny WebAssembly/Wasm interpreter * Copyright (C) 2023-2025 Xavier Del Campo Romero * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #include #include #include #include static void (*const ops[])(struct nw_interp *) = { nwp_op_unreachable, /* OP_UNREACHABLE */ nwp_op_nop, /* OP_NOP */ nwp_op_block, /* OP_BLOCK */ nwp_op_loop, /* OP_LOOP */ nwp_op_if, /* OP_IF */ nwp_op_else, /* OP_ELSE */ NULL, NULL, NULL, NULL, NULL, nwp_op_end, /* OP_END */ nwp_op_br, /* OP_BR */ nwp_op_br_if, /* OP_BR_IF */ nwp_op_br_table, /* OP_BR_TABLE */ nwp_op_return, /* OP_RETURN */ nwp_op_call, /* OP_CALL */ nwp_op_call_indirect, /* OP_CALL_INDIRECT */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, nwp_op_drop, /* OP_DROP */ nwp_op_select, /* OP_SELECT */ NULL, NULL, NULL, NULL, nwp_op_get_local, /* OP_GET_LOCAL */ nwp_op_set_local, /* OP_SET_LOCAL */ nwp_op_tee_local, /* OP_TEE_LOCAL */ nwp_op_get_global, /* OP_GET_GLOBAL */ nwp_op_set_global, /* OP_SET_GLOBAL */ NULL, NULL, NULL, nwp_op_i32_load, /* OP_I32_LOAD */ NULL, /* OP_I64_LOAD */ NULL, /* OP_F32_LOAD */ NULL, /* OP_F64_LOAD */ NULL, /* OP_I32_LOAD8_S */ nwp_op_i32_load8_u, /* OP_I32_LOAD8_U */ NULL, /* OP_I32_LOAD16_S */ NULL, /* OP_I32_LOAD16_U */ NULL, /* OP_I64_LOAD8_S */ NULL, /* OP_I64_LOAD8_U */ NULL, /* OP_I64_LOAD16_S */ NULL, /* OP_I64_LOAD16_U */ NULL, /* OP_I64_LOAD32_S */ NULL, /* OP_I64_LOAD32_U */ nwp_op_i32_store, /* OP_I32_STORE */ nwp_op_i64_store, /* OP_I64_STORE */ NULL, /* OP_F32_STORE */ NULL, /* OP_F64_STORE */ nwp_op_i32_store8, /* OP_I32_STORE8 */ NULL, /* OP_I32_STORE16 */ NULL, /* OP_I64_STORE8 */ NULL, /* OP_I64_STORE16 */ NULL, /* OP_I64_STORE32 */ nwp_op_current_memory, /* OP_CURRENT_MEMORY */ nwp_op_grow_memory, /* OP_GROW_MEMORY */ nwp_op_i32_const, /* OP_I32_CONST */ nwp_op_i64_const, /* OP_I64_CONST */ NULL, /* OP_F32_CONST */ NULL, /* OP_F64_CONST */ nwp_op_i32_eqz, /* OP_I32_EQZ */ nwp_op_i32_eq, /* OP_I32_EQ */ nwp_op_i32_ne, /* OP_I32_NE */ nwp_op_i32_lt_s, /* OP_I32_LT_S */ nwp_op_i32_lt_u, /* OP_I32_LT_U */ nwp_op_i32_gt_s, /* OP_I32_GT_S */ nwp_op_i32_gt_u, /* OP_I32_GT_U */ nwp_op_i32_le_s, /* OP_I32_LE_S */ nwp_op_i32_le_u, /* OP_I32_LE_U */ nwp_op_i32_ge_s, /* OP_I32_GE_S */ nwp_op_i32_ge_u, /* OP_I32_GE_U */ NULL, /* OP_I64_EQZ */ NULL, /* OP_I64_EQ */ NULL, /* OP_I64_NE */ NULL, /* OP_I64_LT_S */ NULL, /* OP_I64_LT_U */ NULL, /* OP_I64_GT_S */ NULL, /* OP_I64_GT_U */ NULL, /* OP_I64_LE_S */ NULL, /* OP_I64_LE_U */ NULL, /* OP_I64_GE_S */ NULL, /* OP_I64_GE_U */ NULL, /* OP_F32_EQ */ NULL, /* OP_F32_NE */ NULL, /* OP_F32_LT */ NULL, /* OP_F32_GT */ NULL, /* OP_F32_LE */ NULL, /* OP_F32_GE */ NULL, /* OP_F64_EQ */ NULL, /* OP_F64_NE */ NULL, /* OP_F64_LT */ NULL, /* OP_F64_GT */ NULL, /* OP_F64_LE */ NULL, /* OP_F64_GE */ NULL, /* OP_I32_CLZ */ NULL, /* OP_I32_CTZ */ NULL, /* OP_I32_POPCNT */ nwp_op_i32_add, /* OP_I32_ADD */ nwp_op_i32_sub, /* OP_I32_SUB */ nwp_op_i32_mul, /* OP_I32_MUL */ NULL, /* OP_I32_DIV_S */ NULL, /* OP_I32_DIV_U */ NULL, /* OP_I32_REM_S */ NULL, /* OP_I32_REM_U */ nwp_op_i32_and, /* OP_I32_AND */ nwp_op_i32_or, /* OP_I32_OR */ nwp_op_i32_xor, /* OP_I32_XOR */ nwp_op_i32_shl, /* OP_I32_SHL */ nwp_op_i32_shr_s, /* OP_I32_SHR_S */ nwp_op_i32_shr_u, /* OP_I32_SHR_U */ NULL, /* OP_I32_ROTL */ NULL, /* OP_I32_ROTR */ NULL, /* OP_I64_CLZ */ NULL, /* OP_I64_CTZ */ NULL, /* OP_I64_POPCNT */ NULL, /* OP_I64_ADD */ NULL, /* OP_I64_SUB */ NULL, /* OP_I64_MUL */ NULL, /* OP_I64_DIV_S */ NULL, /* OP_I64_DIV_U */ NULL, /* OP_I64_REM_S */ NULL, /* OP_I64_REM_U */ NULL, /* OP_I64_AND */ NULL, /* OP_I64_OR */ NULL, /* OP_I64_XOR */ NULL, /* OP_I64_SHL */ NULL, /* OP_I64_SHR_S */ NULL, /* OP_I64_SHR_U */ NULL, /* OP_I64_ROTL */ NULL, /* OP_I64_ROTR */ NULL, /* OP_F32_ABS */ NULL, /* OP_F32_NEG */ NULL, /* OP_F32_CEIL */ NULL, /* OP_F32_FLOOR */ NULL, /* OP_F32_TRUNC */ NULL, /* OP_F32_NEAREST */ NULL, /* OP_F32_SQRT */ NULL, /* OP_F32_ADD */ NULL, /* OP_F32_SUB */ NULL, /* OP_F32_MUL */ NULL, /* OP_F32_DIV */ NULL, /* OP_F32_MIN */ NULL, /* OP_F32_MAX */ NULL, /* OP_F32_COPYSIGN */ NULL, /* OP_F64_ABS */ NULL, /* OP_F64_NEG */ NULL, /* OP_F64_CEIL */ NULL, /* OP_F64_FLOOR */ NULL, /* OP_F64_TRUNC */ NULL, /* OP_F64_NEAREST */ NULL, /* OP_F64_SQRT */ NULL, /* OP_F64_ADD */ NULL, /* OP_F64_SUB */ NULL, /* OP_F64_MUL */ NULL, /* OP_F64_DIV */ NULL, /* OP_F64_MIN */ NULL, /* OP_F64_MAX */ NULL, /* OP_F64_COPYSIGN */ NULL, /* OP_I32_WRAP_I64 */ NULL, /* OP_I32_TRUNC_S_F32 */ NULL, /* OP_I32_TRUNC_U_F32 */ NULL, /* OP_I32_TRUNC_S_F64 */ NULL, /* OP_I32_TRUNC_U_F64 */ NULL, /* OP_I64_EXTEND_S_I32 */ NULL, /* OP_I64_EXTEND_U_I32 */ NULL, /* OP_I64_TRUNC_S_F32 */ NULL, /* OP_I64_TRUNC_U_F32 */ NULL, /* OP_I64_TRUNC_S_F64 */ NULL, /* OP_I64_TRUNC_U_F64 */ NULL, /* OP_F32_CONVERT_S_I32 */ NULL, /* OP_F32_CONVERT_U_I32 */ NULL, /* OP_F32_CONVERT_S_I64 */ NULL, /* OP_F32_CONVERT_U_I64 */ NULL, /* OP_F32_DEMOTE_F64 */ NULL, /* OP_F64_CONVERT_S_I32 */ NULL, /* OP_F64_CONVERT_U_I32 */ NULL, /* OP_F64_CONVERT_S_I64 */ NULL, /* OP_F64_CONVERT_U_I64 */ NULL, /* OP_F64_PROMOTE_F32 */ NULL, /* OP_I32_REINTERPRET_F32 */ NULL, /* OP_I64_REINTERPRET_F64 */ NULL, /* OP_F32_REINTERPRET_I32 */ NULL, /* OP_F64_REINTERPRET_I64 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL /* OP_MISC */ }; const struct nwp_ops nwp_ops = { ops, sizeof ops / sizeof *ops };