MCPcopy Index your code
hub / github.com/explodingcamera/tinywasm / run

Function run

crates/cli/src/cmd/dump.rs:9–41  ·  view source on GitHub ↗
(args: ModuleInputArgs)

Source from the content-addressed store, hash-verified

7use crate::load::load_module;
8
9pub fn run(args: ModuleInputArgs) -> Result<()> {
10 let loaded = load_module(&args.module)?;
11 let module = loaded.module;
12
13 let imported_func_count =
14 module.imports.iter().filter(|import| matches!(import.kind, ImportKind::Function(_))).count() as u32;
15
16 for (func_idx, func) in module.funcs.iter().enumerate() {
17 let global_idx = imported_func_count + func_idx as u32;
18
19 let exports = module
20 .exports
21 .iter()
22 .filter(|export| export.kind == ExternalKind::Func && export.index == global_idx)
23 .map(|export| export.name.as_ref())
24 .collect::<Vec<_>>();
25
26 let header = format!("func[{func_idx}]").blue().bold().to_string();
27 if exports.is_empty() {
28 println!("{header}");
29 } else {
30 println!("{header} {}", format!("exports={}", format!("{exports:?}").cyan()).bright_black());
31 }
32
33 for (ip, instr) in func.instructions.iter().enumerate() {
34 let instr = print_instr(instr);
35 println!(" {}: {}", print_ip(ip), instr);
36 }
37 println!();
38 }
39
40 Ok(())
41}
42
43fn print_ip(ip: usize) -> String {
44 let s = format!("{ip:04}");

Callers

nothing calls this directly

Calls 5

load_moduleFunction · 0.85
print_instrFunction · 0.85
mapMethod · 0.80
as_refMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected