mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 23:04:49 +00:00
wasm: Custom Debug impl for NameSection
This commit is contained in:
parent
a9df6f4ff9
commit
b46690ecf2
2 changed files with 28 additions and 2 deletions
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue