/* * 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 static enum nw_state get_offset(struct nw_interp *const i) { struct nw_i_sm_imm *const imm = &i->sm.imm; struct nw_sm_leb128 *const l = &imm->leb128; const struct nw_io_cfg *const cfg = &i->cfg.io; const enum nw_state n = nwp_varuint32(cfg, l, &imm->out.offset, cfg->user); if (n) return n; imm->next(i); return NW_AGAIN; } static enum nw_state get_flags(struct nw_interp *const i) { struct nw_i_sm_imm *const imm = &i->sm.imm; struct nw_sm_leb128 *const l = &imm->leb128; const struct nw_io_cfg *const cfg = &i->cfg.io; const enum nw_state n = nwp_varuint32(cfg, l, &imm->out.flags, cfg->user); if (n) return n; i->next = get_offset; return NW_AGAIN; } void nwp_mem_imm(struct nw_interp *const i, void (*const next)(struct nw_interp *)) { const struct nw_i_sm_imm imm = {0}; struct nw_i_sm_imm *const p = &i->sm.imm; *p = imm; p->next = next; i->next = get_flags; }