Skip to content

Commit 57392da

Browse files
committed
Implement click-to-highlight
Highlights registers, instructions, arguments, symbols or addresses on click. Resolves #7
1 parent 2dd3dd6 commit 57392da

File tree

7 files changed

+314
-111
lines changed

7 files changed

+314
-111
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "objdiff"
3-
version = "0.4.4"
3+
version = "0.5.0"
44
edition = "2021"
55
rust-version = "1.65"
66
authors = ["Luke Street <luke@street.dev>"]

src/obj/mips.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pub fn process_code(
9191
reloc: reloc.cloned(),
9292
branch_dest,
9393
line,
94+
orig: None,
9495
});
9596
cur_addr += 4;
9697
}

src/obj/mod.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub struct ObjSection {
3737
pub data_diff: Vec<ObjDataDiff>,
3838
pub match_percent: f32,
3939
}
40+
4041
#[derive(Debug, Clone)]
4142
pub enum ObjInsArg {
4243
PpcArg(ppc750cl::Argument),
@@ -46,6 +47,40 @@ pub enum ObjInsArg {
4647
RelocWithBase,
4748
BranchOffset(i32),
4849
}
50+
51+
// TODO derive PartialEq on ppc750cl::Argument so this isn't necessary
52+
impl PartialEq for ObjInsArg {
53+
fn eq(&self, other: &Self) -> bool {
54+
match (self, other) {
55+
(ObjInsArg::PpcArg(a), ObjInsArg::PpcArg(b)) => {
56+
use ppc750cl::Argument;
57+
match (a, b) {
58+
(Argument::GPR(a), Argument::GPR(b)) => a == b,
59+
(Argument::FPR(a), Argument::FPR(b)) => a == b,
60+
(Argument::SR(a), Argument::SR(b)) => a == b,
61+
(Argument::SPR(a), Argument::SPR(b)) => a == b,
62+
(Argument::CRField(a), Argument::CRField(b)) => a == b,
63+
(Argument::CRBit(a), Argument::CRBit(b)) => a == b,
64+
(Argument::GQR(a), Argument::GQR(b)) => a == b,
65+
(Argument::Uimm(a), Argument::Uimm(b)) => a == b,
66+
(Argument::Simm(a), Argument::Simm(b)) => a == b,
67+
(Argument::Offset(a), Argument::Offset(b)) => a == b,
68+
(Argument::BranchDest(a), Argument::BranchDest(b)) => a == b,
69+
(Argument::Bit(a), Argument::Bit(b)) => a == b,
70+
(Argument::OpaqueU(a), Argument::OpaqueU(b)) => a == b,
71+
(_, _) => false,
72+
}
73+
}
74+
(ObjInsArg::MipsArg(a), ObjInsArg::MipsArg(b)) => a == b,
75+
(ObjInsArg::MipsArgWithBase(a), ObjInsArg::MipsArgWithBase(b)) => a == b,
76+
(ObjInsArg::Reloc, ObjInsArg::Reloc) => true,
77+
(ObjInsArg::RelocWithBase, ObjInsArg::RelocWithBase) => true,
78+
(ObjInsArg::BranchOffset(a), ObjInsArg::BranchOffset(b)) => a == b,
79+
(_, _) => false,
80+
}
81+
}
82+
}
83+
4984
#[derive(Debug, Copy, Clone)]
5085
pub struct ObjInsArgDiff {
5186
/// Incrementing index for coloring
@@ -86,6 +121,8 @@ pub struct ObjIns {
86121
pub branch_dest: Option<u32>,
87122
/// Line info
88123
pub line: Option<u32>,
124+
/// Original (unsimplified) instruction
125+
pub orig: Option<String>,
89126
}
90127
#[derive(Debug, Clone, Default)]
91128
pub struct ObjInsDiff {

src/obj/ppc.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::BTreeMap;
22

33
use anyhow::Result;
4-
use ppc750cl::{disasm_iter, Argument};
4+
use ppc750cl::{disasm_iter, Argument, Ins, SimplifiedIns};
55

66
use crate::obj::{ObjIns, ObjInsArg, ObjReloc, ObjRelocKind};
77

@@ -40,7 +40,7 @@ pub fn process_code(
4040
_ => ins.code,
4141
};
4242
}
43-
let simplified = ins.simplified();
43+
let simplified = ins.clone().simplified();
4444
let mut args: Vec<ObjInsArg> = simplified
4545
.args
4646
.iter()
@@ -86,10 +86,21 @@ pub fn process_code(
8686
mnemonic: format!("{}{}", simplified.mnemonic, simplified.suffix),
8787
args,
8888
reloc: reloc.cloned(),
89-
op: 0,
89+
op: ins.op as u8,
9090
branch_dest: None,
9191
line,
92+
orig: Some(format!("{}", basic_form(ins))),
9293
});
9394
}
9495
Ok((ops, insts))
9596
}
97+
98+
// TODO make public in ppc750cl
99+
fn basic_form(ins: Ins) -> SimplifiedIns {
100+
SimplifiedIns {
101+
mnemonic: ins.op.mnemonic(),
102+
suffix: ins.suffix(),
103+
args: ins.fields().iter().flat_map(|field| field.argument()).collect(),
104+
ins,
105+
}
106+
}

0 commit comments

Comments
 (0)