From 11953b625ed022087e3ed6f6d76cf769e6490538 Mon Sep 17 00:00:00 2001 From: Graham Kelly Date: Mon, 19 Feb 2024 13:16:59 -0500 Subject: [PATCH] custom sections are not automatically preserved anymore, but can be added manually --- src/backend/mod.rs | 9 ++++----- src/ir/module.rs | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-) 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) }