custom sections are not automatically preserved anymore, but can be added manually
This commit is contained in:
parent
b5a61d053f
commit
11953b625e
|
@ -16,6 +16,8 @@ use treeify::Trees;
|
||||||
pub mod localify;
|
pub mod localify;
|
||||||
use localify::Localifier;
|
use localify::Localifier;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub struct WasmFuncBackend<'a> {
|
pub struct WasmFuncBackend<'a> {
|
||||||
body: &'a FunctionBody,
|
body: &'a FunctionBody,
|
||||||
trees: Trees,
|
trees: Trees,
|
||||||
|
@ -547,7 +549,7 @@ impl<'a> WasmFuncBackend<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compile(module: &Module<'_>) -> anyhow::Result<Vec<u8>> {
|
pub fn compile(module: &Module<'_>) -> anyhow::Result<wasm_encoder::Module> {
|
||||||
let mut into_mod = wasm_encoder::Module::new();
|
let mut into_mod = wasm_encoder::Module::new();
|
||||||
|
|
||||||
let mut types = wasm_encoder::TypeSection::new();
|
let mut types = wasm_encoder::TypeSection::new();
|
||||||
|
@ -788,11 +790,8 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result<Vec<u8>> {
|
||||||
}
|
}
|
||||||
names.functions(&func_names);
|
names.functions(&func_names);
|
||||||
into_mod.section(&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<u64>) -> wasm_encoder::ConstExpr {
|
fn const_init(ty: Type, value: Option<u64>) -> wasm_encoder::ConstExpr {
|
||||||
|
|
|
@ -192,6 +192,9 @@ impl<'a> Module<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_wasm_bytes(&self) -> Result<Vec<u8>> {
|
pub fn to_wasm_bytes(&self) -> Result<Vec<u8>> {
|
||||||
|
backend::compile(self).map(|a|a.finish())
|
||||||
|
}
|
||||||
|
pub fn to_encoded_module(&self) -> Result<wasm_encoder::Module>{
|
||||||
backend::compile(self)
|
backend::compile(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue