Decode extab entries as comment in assembly output

This commit is contained in:
Luke Street 2024-10-03 22:32:19 -06:00
parent 71701b5667
commit 281b0f7104
3 changed files with 30 additions and 2 deletions

2
Cargo.lock generated
View File

@ -395,7 +395,7 @@ dependencies = [
[[package]]
name = "decomp-toolkit"
version = "1.0.0"
version = "1.1.0"
dependencies = [
"anyhow",
"ar",

View File

@ -3,7 +3,7 @@ name = "decomp-toolkit"
description = "Yet another GameCube/Wii decompilation toolkit."
authors = ["Luke Street <luke@street.dev>"]
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"

View File

@ -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<String> {
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>(
w: &mut W,