pub fn run(&self, wasm: &[u8]) -> anyhow::Result<Vec<u8>> {
        // Parse rename spec.
        let renames = FuncRenames::parse(&self.func_renames)?;

        // Make sure we're given valid Wasm from the get go.
        self.wasm_validate(&wasm)?;

        let mut cx = parse::parse(wasm)?;
        let instrumented_wasm = instrument::instrument(&cx);

        if cfg!(debug_assertions) {
            if let Err(error) = self.wasm_validate(&instrumented_wasm) {
                #[cfg(feature = "wasmprinter")]
                let wat = wasmprinter::print_bytes(&wasm)
                    .unwrap_or_else(|e| format!("Disassembling to WAT failed: {}", e));
                #[cfg(not(feature = "wasmprinter"))]
                let wat = "`wasmprinter` cargo feature is not enabled".to_string();
                panic!(
                    "instrumented Wasm is not valid: {:?}\n\nWAT:\n{}",
                    error, wat
                );
            }
        }

        let config = self.wasmtime_config()?;
        let engine = wasmtime::Engine::new(&config)?;
        let wasi_ctx = self.wasi_context()?;
        let mut store = wasmtime::Store::new(&engine, wasi_ctx);
        let module = wasmtime::Module::new(&engine, &instrumented_wasm)
            .context("failed to compile the Wasm module")?;
        self.validate_init_func(&module)?;

        let instance = self.initialize(&mut store, &module)?;
        let snapshot = snapshot::snapshot(&mut store, &instance);
        let rewritten_wasm = self.rewrite(&mut cx, &mut store, &snapshot, &renames);

        if cfg!(debug_assertions) {
            if let Err(error) = self.wasm_validate(&rewritten_wasm) {
                #[cfg(feature = "wasmprinter")]
                let wat = wasmprinter::print_bytes(&wasm)
                    .unwrap_or_else(|e| format!("Disassembling to WAT failed: {}", e));
                #[cfg(not(feature = "wasmprinter"))]
                let wat = "`wasmprinter` cargo feature is not enabled".to_string();
                panic!("rewritten Wasm is not valid: {:?}\n\nWAT:\n{}", error, wat);
            }
        }

        Ok(rewritten_wasm)
    }
/// Initialize the given Wasm, snapshot it, and return the serialized
/// snapshot as a new, pre-initialized Wasm module.
Initialize the given Wasm, snapshot it, and return the serialized
snapshot as a new, pre-initialized Wasm module.
Initialize the given Wasm snapshot it and return the serialized snapshot as a new pre - initialized Wasm module .
pub fn run(&self, wasm: &[u8]) -> anyhow::Result<Vec<u8>> {
        // Parse rename spec.
        let renames = FuncRenames::parse(&self.func_renames)?;
        // Make sure we're given valid Wasm from the get go.
        self.wasm_validate(&wasm)?;
        let mut cx = parse::parse(wasm)?;
        let instrumented_wasm = instrument::instrument(&cx);
        if cfg!(debug_assertions) {
            if let Err(error) = self.wasm_validate(&instrumented_wasm) {
                #[cfg(feature = "wasmprinter")]
                let wat = wasmprinter::print_bytes(&wasm)
                    .unwrap_or_else(|e| format!("Disassembling to WAT failed: {}", e));
                #[cfg(not(feature = "wasmprinter"))]
                let wat = "`wasmprinter` cargo feature is not enabled".to_string();
                panic!(
                    "instrumented Wasm is not valid: {:?}\n\nWAT:\n{}",
                    error, wat
                );
            }
        }
        let config = self.wasmtime_config()?;
        let engine = wasmtime::Engine::new(&config)?;
        let wasi_ctx = self.wasi_context()?;
        let mut store = wasmtime::Store::new(&engine, wasi_ctx);
        let module = wasmtime::Module::new(&engine, &instrumented_wasm)
            .context("failed to compile the Wasm module")?;
        self.validate_init_func(&module)?;
        let instance = self.initialize(&mut store, &module)?;
        let snapshot = snapshot::snapshot(&mut store, &instance);
        let rewritten_wasm = self.rewrite(&mut cx, &mut store, &snapshot, &renames);
        if cfg!(debug_assertions) {
            if let Err(error) = self.wasm_validate(&rewritten_wasm) {
                #[cfg(feature = "wasmprinter")]
                let wat = wasmprinter::print_bytes(&wasm)
                    .unwrap_or_else(|e| format!("Disassembling to WAT failed: {}", e));
                #[cfg(not(feature = "wasmprinter"))]
                let wat = "`wasmprinter` cargo feature is not enabled".to_string();
                panic!("rewritten Wasm is not valid: {:?}\n\nWAT:\n{}", error, wat);
            }
        }
        Ok(rewritten_wasm)
    }
pub fn run ( & self , wasm : & [ u8 ] ) -> anyhow :: Result < Vec < u8 > > { // Parse rename spec. let renames = FuncRenames :: parse ( & self . func_renames ) ? ; // Make sure we're given valid Wasm from the get go. self . wasm_validate ( & wasm ) ? ; let mut cx = parse :: parse ( wasm ) ? ; let instrumented_wasm = instrument :: instrument ( & cx ) ; if cfg ! ( debug_assertions ) { if let Err ( error ) = self . wasm_validate ( & instrumented_wasm ) { # [ cfg ( feature " " ) ] let wat = wasmprinter :: print_bytes ( & wasm ) . unwrap_or_else ( | e | format ! ( " " e ) ) ; # [ cfg ( not ( feature " " ) ) ] let wat = " " . to_string ( ) ; panic ! ( " \n \n \n " error wat ) ; } } let config = self . wasmtime_config ( ) ? ; let engine = wasmtime :: Engine :: new ( & config ) ? ; let wasi_ctx = self . wasi_context ( ) ? ; let mut store = wasmtime :: Store :: new ( & engine , wasi_ctx ) ; let module = wasmtime :: Module :: new ( & engine , & instrumented_wasm ) . context ( " " ) ? ; self . validate_init_func ( & module ) ? ; let instance = self . initialize ( & mut store , & module ) ? ; let snapshot = snapshot :: snapshot ( & mut store , & instance ) ; let rewritten_wasm = self . rewrite ( & mut cx , & mut store , & snapshot , & renames ) ; if cfg ! ( debug_assertions ) { if let Err ( error ) = self . wasm_validate ( & rewritten_wasm ) { # [ cfg ( feature " " ) ] let wat = wasmprinter :: print_bytes ( & wasm ) . unwrap_or_else ( | e | format ! ( " " e ) ) ; # [ cfg ( not ( feature " " ) ) ] let wat = " " . to_string ( ) ; panic ! ( " \n \n \n " error wat ) ; } } Ok ( rewritten_wasm ) }
Initialize the given Wasm, snapshot it, and return the serialized
snapshot as a new, pre-initialized Wasm module.
Initialize the given Wasm snapshot it and return the serialized snapshot as a new pre - initialized Wasm module .
&self
wasm
&[u8]
&self
wasm
&[u8]