43 lines
1.6 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() {
let args = env::args().collect::<Vec<_>>();
if args.len() != 2 {
println!("Usage: {} somefile.wasm", args[0]);
return;
}
let module = parity_wasm::deserialize_file(&args[1]).expect("Failed to load module");
println!("Module sections: {}", module.sections().len());
for section in module.sections() {
2017-07-20 18:31:15 +03:00
match *section {
Section::Import(ref import_section) => {
2017-03-31 17:31:33 +03:00
println!(" Imports: {}", import_section.entries().len());
2017-07-20 18:31:15 +03:00
import_section.entries().iter().map(|e| println!(" {}.{}", e.module(), e.field())).count();
2017-03-30 20:55:25 +03:00
},
2017-07-20 18:31:15 +03:00
Section::Export(ref exports_section) => {
2017-03-31 17:31:33 +03:00
println!(" Exports: {}", exports_section.entries().len());
2017-07-20 18:31:15 +03:00
exports_section.entries().iter().map(|e| println!(" {}", e.field())).count();
2017-03-31 01:54:04 +03:00
},
2017-07-20 18:31:15 +03:00
Section::Function(ref function_section) => {
println!(" Functions: {}", function_section.entries().len());
2017-03-31 17:31:33 +03:00
},
2017-07-20 18:31:15 +03:00
Section::Type(ref type_section) => {
2017-07-13 15:07:13 +03:00
println!(" Types: {}", type_section.types().len());
},
2017-07-20 18:31:15 +03:00
Section::Global(ref globals_section) => {
2017-03-31 17:31:33 +03:00
println!(" Globals: {}", globals_section.entries().len());
2017-03-30 23:23:54 +03:00
},
2017-07-20 18:31:15 +03:00
Section::Data(ref data_section) if data_section.entries().len() > 0 => {
2017-04-03 13:47:09 +03:00
let data = &data_section.entries()[0];
println!(" Data size: {}", data.value().len());
},
2017-03-30 20:55:25 +03:00
_ => {},
}
}
}