Skip to content

Commit

Permalink
Implement click-to-highlight
Browse files Browse the repository at this point in the history
Highlights registers, instructions, arguments, symbols or addresses on click.

Resolves #7
  • Loading branch information
encounter committed Oct 6, 2023
1 parent 2dd3dd6 commit 57392da
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 111 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "objdiff"
version = "0.4.4"
version = "0.5.0"
edition = "2021"
rust-version = "1.65"
authors = ["Luke Street <[email protected]>"]
Expand Down
1 change: 1 addition & 0 deletions src/obj/mips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub fn process_code(
reloc: reloc.cloned(),
branch_dest,
line,
orig: None,
});
cur_addr += 4;
}
Expand Down
37 changes: 37 additions & 0 deletions src/obj/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct ObjSection {
pub data_diff: Vec<ObjDataDiff>,
pub match_percent: f32,
}

#[derive(Debug, Clone)]
pub enum ObjInsArg {
PpcArg(ppc750cl::Argument),
Expand All @@ -46,6 +47,40 @@ pub enum ObjInsArg {
RelocWithBase,
BranchOffset(i32),
}

// TODO derive PartialEq on ppc750cl::Argument so this isn't necessary
impl PartialEq for ObjInsArg {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(ObjInsArg::PpcArg(a), ObjInsArg::PpcArg(b)) => {
use ppc750cl::Argument;
match (a, b) {
(Argument::GPR(a), Argument::GPR(b)) => a == b,
(Argument::FPR(a), Argument::FPR(b)) => a == b,
(Argument::SR(a), Argument::SR(b)) => a == b,
(Argument::SPR(a), Argument::SPR(b)) => a == b,
(Argument::CRField(a), Argument::CRField(b)) => a == b,
(Argument::CRBit(a), Argument::CRBit(b)) => a == b,
(Argument::GQR(a), Argument::GQR(b)) => a == b,
(Argument::Uimm(a), Argument::Uimm(b)) => a == b,
(Argument::Simm(a), Argument::Simm(b)) => a == b,
(Argument::Offset(a), Argument::Offset(b)) => a == b,
(Argument::BranchDest(a), Argument::BranchDest(b)) => a == b,
(Argument::Bit(a), Argument::Bit(b)) => a == b,
(Argument::OpaqueU(a), Argument::OpaqueU(b)) => a == b,
(_, _) => 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
Expand Down Expand Up @@ -86,6 +121,8 @@ pub struct ObjIns {
pub branch_dest: Option<u32>,
/// Line info
pub line: Option<u32>,
/// Original (unsimplified) instruction
pub orig: Option<String>,
}
#[derive(Debug, Clone, Default)]
pub struct ObjInsDiff {
Expand Down
17 changes: 14 additions & 3 deletions src/obj/ppc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::BTreeMap;

use anyhow::Result;
use ppc750cl::{disasm_iter, Argument};
use ppc750cl::{disasm_iter, Argument, Ins, SimplifiedIns};

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

Expand Down Expand Up @@ -40,7 +40,7 @@ pub fn process_code(
_ => ins.code,
};
}
let simplified = ins.simplified();
let simplified = ins.clone().simplified();
let mut args: Vec<ObjInsArg> = simplified
.args
.iter()
Expand Down Expand Up @@ -86,10 +86,21 @@ pub fn process_code(
mnemonic: format!("{}{}", simplified.mnemonic, simplified.suffix),
args,
reloc: reloc.cloned(),
op: 0,
op: ins.op as u8,
branch_dest: None,
line,
orig: Some(format!("{}", basic_form(ins))),
});
}
Ok((ops, insts))
}

// TODO make public in ppc750cl
fn basic_form(ins: Ins) -> SimplifiedIns {
SimplifiedIns {
mnemonic: ins.op.mnemonic(),
suffix: ins.suffix(),
args: ins.fields().iter().flat_map(|field| field.argument()).collect(),
ins,
}
}
Loading

0 comments on commit 57392da

Please sign in to comment.