wasm/execution/runtime_structure/
module_instances.rs

1use alloc::{collections::btree_map::BTreeMap, string::String};
2
3use crate::{
4    core::{
5        sidetable::Sidetable,
6        structure::modules::indices::{
7            DataIdx, ElemIdx, FuncIdx, GlobalIdx, IdxVec, MemIdx, TableIdx, TypeIdx,
8        },
9    },
10    DataAddr, ElemAddr, ExternVal, FuncAddr, FuncType, GlobalAddr, MemAddr, TableAddr,
11};
12
13/// <https://webassembly.github.io/spec/core/exec/runtime.html#module-instances>/
14///
15/// # Safety
16///
17/// All indices contained in a module instance must be valid in their associated
18/// index vectors from the same module instance.
19#[derive(Debug)]
20pub struct ModuleInst<'b> {
21    pub types: IdxVec<TypeIdx, FuncType>,
22    pub func_addrs: IdxVec<FuncIdx, FuncAddr>,
23    pub table_addrs: IdxVec<TableIdx, TableAddr>,
24    pub mem_addrs: IdxVec<MemIdx, MemAddr>,
25    pub global_addrs: IdxVec<GlobalIdx, GlobalAddr>,
26    pub elem_addrs: IdxVec<ElemIdx, ElemAddr>,
27    pub data_addrs: IdxVec<DataIdx, DataAddr>,
28    ///<https://webassembly.github.io/spec/core/exec/runtime.html#export-instances>
29    /// matches the list of ExportInst structs in the spec, however the spec never uses the name attribute
30    /// except during linking, which is up to the embedder to implement.
31    /// therefore this is a map data structure instead.
32    pub exports: BTreeMap<String, ExternVal>,
33
34    // TODO the bytecode is not in the spec, but required for re-parsing
35    pub wasm_bytecode: &'b [u8],
36
37    // sidetable is not in the spec, but required for control flow
38    pub sidetable: Sidetable,
39}