mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
Wasm: Convert remaining sections to store bytes, and add .size() methods
This commit is contained in:
parent
f4ac5bffa3
commit
5d5e0eca96
5 changed files with 154 additions and 54 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue