1 use super::create_handle::create_handle;
2 use crate::trampoline::StoreInstanceHandle;
3 use crate::Store;
4 use crate::{TableType, ValType};
5 use anyhow::{bail, Result};
6 use wasmtime_environ::entity::PrimaryMap;
7 use wasmtime_environ::{wasm, EntityIndex, Module};
8
create_handle_with_table(store: &Store, table: &TableType) -> Result<StoreInstanceHandle>9 pub fn create_handle_with_table(store: &Store, table: &TableType) -> Result<StoreInstanceHandle> {
10 let mut module = Module::new();
11
12 let table = wasm::Table {
13 minimum: table.limits().min(),
14 maximum: table.limits().max(),
15 ty: match table.element() {
16 ValType::FuncRef => wasm::TableElementType::Func,
17 _ => bail!("cannot support {:?} as a table element", table.element()),
18 },
19 };
20 let tunable = Default::default();
21
22 let table_plan = wasmtime_environ::TablePlan::for_table(table, &tunable);
23 let table_id = module.local.table_plans.push(table_plan);
24 module
25 .exports
26 .insert("table".to_string(), EntityIndex::Table(table_id));
27
28 create_handle(
29 module,
30 store,
31 PrimaryMap::new(),
32 Default::default(),
33 Box::new(()),
34 )
35 }
36