diff --git a/src/backend/mod.rs b/src/backend/mod.rs index e6ef716..03d15b2 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -16,6 +16,8 @@ use treeify::Trees; pub mod localify; use localify::Localifier; + + pub struct WasmFuncBackend<'a> { body: &'a FunctionBody, trees: Trees, @@ -547,7 +549,7 @@ impl<'a> WasmFuncBackend<'a> { } } -pub fn compile(module: &Module<'_>) -> anyhow::Result> { +pub fn compile(module: &Module<'_>) -> anyhow::Result { let mut into_mod = wasm_encoder::Module::new(); let mut types = wasm_encoder::TypeSection::new(); @@ -788,11 +790,8 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result> { } names.functions(&func_names); into_mod.section(&names); - for (k, v) in module.custom_sections.iter() { - into_mod.section(&CustomSection { name: &k, data: &v }); - } - Ok(into_mod.finish()) + Ok(into_mod) } fn const_init(ty: Type, value: Option) -> wasm_encoder::ConstExpr { diff --git a/src/ir/module.rs b/src/ir/module.rs index a3f2d37..54be09b 100644 --- a/src/ir/module.rs +++ b/src/ir/module.rs @@ -192,6 +192,9 @@ impl<'a> Module<'a> { } pub fn to_wasm_bytes(&self) -> Result> { + backend::compile(self).map(|a|a.finish()) + } + pub fn to_encoded_module(&self) -> Result{ backend::compile(self) }