Wasm: Convert remaining sections to store bytes, and add .size() methods

This commit is contained in:
Brian Carroll 2022-01-08 18:23:09 +00:00
parent f4ac5bffa3
commit 5d5e0eca96
5 changed files with 154 additions and 54 deletions

View file

@ -21,7 +21,7 @@ pub struct WasmModule<'a> {
pub import: ImportSection<'a>,
pub function: FunctionSection<'a>,
pub table: OpaqueSection<'a>,
pub memory: MemorySection,
pub memory: MemorySection<'a>,
pub global: GlobalSection<'a>,
pub export: ExportSection<'a>,
pub start: OpaqueSection<'a>,
@ -96,6 +96,22 @@ impl<'a> WasmModule<'a> {
self.relocations.target_section_index = Some(code_section_index);
self.relocations.serialize(buffer);
}
/// Module size in bytes (assuming no linker data)
/// May be slightly overestimated. Intended for allocating buffer capacity.
pub fn size(&self) -> usize {
self.types.size()
+ self.import.size()
+ self.function.size()
+ self.table.size()
+ self.memory.size()
+ self.global.size()
+ self.export.size()
+ self.start.size()
+ self.element.size()
+ self.code.size()
+ self.data.size()
}
}
/// Helper struct to count non-empty sections.