43 lines
1.3 KiB
Rust
Raw Normal View History

2017-03-30 20:55:25 +03:00
extern crate parity_wasm;
use std::env;
2017-04-03 13:58:49 +03:00
use parity_wasm::elements::Section;
2017-03-30 20:55:25 +03:00
fn main() {
2018-01-23 22:47:20 +03:00
let args = env::args().collect::<Vec<_>>();
if args.len() != 2 {
println!("Usage: {} somefile.wasm", args[0]);
return;
}
2017-03-30 20:55:25 +03:00
2018-01-23 22:47:20 +03:00
let module = parity_wasm::deserialize_file(&args[1]).expect("Failed to load module");
2017-03-30 20:55:25 +03:00
2018-01-23 22:47:20 +03:00
println!("Module sections: {}", module.sections().len());
2017-03-30 20:55:25 +03:00
2018-01-23 22:47:20 +03:00
for section in module.sections() {
match *section {
Section::Import(ref import_section) => {
println!(" Imports: {}", import_section.entries().len());
import_section.entries().iter().map(|e| println!(" {}.{}", e.module(), e.field())).count();
},
Section::Export(ref exports_section) => {
println!(" Exports: {}", exports_section.entries().len());
exports_section.entries().iter().map(|e| println!(" {}", e.field())).count();
},
Section::Function(ref function_section) => {
println!(" Functions: {}", function_section.entries().len());
},
Section::Type(ref type_section) => {
println!(" Types: {}", type_section.types().len());
},
Section::Global(ref globals_section) => {
println!(" Globals: {}", globals_section.entries().len());
},
Section::Data(ref data_section) if data_section.entries().len() > 0 => {
let data = &data_section.entries()[0];
println!(" Data size: {}", data.value().len());
},
_ => {},
}
}
2017-03-30 20:55:25 +03:00
}