/* * nanowasm, a tiny WebAssembly/Wasm interpreter * Copyright (C) 2023-2024 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 #include int nwp_interp_check_opcode(const uint8_t op, FILE *const f) { static int (*const checks[])(FILE *) = { [OP_UNREACHABLE] = check_unreachable, [OP_NOP] = check_nop, [OP_BLOCK] = check_block, [OP_LOOP] = check_loop, [OP_IF] = check_if, [OP_ELSE] = check_else, [OP_END] = check_end, [OP_BR] = check_br, [OP_BR_IF] = check_br_if, [OP_BR_TABLE] = check_br_table, [OP_RETURN] = check_return, [OP_CALL] = check_call, [OP_CALL_INDIRECT] = check_call_indirect, [OP_GET_LOCAL] = check_get_local, [OP_SET_LOCAL] = check_set_local, [OP_TEE_LOCAL] = check_tee_local, [OP_GET_GLOBAL] = check_get_global, [OP_SET_GLOBAL] = check_set_global, [OP_I32_LOAD] = check_i32_load, [OP_I32_STORE] = check_i32_store, [OP_I32_CONST] = check_i32_const, [OP_I64_CONST] = check_i64_const, [OP_F32_CONST] = check_f32_const, [OP_F64_CONST] = check_f64_const, [OP_I32_SUB] = check_i32_sub }; if (op >= sizeof checks / sizeof *checks) { LOG("%s: invalid opcode %#" PRIx8 "\n", __func__, op); return 1; } else if (!checks[op]) { LOG("%s: unsupported opcode %#" PRIx8 "\n", __func__, op); return 1; } return checks[op](f); }