MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / build_wat_offset_map

Function build_wat_offset_map

src/commands/hot_blocks.rs:698–714  ·  view source on GitHub ↗

Build a map from wasm bytecode offset to WAT disassembly text using wasmprinter.

(wasm_bytes: &[u8])

Source from the content-addressed store, hash-verified

696
697/// Build a map from wasm bytecode offset to WAT disassembly text using wasmprinter.
698fn build_wat_offset_map(wasm_bytes: &[u8]) -> BTreeMap<u32, String> {
699 let mut map = BTreeMap::new();
700 let printer = wasmprinter::Config::new();
701 let mut storage = String::new();
702 let Ok(chunks) = printer.offsets_and_lines(wasm_bytes, &mut storage) else {
703 return map;
704 };
705 for (offset, wat_line) in chunks {
706 if let Some(offset) = offset {
707 let trimmed = wat_line.trim();
708 if !trimmed.is_empty() && !trimmed.starts_with('(') && !trimmed.starts_with(')') {
709 map.insert(u32::try_from(offset).unwrap(), trimmed.to_string());
710 }
711 }
712 }
713 map
714}
715
716/// Read CLIF file for a given function, returning pairs of
717/// (wasm_offset, clif_line).

Callers 2

executeMethod · 0.85
test_wat_offset_mapFunction · 0.85

Calls 5

newFunction · 0.50
is_emptyMethod · 0.45
insertMethod · 0.45
unwrapMethod · 0.45
to_stringMethod · 0.45

Tested by 1

test_wat_offset_mapFunction · 0.68