mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-03-15 11:10:49 +00:00
func and tests
This commit is contained in:
parent
ba45e15567
commit
be40285a67
30
src/graph.rs
30
src/graph.rs
@ -116,6 +116,15 @@ impl Module {
|
||||
};
|
||||
}
|
||||
},
|
||||
elements::Section::Function(function_section) => {
|
||||
for f in function_section.entries() {
|
||||
res.funcs.push(Func {
|
||||
type_ref: res.types.get(f.type_ref() as usize).expect("validated; qed").clone(),
|
||||
// code will be populated later
|
||||
origin: ImportedOrDeclared::Declared(Vec::new()),
|
||||
});
|
||||
};
|
||||
},
|
||||
_ => continue,
|
||||
}
|
||||
}
|
||||
@ -125,7 +134,28 @@ impl Module {
|
||||
|
||||
}
|
||||
|
||||
fn parse(wasm: &[u8]) -> Module {
|
||||
Module::from_elements(&::parity_wasm::deserialize_buffer(wasm).expect("failed to parse wasm"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
extern crate wabt;
|
||||
use parity_wasm;
|
||||
|
||||
#[test]
|
||||
fn smoky() {
|
||||
let wasm = wabt::wat2wasm(r#"
|
||||
(module
|
||||
(type (func))
|
||||
(func (type 0))
|
||||
)
|
||||
"#).expect("Failed to read fixture");
|
||||
|
||||
let f = super::parse(&wasm[..]);
|
||||
|
||||
assert_eq!(f.types.len(), 1);
|
||||
assert_eq!(f.funcs.len(), 1);
|
||||
}
|
||||
}
|
@ -144,6 +144,10 @@ impl<T> RefList<T> {
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.items.len()
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
Loading…
x
Reference in New Issue
Block a user