info/
info.rs

1extern crate sophon_wasm;
2
3use std::env;
4use sophon_wasm::elements::Section;
5
6fn main() {
7    let args = env::args().collect::<Vec<_>>();
8    if args.len() != 2 {
9        println!("Usage: {} somefile.wasm", args[0]);
10        return;
11    }
12
13    let module = sophon_wasm::deserialize_file(&args[1]).expect("Failed to load module");
14
15    println!("Module sections: {}", module.sections().len());
16
17    for section in module.sections() {
18        match *section {
19            Section::Import(ref import_section) => {
20                println!("  Imports: {}", import_section.entries().len());
21                import_section.entries().iter().map(|e| println!("    {}.{}", e.module(), e.field())).count();
22            },
23            Section::Export(ref exports_section) => {
24                println!("  Exports: {}", exports_section.entries().len());
25                exports_section.entries().iter().map(|e| println!("    {}", e.field())).count();
26            },            
27            Section::Function(ref function_section) => {
28                println!("  Functions: {}", function_section.entries().len());
29            },
30            Section::Type(ref type_section) => {
31                println!("  Types: {}", type_section.types().len());
32            },
33            Section::Global(ref globals_section) => {
34                println!("  Globals: {}", globals_section.entries().len());                
35            },
36            Section::Data(ref data_section) if data_section.entries().len() > 0 => {
37                let data = &data_section.entries()[0];
38                println!("  Data size: {}", data.value().len()); 
39            },
40            _ => {},
41        }
42    }
43}