Build a map from wasm bytecode offset to WAT disassembly text using wasmprinter.
(wasm_bytes: &[u8])
| 696 | |
| 697 | /// Build a map from wasm bytecode offset to WAT disassembly text using wasmprinter. |
| 698 | fn 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). |