Skip to content

Commit 3662c9b

Browse files
committed
Match on Opcode rather than mnemonic string
1 parent 593ccf4 commit 3662c9b

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

objdiff-core/src/arch/ppc.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use object::{
77
elf, File, Object, ObjectSection, ObjectSymbol, Relocation, RelocationFlags, RelocationTarget,
88
Symbol, SymbolKind,
99
};
10-
use ppc750cl::{Argument, InsIter, GPR};
10+
use ppc750cl::{Argument, InsIter, Opcode, GPR};
1111

1212
use crate::{
1313
arch::{DataType, ObjArch, ProcessCodeResult},
@@ -194,19 +194,21 @@ impl ObjArch for ObjArchPpc {
194194
return Some(DataType::String);
195195
}
196196

197-
match instruction.mnemonic.as_str() {
198-
"lbz" | "lbzu" | "lbzux" | "lbzx" => Some(DataType::Int8),
199-
"lhz" | "lhzu" | "lhzux" | "lhzx" => Some(DataType::Int16),
200-
"lha" | "lhau" | "lhaux" | "lhax" => Some(DataType::Int16),
201-
"lwz" | "lwzu" | "lwzux" | "lwzx" => Some(DataType::Int32),
202-
"lfs" | "lfsu" | "lfsux" | "lfsx" => Some(DataType::Float),
203-
"lfd" | "lfdu" | "lfdux" | "lfdx" => Some(DataType::Double),
204-
205-
"stb" | "stbu" | "stbux" | "stbx" => Some(DataType::Int8),
206-
"sth" | "sthu" | "sthux" | "sthx" => Some(DataType::Int16),
207-
"stw" | "stwu" | "stwux" | "stwx" => Some(DataType::Int32),
208-
"stfs" | "stfsu" | "stfsux" | "stfsx" => Some(DataType::Float),
209-
"stfd" | "stfdu" | "stfdux" | "stfdx" => Some(DataType::Double),
197+
// SAFETY: ppc750cl::Opcode is repr(u8) and op is originally obtained on PPC from casting
198+
// an Opcode to a u8 so we know it's a valid value for Opcode.
199+
match unsafe { std::mem::transmute::<u8, Opcode>(instruction.op as u8) } {
200+
Opcode::Lbz | Opcode::Lbzu | Opcode::Lbzux | Opcode::Lbzx => Some(DataType::Int8),
201+
Opcode::Lhz | Opcode::Lhzu | Opcode::Lhzux | Opcode::Lhzx => Some(DataType::Int16),
202+
Opcode::Lha | Opcode::Lhau | Opcode::Lhaux | Opcode::Lhax => Some(DataType::Int16),
203+
Opcode::Lwz | Opcode::Lwzu | Opcode::Lwzux | Opcode::Lwzx => Some(DataType::Int32),
204+
Opcode::Lfs | Opcode::Lfsu | Opcode::Lfsux | Opcode::Lfsx => Some(DataType::Float),
205+
Opcode::Lfd | Opcode::Lfdu | Opcode::Lfdux | Opcode::Lfdx => Some(DataType::Double),
206+
207+
Opcode::Stb | Opcode::Stbu | Opcode::Stbux | Opcode::Stbx => Some(DataType::Int8),
208+
Opcode::Sth | Opcode::Sthu | Opcode::Sthux | Opcode::Sthx => Some(DataType::Int16),
209+
Opcode::Stw | Opcode::Stwu | Opcode::Stwux | Opcode::Stwx => Some(DataType::Int32),
210+
Opcode::Stfs | Opcode::Stfsu | Opcode::Stfsux | Opcode::Stfsx => Some(DataType::Float),
211+
Opcode::Stfd | Opcode::Stfdu | Opcode::Stfdux | Opcode::Stfdx => Some(DataType::Double),
210212
_ => None,
211213
}
212214
}

0 commit comments

Comments
 (0)