Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,11 @@ generate! { function_name -> (FuncIdx, Name) = {
let name = run!(name);
(idx, name)
}}
generate! { global_name -> (GlobalIdx, Name) = {
let idx = run!(globalidx);
let name = run!(name);
(idx, name)
}}
generate! { names -> Names = {
// Reference: https://github.com/WebAssembly/wabt/blob/713bece/src/binary-reader.cc#L1634
// This is a custom section, that appears to show up in WASI modules.
Expand All @@ -749,19 +754,30 @@ generate! { names -> Names = {
module: None,
functions: HashMap::new(),
locals: HashMap::new(),
globals: HashMap::new(),
};
let name_type = run!(u32); // module = 0, function = 1, local = 2
if name_type != 1 {
// We don't support non-function names just yet. Might add it
// in the future.
unimplemented!()
}
let subsection_size = run!(u32);
if subsection_size > 0 {
let mut inp = inp![..subsection_size as usize];
names.functions = run_manual!(vec(inp, function_name)).into_iter().collect();
if inp.len() != 0 {
err!("Unused bytes in custom name section")
while peek_inp!(@@@length@@@) != 0 {
let name_type = run!(byte);
let subsection_size = run!(u32);
if subsection_size > 0 {
let mut inp = inp![..subsection_size as usize];
match name_type {
0 => {
names.module = Some(run_manual!(name(inp)));
},
1 => {
names.functions = run_manual!(vec(inp, function_name)).into_iter().collect();
},
7 => {
names.globals = run_manual!(vec(inp, global_name)).into_iter().collect();
},
_ => {
err!("Unimplemented name type {}", name_type)
},
};
if inp.len() != 0 {
err!("Unused bytes in custom name section")
}
}
}
names
Expand Down Expand Up @@ -833,6 +849,7 @@ generate! { module -> Module = {
module: None,
functions: HashMap::new(),
locals: HashMap::new(),
globals: HashMap::new(),
}
}
};
Expand Down
5 changes: 3 additions & 2 deletions src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub mod syntax {
pub struct TableIdx(pub u32);
#[derive(Copy, Clone, Debug)]
pub struct MemIdx(pub u32);
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct GlobalIdx(pub u32);
#[derive(Copy, Clone, Debug)]
pub struct LocalIdx(pub u32);
Expand Down Expand Up @@ -315,7 +315,8 @@ pub mod syntax {
pub struct Names {
pub module: Option<Name>,
pub functions: std::collections::HashMap<FuncIdx, Name>,
pub locals: std::collections::HashMap<FuncIdx, Vec<Name>>,
pub locals: std::collections::HashMap<LocalIdx, Vec<Name>>,
pub globals: std::collections::HashMap<GlobalIdx, Name>,
}

pub enum FuncInternals {
Expand Down