Fix branch immediates missing diff colors

Resolves #86
This commit is contained in:
Luke Street 2024-08-11 14:01:53 -06:00
parent e1ccee1e73
commit 177bd5e895
3 changed files with 15 additions and 7 deletions

View File

@ -750,8 +750,11 @@ impl FunctionDiffUi {
base_color = COLOR_ROTATION[diff.idx % COLOR_ROTATION.len()] base_color = COLOR_ROTATION[diff.idx % COLOR_ROTATION.len()]
} }
} }
DiffText::BranchDest(addr) => { DiffText::BranchDest(addr, diff) => {
label_text = format!("{addr:x}"); label_text = format!("{addr:x}");
if let Some(diff) = diff {
base_color = COLOR_ROTATION[diff.idx % COLOR_ROTATION.len()]
}
} }
DiffText::Symbol(sym) => { DiffText::Symbol(sym) => {
let name = sym.demangled_name.as_ref().unwrap_or(&sym.name); let name = sym.demangled_name.as_ref().unwrap_or(&sym.name);

View File

@ -20,7 +20,7 @@ pub enum DiffText<'a> {
/// Instruction argument /// Instruction argument
Argument(&'a ObjInsArgValue, Option<&'a ObjInsArgDiff>), Argument(&'a ObjInsArgValue, Option<&'a ObjInsArgDiff>),
/// Branch destination /// Branch destination
BranchDest(u64), BranchDest(u64, Option<&'a ObjInsArgDiff>),
/// Symbol name /// Symbol name
Symbol(&'a ObjSymbol), Symbol(&'a ObjSymbol),
/// Number of spaces /// Number of spaces
@ -62,12 +62,12 @@ pub fn display_diff<E>(
if i == 0 { if i == 0 {
cb(DiffText::Spacing(1))?; cb(DiffText::Spacing(1))?;
} }
let diff = ins_diff.arg_diff.get(i).and_then(|o| o.as_ref());
match arg { match arg {
ObjInsArg::PlainText(s) => { ObjInsArg::PlainText(s) => {
cb(DiffText::Basic(s))?; cb(DiffText::Basic(s))?;
} }
ObjInsArg::Arg(v) => { ObjInsArg::Arg(v) => {
let diff = ins_diff.arg_diff.get(i).and_then(|o| o.as_ref());
cb(DiffText::Argument(v, diff))?; cb(DiffText::Argument(v, diff))?;
} }
ObjInsArg::Reloc => { ObjInsArg::Reloc => {
@ -75,7 +75,7 @@ pub fn display_diff<E>(
} }
ObjInsArg::BranchDest(dest) => { ObjInsArg::BranchDest(dest) => {
if let Some(dest) = dest.checked_sub(base_addr) { if let Some(dest) = dest.checked_sub(base_addr) {
cb(DiffText::BranchDest(dest))?; cb(DiffText::BranchDest(dest, diff))?;
} else { } else {
cb(DiffText::Basic("<unknown>"))?; cb(DiffText::Basic("<unknown>"))?;
} }
@ -107,7 +107,9 @@ impl PartialEq<DiffText<'_>> for HighlightKind {
(HighlightKind::Opcode(a), DiffText::Opcode(_, b)) => a == b, (HighlightKind::Opcode(a), DiffText::Opcode(_, b)) => a == b,
(HighlightKind::Arg(a), DiffText::Argument(b, _)) => a.loose_eq(b), (HighlightKind::Arg(a), DiffText::Argument(b, _)) => a.loose_eq(b),
(HighlightKind::Symbol(a), DiffText::Symbol(b)) => a == &b.name, (HighlightKind::Symbol(a), DiffText::Symbol(b)) => a == &b.name,
(HighlightKind::Address(a), DiffText::Address(b) | DiffText::BranchDest(b)) => a == b, (HighlightKind::Address(a), DiffText::Address(b) | DiffText::BranchDest(b, _)) => {
a == b
}
_ => false, _ => false,
} }
} }
@ -123,7 +125,7 @@ impl From<DiffText<'_>> for HighlightKind {
DiffText::Opcode(_, op) => HighlightKind::Opcode(op), DiffText::Opcode(_, op) => HighlightKind::Opcode(op),
DiffText::Argument(arg, _) => HighlightKind::Arg(arg.clone()), DiffText::Argument(arg, _) => HighlightKind::Arg(arg.clone()),
DiffText::Symbol(sym) => HighlightKind::Symbol(sym.name.to_string()), DiffText::Symbol(sym) => HighlightKind::Symbol(sym.name.to_string()),
DiffText::Address(addr) | DiffText::BranchDest(addr) => HighlightKind::Address(addr), DiffText::Address(addr) | DiffText::BranchDest(addr, _) => HighlightKind::Address(addr),
_ => HighlightKind::None, _ => HighlightKind::None,
} }
} }

View File

@ -216,8 +216,11 @@ fn diff_text_ui(
base_color = appearance.diff_colors[diff.idx % appearance.diff_colors.len()] base_color = appearance.diff_colors[diff.idx % appearance.diff_colors.len()]
} }
} }
DiffText::BranchDest(addr) => { DiffText::BranchDest(addr, diff) => {
label_text = format!("{addr:x}"); label_text = format!("{addr:x}");
if let Some(diff) = diff {
base_color = appearance.diff_colors[diff.idx % appearance.diff_colors.len()]
}
} }
DiffText::Symbol(sym) => { DiffText::Symbol(sym) => {
let name = sym.demangled_name.as_ref().unwrap_or(&sym.name); let name = sym.demangled_name.as_ref().unwrap_or(&sym.name);