Skip to content

Commit 8bf0629

Browse files
committed
Formatting
1 parent ad01306 commit 8bf0629

File tree

10 files changed

+65
-64
lines changed

10 files changed

+65
-64
lines changed

objdiff-core/src/arch/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
use alloc::{borrow::Cow, boxed::Box, format, string::String, vec::Vec};
2-
use core::{ffi::CStr, fmt::{self, Debug}};
2+
use core::{
3+
ffi::CStr,
4+
fmt::{self, Debug},
5+
};
36

47
use anyhow::{Result, bail};
58
use encoding_rs::SHIFT_JIS;
69
use object::Endian as _;
710

811
use crate::{
912
diff::{
10-
display::{ContextItem, HoverItem, InstructionPart}, DiffObjConfig
13+
DiffObjConfig,
14+
display::{ContextItem, HoverItem, InstructionPart},
1115
},
1216
obj::{
13-
FlowAnalysisResult, InstructionArg, InstructionRef, Object, ParsedInstruction, Relocation, RelocationFlags, ResolvedInstructionRef, ResolvedSymbol, Section, Symbol, SymbolFlagSet, SymbolKind
17+
FlowAnalysisResult, InstructionArg, InstructionRef, Object, ParsedInstruction, Relocation,
18+
RelocationFlags, ResolvedInstructionRef, ResolvedSymbol, Section, Symbol, SymbolFlagSet,
19+
SymbolKind,
1420
},
1521
util::ReallySigned,
1622
};

objdiff-core/src/arch/ppc/flow_analysis.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1+
use alloc::{
2+
boxed::Box,
3+
collections::{BTreeMap, BTreeSet},
4+
format,
5+
string::String,
6+
vec::Vec,
7+
};
8+
use core::{
9+
ffi::CStr,
10+
ops::{Index, IndexMut},
11+
};
12+
13+
use itertools::Itertools;
14+
use ppc750cl::Simm;
15+
116
use crate::{
217
arch::DataType,
318
obj::{FlowAnalysisResult, FlowAnalysisValue, Object, Relocation, Symbol},
419
util::{RawDouble, RawFloat},
520
};
6-
use alloc::collections::{BTreeMap, BTreeSet};
7-
use alloc::{boxed::Box, format, string::String, vec::Vec};
8-
use core::ffi::CStr;
9-
use core::ops::{Index, IndexMut};
10-
use itertools::Itertools;
11-
use ppc750cl::Simm;
1221

1322
fn is_store_instruction(op: ppc750cl::Opcode) -> bool {
1423
use ppc750cl::Opcode;
@@ -165,9 +174,8 @@ impl RegisterState {
165174

166175
impl Index<ppc750cl::GPR> for RegisterState {
167176
type Output = RegisterContent;
168-
fn index(&self, gpr: ppc750cl::GPR) -> &Self::Output {
169-
&self.gpr[gpr.0 as usize]
170-
}
177+
178+
fn index(&self, gpr: ppc750cl::GPR) -> &Self::Output { &self.gpr[gpr.0 as usize] }
171179
}
172180
impl IndexMut<ppc750cl::GPR> for RegisterState {
173181
fn index_mut(&mut self, gpr: ppc750cl::GPR) -> &mut Self::Output {
@@ -177,9 +185,8 @@ impl IndexMut<ppc750cl::GPR> for RegisterState {
177185

178186
impl Index<ppc750cl::FPR> for RegisterState {
179187
type Output = RegisterContent;
180-
fn index(&self, fpr: ppc750cl::FPR) -> &Self::Output {
181-
&self.fpr[fpr.0 as usize]
182-
}
188+
189+
fn index(&self, fpr: ppc750cl::FPR) -> &Self::Output { &self.fpr[fpr.0 as usize] }
183190
}
184191
impl IndexMut<ppc750cl::FPR> for RegisterState {
185192
fn index_mut(&mut self, fpr: ppc750cl::FPR) -> &mut Self::Output {
@@ -296,9 +303,7 @@ impl PPCFlowAnalysisResult {
296303
self.argument_contents.insert((address, argument), value);
297304
}
298305

299-
fn new() -> Self {
300-
PPCFlowAnalysisResult { argument_contents: Default::default() }
301-
}
306+
fn new() -> Self { PPCFlowAnalysisResult { argument_contents: Default::default() } }
302307
}
303308

304309
impl FlowAnalysisResult for PPCFlowAnalysisResult {
@@ -372,9 +377,7 @@ fn fill_registers_from_relocation(
372377
// See: https://github.com/encounter/decomp-toolkit/blob/main/src/analysis/pass.rs
373378
const SLEDS: [&str; 6] = ["_savefpr_", "_restfpr_", "_savegpr_", "_restgpr_", "_savev", "_restv"];
374379

375-
fn is_sled_function(name: &str) -> bool {
376-
SLEDS.iter().any(|sled| name.starts_with(sled))
377-
}
380+
fn is_sled_function(name: &str) -> bool { SLEDS.iter().any(|sled| name.starts_with(sled)) }
378381

379382
pub fn ppc_data_flow_analysis(
380383
obj: &Object,
@@ -383,6 +386,7 @@ pub fn ppc_data_flow_analysis(
383386
relocations: &[Relocation],
384387
) -> Box<dyn FlowAnalysisResult> {
385388
use alloc::collections::VecDeque;
389+
386390
use ppc750cl::InsIter;
387391
let instructions = InsIter::new(code, func_symbol.address as u32)
388392
.map(|(_addr, ins)| (ins.op, ins.basic().args))

objdiff-core/src/arch/ppc/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use alloc::{
2+
boxed::Box,
23
collections::{BTreeMap, BTreeSet},
34
string::{String, ToString},
45
vec,
56
vec::Vec,
6-
boxed::Box,
77
};
88

99
use anyhow::{Result, bail, ensure};
@@ -20,7 +20,7 @@ use crate::{
2020
},
2121
obj::{
2222
FlowAnalysisResult, InstructionRef, Object, Relocation, RelocationFlags,
23-
ResolvedInstructionRef, ResolvedRelocation, Symbol, SymbolFlag, SymbolFlagSet
23+
ResolvedInstructionRef, ResolvedRelocation, Symbol, SymbolFlag, SymbolFlagSet,
2424
},
2525
};
2626

@@ -170,7 +170,7 @@ impl Arch for ArchPpc {
170170
) -> Vec<Relocation> {
171171
generate_fake_pool_relocations_for_function(address, code, relocations, symbols)
172172
}
173-
173+
174174
fn data_flow_analysis(
175175
&self,
176176
obj: &Object,

objdiff-core/src/diff/display.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ use itertools::Itertools;
1212
use regex::Regex;
1313

1414
use crate::{
15-
diff::{DiffObjConfig, InstructionDiffKind, InstructionDiffRow, ObjectDiff, SymbolDiff}, obj::{
16-
FlowAnalysisValue, InstructionArg, InstructionArgValue, Object, ParsedInstruction, ResolvedInstructionRef, ResolvedRelocation, SectionFlag, SectionKind, Symbol, SymbolFlag, SymbolKind
17-
}
15+
diff::{DiffObjConfig, InstructionDiffKind, InstructionDiffRow, ObjectDiff, SymbolDiff},
16+
obj::{
17+
FlowAnalysisValue, InstructionArg, InstructionArgValue, Object, ParsedInstruction,
18+
ResolvedInstructionRef, ResolvedRelocation, SectionFlag, SectionKind, Symbol, SymbolFlag,
19+
SymbolKind,
20+
},
1821
};
1922

2023
#[derive(Debug, Clone)]
@@ -44,7 +47,7 @@ pub enum DiffText<'a> {
4447
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, Hash)]
4548
pub enum DiffTextColor {
4649
#[default]
47-
Normal, // Grey
50+
Normal, // Grey
4851
Dim, // Dark grey
4952
Bright, // White
5053
DataFlow, // Light blue

objdiff-core/src/obj/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,12 @@ pub enum FlowAnalysisValue {
238238
Text(String),
239239
}
240240

241-
pub trait FlowAnalysisResult : core::fmt::Debug + Send {
242-
fn get_argument_value_at_address(&self, address: u64, argument: u8) -> Option<&FlowAnalysisValue>;
241+
pub trait FlowAnalysisResult: core::fmt::Debug + Send {
242+
fn get_argument_value_at_address(
243+
&self,
244+
address: u64,
245+
argument: u8,
246+
) -> Option<&FlowAnalysisValue>;
243247
}
244248

245249
#[derive(Debug, Clone, Eq, PartialEq, Hash, Default)]
@@ -323,10 +327,8 @@ impl Object {
323327
pub fn symbol_by_name(&self, name: &str) -> Option<usize> {
324328
self.symbols.iter().position(|symbol| symbol.section.is_some() && symbol.name == name)
325329
}
326-
327-
pub fn has_flow_analysis_result(&self) -> bool {
328-
!self.flow_analysis_results.is_empty()
329-
}
330+
331+
pub fn has_flow_analysis_result(&self) -> bool { !self.flow_analysis_results.is_empty() }
330332
}
331333

332334
#[derive(Debug, Clone, Eq, PartialEq, Hash)]

objdiff-core/src/obj/read.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -467,20 +467,16 @@ fn perform_data_flow_analysis(obj: &mut Object, config: &DiffObjConfig) -> Resul
467467
symbol.address,
468468
code,
469469
&section.relocations,
470-
&obj.symbols);
470+
&obj.symbols,
471+
);
471472
generated_relocations.push((section_index, relocations));
472473
}
473474

474475
// Optional full data flow analysis
475476
if config.analyze_data_flow {
476-
obj.arch.data_flow_analysis(
477-
&obj,
478-
symbol,
479-
code,
480-
&section.relocations,
481-
).and_then(|flow_result| {
482-
obj.flow_analysis_results.insert(symbol.address, flow_result)
483-
});
477+
obj.arch.data_flow_analysis(&obj, symbol, code, &section.relocations).and_then(
478+
|flow_result| obj.flow_analysis_results.insert(symbol.address, flow_result),
479+
);
484480
}
485481
}
486482
}

objdiff-core/src/util.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,39 +65,27 @@ pub fn align_data_slice_to(data: &mut Vec<u8>, align: u64) {
6565
#[derive(Copy, Clone, Debug)]
6666
pub struct RawFloat(pub f32);
6767
impl PartialEq for RawFloat {
68-
fn eq(&self, other: &Self) -> bool {
69-
self.0.to_bits() == other.0.to_bits()
70-
}
68+
fn eq(&self, other: &Self) -> bool { self.0.to_bits() == other.0.to_bits() }
7169
}
7270
impl Eq for RawFloat {}
7371
impl Ord for RawFloat {
74-
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
75-
self.0.to_bits().cmp(&other.0.to_bits())
76-
}
72+
fn cmp(&self, other: &Self) -> core::cmp::Ordering { self.0.to_bits().cmp(&other.0.to_bits()) }
7773
}
7874
impl PartialOrd for RawFloat {
79-
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
80-
Some(self.cmp(other))
81-
}
75+
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> { Some(self.cmp(other)) }
8276
}
8377

8478
// Double where we specifically care about comparing the raw bits rather than
8579
// caring about IEEE semantics.
8680
#[derive(Copy, Clone, Debug)]
8781
pub struct RawDouble(pub f64);
8882
impl PartialEq for RawDouble {
89-
fn eq(&self, other: &Self) -> bool {
90-
self.0.to_bits() == other.0.to_bits()
91-
}
83+
fn eq(&self, other: &Self) -> bool { self.0.to_bits() == other.0.to_bits() }
9284
}
9385
impl Eq for RawDouble {}
9486
impl Ord for RawDouble {
95-
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
96-
self.0.to_bits().cmp(&other.0.to_bits())
97-
}
87+
fn cmp(&self, other: &Self) -> core::cmp::Ordering { self.0.to_bits().cmp(&other.0.to_bits()) }
9888
}
9989
impl PartialOrd for RawDouble {
100-
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
101-
Some(self.cmp(other))
102-
}
90+
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> { Some(self.cmp(other)) }
10391
}

objdiff-gui/src/views/appearance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct Appearance {
2323
#[serde(skip)]
2424
pub highlight_color: Color32, // WHITE
2525
#[serde(skip)]
26-
pub dataflow_color: Color32, //
26+
pub dataflow_color: Color32, //
2727
#[serde(skip)]
2828
pub replace_color: Color32, // LIGHT_BLUE
2929
#[serde(skip)]

objdiff-gui/src/views/diff.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ pub fn diff_view_ui(
284284

285285
// Only need to check the first Object. Technically the first could not have a flow analysis
286286
// result while the second does but we don't want to waste space on two separate checkboxes.
287-
if result.first_obj.as_ref().is_some_and(|(first, _)| first.has_flow_analysis_result()) {
287+
if result.first_obj.as_ref().is_some_and(|(first, _)| first.has_flow_analysis_result())
288+
{
288289
let mut placeholder = diff_config.show_data_flow;
289290
if ui
290291
.checkbox(&mut placeholder, "Show data flow")

objdiff-gui/src/views/symbol_diff.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ impl DiffViewState {
356356
let Ok(mut state) = state.write() else {
357357
return;
358358
};
359-
state.config.diff_obj_config.show_data_flow = !state.config.diff_obj_config.show_data_flow;
359+
state.config.diff_obj_config.show_data_flow =
360+
!state.config.diff_obj_config.show_data_flow;
360361
}
361362
}
362363
}

0 commit comments

Comments
 (0)