diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 2c074df..b11110c 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -1303,11 +1303,6 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result { let mut code = wasm_encoder::CodeSection::new(); - enum FuncOrRawBytes<'a> { - Raw(&'a [u8]), - Func(Cow<'a, wasm_encoder::Function>), - } - let bodies = module .funcs .entries() @@ -1318,16 +1313,14 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result { match func_decl { FuncDecl::Lazy(_, _name, reader) => { let data = &module.orig_bytes[reader.range()]; - Ok(FuncOrRawBytes::Raw(data)) - } - FuncDecl::Compiled(_, _name, encoder) => { - Ok(FuncOrRawBytes::Func(Cow::Borrowed(encoder))) + Ok(Cow::Borrowed(data)) } + FuncDecl::Compiled(_, _name, bytes) => Ok(Cow::Borrowed(&bytes[..])), FuncDecl::Body(_, name, body) => { log::debug!("Compiling {} \"{}\"", func, name); WasmFuncBackend::new(body)? .compile() - .map(|func| FuncOrRawBytes::Func(Cow::Owned(func))) + .map(|func| Cow::Owned(func.into_raw_body())) } FuncDecl::Import(_, _) => unreachable!("Should have skipped imports"), FuncDecl::None => panic!("FuncDecl::None at compilation time"), @@ -1336,14 +1329,7 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result { .collect::>>()?; for body in bodies { - match body { - FuncOrRawBytes::Raw(bytes) => { - code.raw(bytes); - } - FuncOrRawBytes::Func(func) => { - code.function(&*func); - } - } + code.raw(&body); } into_mod.section(&code); diff --git a/src/ir/func.rs b/src/ir/func.rs index f160ece..61ba209 100644 --- a/src/ir/func.rs +++ b/src/ir/func.rs @@ -22,7 +22,7 @@ pub enum FuncDecl<'a> { /// A modified or new function body that requires compilation. Body(Signature, String, FunctionBody), /// A compiled function body (was IR, has been collapsed back to bytecode). - Compiled(Signature, String, wasm_encoder::Function), + Compiled(Signature, String, Vec), /// A placeholder. #[default] None,