From 281b0f7104eeb7be1a3fa78a33ce40fbca340909 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Thu, 3 Oct 2024 22:32:19 -0600 Subject: [PATCH] Decode extab entries as comment in assembly output --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/util/asm.rs | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 240005a..a9c7b8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -395,7 +395,7 @@ dependencies = [ [[package]] name = "decomp-toolkit" -version = "1.0.0" +version = "1.1.0" dependencies = [ "anyhow", "ar", diff --git a/Cargo.toml b/Cargo.toml index 4e0cded..5a768dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "decomp-toolkit" description = "Yet another GameCube/Wii decompilation toolkit." authors = ["Luke Street "] license = "MIT OR Apache-2.0" -version = "1.0.0" +version = "1.1.0" edition = "2021" publish = false repository = "https://github.com/encounter/decomp-toolkit" diff --git a/src/util/asm.rs b/src/util/asm.rs index 43d23ec..ac2df16 100644 --- a/src/util/asm.rs +++ b/src/util/asm.rs @@ -432,9 +432,37 @@ where write_symbol_name(w, &symbol.name)?; writeln!(w)?; } + + if entry.kind == SymbolEntryKind::Start && section.name == "extab" { + writeln!(w, "/*")?; + match parse_extab(symbols, entry, section) { + Ok(s) => { + for line in s.trim_end().lines() { + writeln!(w, " * {}", line)?; + } + } + Err(e) => { + log::warn!("Failed to decode extab entry {}: {}", symbol.name, e); + writeln!(w, " * Failed to decode extab entry: {}", e)?; + } + } + writeln!(w, " */")?; + } Ok(()) } +fn parse_extab(symbols: &[ObjSymbol], entry: &SymbolEntry, section: &ObjSection) -> Result { + let symbol = &symbols[entry.index]; + let data = section.symbol_data(symbol)?; + let decoded = cwextab::decode_extab(data)?; + let function_names = section + .relocations + .range(symbol.address as u32..(symbol.address + symbol.size) as u32) + .map(|(_, reloc)| symbols[reloc.target_symbol].name.clone()) + .collect_vec(); + decoded.to_string(function_names).ok_or_else(|| anyhow!("Failed to print extab entry")) +} + #[allow(clippy::too_many_arguments)] fn write_data( w: &mut W,