From 0ec7bf078bc644f5827e82a5acc416c5a334fca6 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Wed, 22 Nov 2023 00:07:21 -0500 Subject: [PATCH] Highlight: Consider reg offsets and signed immediates equivalent Fixes #32 --- src/obj/mod.rs | 24 ++++++++++++++++++++++++ src/views/function_diff.rs | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/obj/mod.rs b/src/obj/mod.rs index e64c416..a923373 100644 --- a/src/obj/mod.rs +++ b/src/obj/mod.rs @@ -50,6 +50,30 @@ pub enum ObjInsArg { BranchOffset(i32), } +impl ObjInsArg { + pub fn loose_eq(&self, other: &ObjInsArg) -> bool { + match (self, other) { + (ObjInsArg::PpcArg(a), ObjInsArg::PpcArg(b)) => { + a == b + || match (a, b) { + // Consider Simm and Offset equivalent + (ppc750cl::Argument::Simm(simm), ppc750cl::Argument::Offset(off)) + | (ppc750cl::Argument::Offset(off), ppc750cl::Argument::Simm(simm)) => { + simm.0 == off.0 + } + _ => false, + } + } + (ObjInsArg::MipsArg(a), ObjInsArg::MipsArg(b)) => a == b, + (ObjInsArg::MipsArgWithBase(a), ObjInsArg::MipsArgWithBase(b)) => a == b, + (ObjInsArg::Reloc, ObjInsArg::Reloc) => true, + (ObjInsArg::RelocWithBase, ObjInsArg::RelocWithBase) => true, + (ObjInsArg::BranchOffset(a), ObjInsArg::BranchOffset(b)) => a == b, + _ => false, + } + } +} + #[derive(Debug, Copy, Clone)] pub struct ObjInsArgDiff { /// Incrementing index for coloring diff --git a/src/views/function_diff.rs b/src/views/function_diff.rs index ee9dee2..2c68b23 100644 --- a/src/views/function_diff.rs +++ b/src/views/function_diff.rs @@ -194,7 +194,7 @@ fn write_ins( HighlightKind::Address(v) => { matches!(arg, ObjInsArg::BranchOffset(offset) if (offset + ins.address as i32 - base_addr as i32) as u32 == *v) } - HighlightKind::Arg(v) => v == arg, + HighlightKind::Arg(v) => v.loose_eq(arg), _ => false, }; let color = if highlighted_arg {