use crate::Wizer;
use ::wasmtime::{Result, bail};
mod info;
mod instrument;
mod parse;
mod rewrite;
mod snapshot;
#[cfg(feature = "wasmtime")]
mod wasmtime;
#[cfg(feature = "wasmtime")]
pub use wasmtime::*;
const WIZER_INSTANCE: &str = "wasmtime:wizer/access";
pub use self::info::ComponentContext;
impl Wizer {
pub fn instrument_component<'a>(
&self,
wasm: &'a [u8],
) -> Result<(ComponentContext<'a>, Vec<u8>)> {
self.wasm_validate(&wasm)?;
let mut cx = parse::parse(wasm)?;
let instrumented_wasm = instrument::instrument(&mut cx)?;
self.debug_assert_valid_wasm(&instrumented_wasm, "instrumented component");
Ok((cx, instrumented_wasm))
}
pub async fn snapshot_component(
&self,
mut cx: ComponentContext<'_>,
instance: &mut impl ComponentInstanceState,
) -> Result<Vec<u8>> {
if !self.func_renames.is_empty() {
bail!("components do not support renaming functions");
}
let snapshot = snapshot::snapshot(&cx, instance).await;
let rewritten_wasm = self.rewrite_component(&mut cx, &snapshot);
self.debug_assert_valid_wasm(&rewritten_wasm, "rewritten component");
Ok(rewritten_wasm)
}
}
pub trait ComponentInstanceState: Send {
fn call_func_ret_list_u8(
&mut self,
instance: &str,
func: &str,
contents: impl FnOnce(&[u8]) + Send,
) -> impl Future<Output = ()> + Send;
fn call_func_ret_s32(&mut self, instance: &str, func: &str)
-> impl Future<Output = i32> + Send;
fn call_func_ret_s64(&mut self, instance: &str, func: &str)
-> impl Future<Output = i64> + Send;
fn call_func_ret_f32(&mut self, instance: &str, func: &str)
-> impl Future<Output = u32> + Send;
fn call_func_ret_f64(&mut self, instance: &str, func: &str)
-> impl Future<Output = u64> + Send;
}