diff --git a/compiler/gen_wasm/src/wasm_module/mod.rs b/compiler/gen_wasm/src/wasm_module/mod.rs index 4badf3aefc..11722bf0d3 100644 --- a/compiler/gen_wasm/src/wasm_module/mod.rs +++ b/compiler/gen_wasm/src/wasm_module/mod.rs @@ -119,6 +119,7 @@ impl<'a> WasmModule<'a> { + self.element.size() + self.code.size() + self.data.size() + + self.names.size() } pub fn preload(arena: &'a Bump, bytes: &[u8]) -> Self { @@ -146,7 +147,6 @@ impl<'a> WasmModule<'a> { let global = GlobalSection::preload(arena, bytes, &mut cursor); ExportSection::skip_bytes(bytes, &mut cursor); - let export = ExportSection::empty(arena); let start = OpaqueSection::preload(SectionId::Start, arena, bytes, &mut cursor); diff --git a/compiler/gen_wasm/src/wasm_module/sections.rs b/compiler/gen_wasm/src/wasm_module/sections.rs index f49ce674e7..68e39cbd45 100644 --- a/compiler/gen_wasm/src/wasm_module/sections.rs +++ b/compiler/gen_wasm/src/wasm_module/sections.rs @@ -1,3 +1,5 @@ +use std::fmt::Debug; + use bumpalo::collections::vec::Vec; use bumpalo::Bump; use roc_collections::all::MutMap; @@ -1153,7 +1155,6 @@ enum NameSubSections { LocalNames = 2, } -#[derive(Debug)] pub struct NameSection<'a> { pub bytes: Vec<'a, u8>, pub functions: MutMap<&'a [u8], u32>, @@ -1189,6 +1190,10 @@ impl<'a> NameSection<'a> { section } + pub fn size(&self) -> usize { + self.bytes.len() + } + fn parse_body( &mut self, arena: &'a Bump, @@ -1253,6 +1258,27 @@ impl<'a> Serialize for NameSection<'a> { } } +impl<'a> Debug for NameSection<'a> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "NameSection\n")?; + + // We want to display index->name because it matches the binary format and looks nicer. + // But our hashmap is name->index because that's what code gen wants to look up. + let mut by_index = std::vec::Vec::with_capacity(self.functions.len()); + for (name, index) in self.functions.iter() { + by_index.push((*index, name)); + } + by_index.sort_unstable(); + + for (index, name) in by_index.iter() { + let name_str = unsafe { std::str::from_utf8_unchecked(name) }; + write!(f, " {:4}: {}\n", index, name_str)?; + } + + Ok(()) + } +} + /******************************************************************* * * Unit tests