54 lines
1.6 KiB
Rust
54 lines
1.6 KiB
Rust
//! Utility module to create trampolines in/out WebAssembly module.
|
|
|
|
mod code_memory;
|
|
mod create_handle;
|
|
mod func;
|
|
mod global;
|
|
mod memory;
|
|
mod table;
|
|
|
|
use crate::r#ref::HostRef;
|
|
use failure::Error;
|
|
use std::rc::Rc;
|
|
|
|
use self::func::create_handle_with_function;
|
|
use self::global::create_global;
|
|
use self::memory::create_handle_with_memory;
|
|
use self::table::create_handle_with_table;
|
|
use super::{Callable, FuncType, GlobalType, MemoryType, Store, TableType, Val};
|
|
|
|
pub use self::global::GlobalState;
|
|
|
|
pub fn generate_func_export(
|
|
ft: &FuncType,
|
|
func: &Rc<dyn Callable + 'static>,
|
|
store: &HostRef<Store>,
|
|
) -> Result<(wasmtime_runtime::InstanceHandle, wasmtime_runtime::Export), Error> {
|
|
let mut instance = create_handle_with_function(ft, func, store)?;
|
|
let export = instance.lookup("trampoline").expect("trampoline export");
|
|
Ok((instance, export))
|
|
}
|
|
|
|
pub fn generate_global_export(
|
|
gt: &GlobalType,
|
|
val: Val,
|
|
) -> Result<(wasmtime_runtime::Export, GlobalState), Error> {
|
|
create_global(gt, val)
|
|
}
|
|
|
|
pub fn generate_memory_export(
|
|
m: &MemoryType,
|
|
) -> Result<(wasmtime_runtime::InstanceHandle, wasmtime_runtime::Export), Error> {
|
|
let mut instance = create_handle_with_memory(m)?;
|
|
let export = instance.lookup("memory").expect("memory export");
|
|
Ok((instance, export))
|
|
}
|
|
|
|
pub fn generate_table_export(
|
|
t: &TableType,
|
|
) -> Result<(wasmtime_runtime::InstanceHandle, wasmtime_runtime::Export), Error> {
|
|
let mut instance = create_handle_with_table(t)?;
|
|
let export = instance.lookup("table").expect("table export");
|
|
Ok((instance, export))
|
|
}
|