Skip to content

Commit ec062bf

Browse files
authored
User rabbitizer crate (#22)
* Start using rabbitizer crate * Fix reference problem * bump rabbitizer version
1 parent 500965a commit ec062bf

File tree

3 files changed

+24
-186
lines changed

3 files changed

+24
-186
lines changed

Cargo.lock

Lines changed: 5 additions & 173 deletions
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
@@ -32,7 +32,7 @@ notify = "5.0.0"
3232
object = { version = "0.30.2", features = ["read_core", "std", "elf"], default-features = false }
3333
png = "0.17.7"
3434
ppc750cl = { git = "https://github.com/terorie/ppc750cl", rev = "9ae36eef34aa6d74e00972c7671f547a2acfd0aa" }
35-
rabbitizer = { git = "https://github.com/encounter/rabbitizer-rs", rev = "10c279b2ef251c62885b1dcdcfe740b0db8e9956" }
35+
rabbitizer = "1.5.7"
3636
rfd = { version = "0.10.0" } #, default-features = false, features = ['xdg-portal']
3737
serde = { version = "1", features = ["derive"] }
3838
tempfile = "3.3.0"

src/obj/mips.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
use std::collections::BTreeMap;
22

33
use anyhow::Result;
4-
use rabbitizer::{config_set_register_fpr_abi_names, Abi, Instruction, SimpleOperandType};
4+
use rabbitizer::{config, Abi, Instruction, InstrCategory, OperandType};
55

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

8+
fn configure_rabbitizer() {
9+
unsafe {
10+
config::RabbitizerConfig_Cfg.reg_names.fpr_abi_names = Abi::O32;
11+
}
12+
}
13+
814
pub fn process_code(
915
data: &[u8],
1016
start_address: u64,
1117
end_address: u64,
1218
relocs: &[ObjReloc],
1319
line_info: &Option<BTreeMap<u32, u32>>,
1420
) -> Result<(Vec<u8>, Vec<ObjIns>)> {
15-
config_set_register_fpr_abi_names(Abi::RABBITIZER_ABI_O32);
21+
configure_rabbitizer();
1622

1723
let ins_count = data.len() / 4;
1824
let mut ops = Vec::<u8>::with_capacity(ins_count);
@@ -21,21 +27,21 @@ pub fn process_code(
2127
for chunk in data.chunks_exact(4) {
2228
let reloc = relocs.iter().find(|r| (r.address as u32 & !3) == cur_addr);
2329
let code = u32::from_be_bytes(chunk.try_into()?);
24-
let mut instruction = Instruction::new(code, cur_addr);
30+
let instruction = Instruction::new(code, cur_addr, InstrCategory::CPU);
2531

26-
let op = instruction.instr_id() as u8;
32+
let op = instruction.unique_id as u8;
2733
ops.push(op);
2834

29-
let mnemonic = instruction.instr_id().get_opcode_name().unwrap_or_default().to_string();
35+
let mnemonic = instruction.opcode_name().to_string();
3036
let is_branch = instruction.is_branch();
3137
let branch_offset = instruction.branch_offset();
3238
let branch_dest =
3339
if is_branch { Some((cur_addr as i32 + branch_offset) as u32) } else { None };
3440
let args = instruction
35-
.simple_operands()
41+
.get_operands_slice()
3642
.iter()
37-
.map(|op| match op.kind {
38-
SimpleOperandType::Imm | SimpleOperandType::Label => {
43+
.map(|op| match op {
44+
OperandType::cpu_immediate | OperandType::cpu_label | OperandType::cpu_branch_target_label => {
3945
if is_branch {
4046
ObjInsArg::BranchOffset(branch_offset)
4147
} else if let Some(reloc) = reloc {
@@ -49,17 +55,17 @@ pub fn process_code(
4955
ObjInsArg::Reloc
5056
}
5157
} else {
52-
ObjInsArg::MipsArg(op.disassembled.clone())
58+
ObjInsArg::MipsArg(op.disassemble(&instruction, None))
5359
}
5460
}
55-
SimpleOperandType::ImmBase => {
61+
OperandType::cpu_immediate_base => {
5662
if reloc.is_some() {
5763
ObjInsArg::RelocWithBase
5864
} else {
59-
ObjInsArg::MipsArg(op.disassembled.clone())
65+
ObjInsArg::MipsArg(op.disassemble(&instruction, None))
6066
}
6167
}
62-
_ => ObjInsArg::MipsArg(op.disassembled.clone()),
68+
_ => ObjInsArg::MipsArg(op.disassemble(&instruction, None)),
6369
})
6470
.collect();
6571
let line =

0 commit comments

Comments
 (0)