Move WasmModule initialisation into WasmBackend

It helps to coordinate different sections with related values,
based on knowledge of Roc rather than Wasm.
This commit is contained in:
Brian Carroll 2021-11-04 20:41:23 +00:00
parent 1b91fd9533
commit 414c9e6f86
3 changed files with 58 additions and 49 deletions

View file

@ -13,8 +13,8 @@ use roc_mono::layout::LayoutIds;
use crate::backend::WasmBackend;
use crate::wasm_module::{
Align, CodeBuilder, Export, ExportType, Global, ConstExpr, GlobalType, LinkingSubSection,
LocalId, SymInfo, ValueType, WasmModule,
Align, CodeBuilder, Export, ExportType, LinkingSubSection, LocalId, SymInfo, ValueType,
WasmModule,
};
const PTR_SIZE: u32 = 4;
@ -73,21 +73,6 @@ pub fn build_module_help<'a>(
let symbol_table = LinkingSubSection::SymbolTable(symbol_table_entries);
backend.module.linking.subsections.push(symbol_table);
backend.module.export.entries.push(Export {
name: "memory".to_string(),
ty: ExportType::Mem,
index: 0,
});
let stack_pointer_init = backend.module.memory.min_size().unwrap() as i32;
backend.module.global.entries.push(Global {
ty: GlobalType {
value_type: ValueType::I32,
is_mutable: true,
},
init: ConstExpr::I32(stack_pointer_init),
});
Ok(backend.module)
}