Skip to content

Commit 71bd6ab

Browse files
committed
Move DiffSide to diff mod
1 parent 1ddd46a commit 71bd6ab

File tree

12 files changed

+62
-50
lines changed

12 files changed

+62
-50
lines changed

objdiff-cli/src/cmd/report.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use objdiff_core::{
99
},
1010
config::path::platform_path,
1111
diff,
12-
obj::{self, DiffSide, SectionKind, SymbolFlag},
12+
obj::{self, SectionKind, SymbolFlag},
1313
};
1414
use prost::Message;
1515
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
@@ -177,15 +177,15 @@ fn report_object(
177177
.target_path
178178
.as_ref()
179179
.map(|p| {
180-
obj::read::read(p.as_ref(), diff_config, DiffSide::Target)
180+
obj::read::read(p.as_ref(), diff_config, diff::DiffSide::Target)
181181
.with_context(|| format!("Failed to open {p}"))
182182
})
183183
.transpose()?;
184184
let base = object
185185
.base_path
186186
.as_ref()
187187
.map(|p| {
188-
obj::read::read(p.as_ref(), diff_config, DiffSide::Base)
188+
obj::read::read(p.as_ref(), diff_config, diff::DiffSide::Base)
189189
.with_context(|| format!("Failed to open {p}"))
190190
})
191191
.transpose()?;

objdiff-core/src/arch/mips.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use rabbitizer::{
1212

1313
use crate::{
1414
arch::{Arch, RelocationOverride, RelocationOverrideTarget},
15-
diff::{DiffObjConfig, MipsAbi, MipsInstrCategory, display::InstructionPart},
15+
diff::{DiffObjConfig, DiffSide, MipsAbi, MipsInstrCategory, display::InstructionPart},
1616
obj::{
17-
DiffSide, InstructionArg, InstructionArgValue, InstructionRef, Relocation, RelocationFlags,
17+
InstructionArg, InstructionArgValue, InstructionRef, Relocation, RelocationFlags,
1818
ResolvedInstructionRef, ResolvedRelocation, Section, Symbol, SymbolFlag, SymbolFlagSet,
1919
},
2020
};

objdiff-core/src/arch/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ use object::Endian as _;
1717

1818
use crate::{
1919
diff::{
20-
DiffObjConfig,
20+
DiffObjConfig, DiffSide,
2121
display::{ContextItem, HoverItem, InstructionPart},
2222
},
2323
obj::{
24-
DiffSide, FlowAnalysisResult, InstructionArg, InstructionRef, Object, ParsedInstruction,
25-
Relocation, RelocationFlags, ResolvedInstructionRef, ResolvedSymbol, Section, Symbol,
26-
SymbolFlagSet, SymbolKind,
24+
FlowAnalysisResult, InstructionArg, InstructionRef, Object, ParsedInstruction, Relocation,
25+
RelocationFlags, ResolvedInstructionRef, ResolvedSymbol, Section, Symbol, SymbolFlagSet,
26+
SymbolKind,
2727
},
2828
util::ReallySigned,
2929
};

objdiff-core/src/diff/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,3 +807,11 @@ fn find_section(
807807
s.kind == section_kind && s.name == name && !matches.iter().any(|m| m.right == Some(i))
808808
})
809809
}
810+
811+
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
812+
pub enum DiffSide {
813+
/// The target/expected side of the diff.
814+
Target,
815+
/// The base side of the diff.
816+
Base,
817+
}

objdiff-core/src/jobs/objdiff.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use typed_path::Utf8PlatformPathBuf;
66

77
use crate::{
88
build::{BuildConfig, BuildStatus, run_make},
9-
diff::{DiffObjConfig, MappingConfig, ObjectDiff, diff_objs},
9+
diff::{DiffObjConfig, DiffSide, MappingConfig, ObjectDiff, diff_objs},
1010
jobs::{Job, JobContext, JobResult, JobState, start_job, update_status},
11-
obj::{DiffSide, Object, read},
11+
obj::{Object, read},
1212
};
1313

1414
pub struct ObjDiffConfig {

objdiff-core/src/obj/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,3 @@ impl Default for ResolvedInstructionRef<'_> {
437437
}
438438
}
439439
}
440-
441-
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
442-
pub enum DiffSide {
443-
/// The target/expected side of the diff.
444-
Target,
445-
/// The base side of the diff.
446-
Base,
447-
}

objdiff-core/src/obj/read.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use object::{Object as _, ObjectSection as _, ObjectSymbol as _};
1212

1313
use crate::{
1414
arch::{Arch, RelocationOverride, RelocationOverrideTarget, new_arch},
15-
diff::DiffObjConfig,
15+
diff::{DiffObjConfig, DiffSide},
1616
obj::{
17-
DiffSide, FlowAnalysisResult, Object, Relocation, RelocationFlags, Section, SectionData,
18-
SectionFlag, SectionKind, Symbol, SymbolFlag, SymbolKind,
17+
FlowAnalysisResult, Object, Relocation, RelocationFlags, Section, SectionData, SectionFlag,
18+
SectionKind, Symbol, SymbolFlag, SymbolKind,
1919
split_meta::{SPLITMETA_SECTION, SplitMeta},
2020
},
2121
util::{align_data_slice_to, align_u64_to, read_u16, read_u32},

objdiff-core/tests/arch_arm.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn read_arm() {
99
let obj = obj::read::parse(
1010
include_object!("data/arm/LinkStateItem.o"),
1111
&diff_config,
12-
obj::DiffSide::Base,
12+
diff::DiffSide::Base,
1313
)
1414
.unwrap();
1515
insta::assert_debug_snapshot!(obj);
@@ -26,7 +26,7 @@ fn read_arm() {
2626
fn read_thumb() {
2727
let diff_config = diff::DiffObjConfig { ..Default::default() };
2828
let obj =
29-
obj::read::parse(include_object!("data/arm/thumb.o"), &diff_config, obj::DiffSide::Base)
29+
obj::read::parse(include_object!("data/arm/thumb.o"), &diff_config, diff::DiffSide::Base)
3030
.unwrap();
3131
insta::assert_debug_snapshot!(obj);
3232
let symbol_idx = obj
@@ -44,9 +44,12 @@ fn read_thumb() {
4444
#[cfg(feature = "arm")]
4545
fn combine_text_sections() {
4646
let diff_config = diff::DiffObjConfig { combine_text_sections: true, ..Default::default() };
47-
let obj =
48-
obj::read::parse(include_object!("data/arm/enemy300.o"), &diff_config, obj::DiffSide::Base)
49-
.unwrap();
47+
let obj = obj::read::parse(
48+
include_object!("data/arm/enemy300.o"),
49+
&diff_config,
50+
diff::DiffSide::Base,
51+
)
52+
.unwrap();
5053
let symbol_idx = obj.symbols.iter().position(|s| s.name == "Enemy300Draw").unwrap();
5154
let diff = diff::code::no_diff_code(&obj, symbol_idx, &diff_config).unwrap();
5255
insta::assert_debug_snapshot!(diff.instruction_rows);

objdiff-core/tests/arch_mips.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod common;
77
fn read_mips() {
88
let diff_config = diff::DiffObjConfig { mips_register_prefix: true, ..Default::default() };
99
let obj =
10-
obj::read::parse(include_object!("data/mips/main.c.o"), &diff_config, obj::DiffSide::Base)
10+
obj::read::parse(include_object!("data/mips/main.c.o"), &diff_config, diff::DiffSide::Base)
1111
.unwrap();
1212
insta::assert_debug_snapshot!(obj);
1313
let symbol_idx = obj.symbols.iter().position(|s| s.name == "ControlEntry").unwrap();
@@ -21,13 +21,19 @@ fn read_mips() {
2121
#[cfg(feature = "mips")]
2222
fn cross_endian_diff() {
2323
let diff_config = diff::DiffObjConfig::default();
24-
let obj_be =
25-
obj::read::parse(include_object!("data/mips/code_be.o"), &diff_config, obj::DiffSide::Base)
26-
.unwrap();
24+
let obj_be = obj::read::parse(
25+
include_object!("data/mips/code_be.o"),
26+
&diff_config,
27+
diff::DiffSide::Base,
28+
)
29+
.unwrap();
2730
assert_eq!(obj_be.endianness, object::Endianness::Big);
28-
let obj_le =
29-
obj::read::parse(include_object!("data/mips/code_le.o"), &diff_config, obj::DiffSide::Base)
30-
.unwrap();
31+
let obj_le = obj::read::parse(
32+
include_object!("data/mips/code_le.o"),
33+
&diff_config,
34+
diff::DiffSide::Base,
35+
)
36+
.unwrap();
3137
assert_eq!(obj_le.endianness, object::Endianness::Little);
3238
let left_symbol_idx = obj_be.symbols.iter().position(|s| s.name == "func_00000000").unwrap();
3339
let right_symbol_idx =
@@ -51,7 +57,7 @@ fn filter_non_matching() {
5157
let obj = obj::read::parse(
5258
include_object!("data/mips/vw_main.c.o"),
5359
&diff_config,
54-
obj::DiffSide::Base,
60+
diff::DiffSide::Base,
5561
)
5662
.unwrap();
5763
insta::assert_debug_snapshot!(obj.symbols);

objdiff-core/tests/arch_ppc.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mod common;
1111
fn read_ppc() {
1212
let diff_config = diff::DiffObjConfig::default();
1313
let obj =
14-
obj::read::parse(include_object!("data/ppc/IObj.o"), &diff_config, obj::DiffSide::Base)
14+
obj::read::parse(include_object!("data/ppc/IObj.o"), &diff_config, diff::DiffSide::Base)
1515
.unwrap();
1616
insta::assert_debug_snapshot!(obj);
1717
let symbol_idx =
@@ -29,7 +29,7 @@ fn read_dwarf1_line_info() {
2929
let obj = obj::read::parse(
3030
include_object!("data/ppc/m_Do_hostIO.o"),
3131
&diff_config,
32-
obj::DiffSide::Base,
32+
diff::DiffSide::Base,
3333
)
3434
.unwrap();
3535
let line_infos = obj
@@ -48,7 +48,7 @@ fn read_extab() {
4848
let obj = obj::read::parse(
4949
include_object!("data/ppc/NMWException.o"),
5050
&diff_config,
51-
obj::DiffSide::Base,
51+
diff::DiffSide::Base,
5252
)
5353
.unwrap();
5454
insta::assert_debug_snapshot!(obj);
@@ -62,13 +62,13 @@ fn diff_ppc() {
6262
let target_obj = obj::read::parse(
6363
include_object!("data/ppc/CDamageVulnerability_target.o"),
6464
&diff_config,
65-
obj::DiffSide::Target,
65+
diff::DiffSide::Target,
6666
)
6767
.unwrap();
6868
let base_obj = obj::read::parse(
6969
include_object!("data/ppc/CDamageVulnerability_base.o"),
7070
&diff_config,
71-
obj::DiffSide::Base,
71+
diff::DiffSide::Base,
7272
)
7373
.unwrap();
7474
let diff =
@@ -108,9 +108,12 @@ fn diff_ppc() {
108108
#[cfg(feature = "ppc")]
109109
fn read_vmx128_coff() {
110110
let diff_config = diff::DiffObjConfig { combine_data_sections: true, ..Default::default() };
111-
let obj =
112-
obj::read::parse(include_object!("data/ppc/vmx128.obj"), &diff_config, obj::DiffSide::Base)
113-
.unwrap();
111+
let obj = obj::read::parse(
112+
include_object!("data/ppc/vmx128.obj"),
113+
&diff_config,
114+
diff::DiffSide::Base,
115+
)
116+
.unwrap();
114117
insta::assert_debug_snapshot!(obj);
115118
let symbol_idx =
116119
obj.symbols.iter().position(|s| s.name == "?FloatingPointExample@@YAXXZ").unwrap();

0 commit comments

Comments
 (0)