From c9a266cd62713f2ff7f5cf637adafd685ee17f16 Mon Sep 17 00:00:00 2001 From: iximeow Date: Mon, 3 Jan 2022 01:18:46 -0800 Subject: name the fields in the auxiliary data for `print_instr` --- src/main.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8597aca..d834785 100644 --- a/src/main.rs +++ b/src/main.rs @@ -161,9 +161,15 @@ struct Printer { verbose: bool, } +struct InstDetails { + pub inst_len: usize, + pub well_defined: bool, + pub inst: I, +} + impl Printer { // shared generic function to keep display logic consistent regardless of yaxpeax-arch version - fn print_instr(&self, rest: &[u8], addr: usize, x: Result<(usize, bool, I), E>) + fn print_instr(&self, rest: &[u8], addr: usize, inst_res: Result, E>) where I: fmt::Display + fmt::Debug, E: fmt::Display, @@ -171,8 +177,8 @@ impl Printer { // TODO: lock stdout for the whole time? What if an arch implementation tries to log something? let mut stdout = self.stdout.lock(); write!(stdout, "{:#010x}: ", addr).unwrap(); - match x { - Ok((inst_len, well_defined, inst)) => { + match inst_res { + Ok(InstDetails { inst_len, well_defined, inst }) => { writeln!(stdout, "{:14}: {}", hex::encode(&rest[..inst_len]), inst) .unwrap(); if self.verbose { @@ -230,11 +236,11 @@ mod arch_02 { Err(_) => A::Instruction::min_size(), }; let generic_res = res.map(|inst| { - ( - A::Address::zero().wrapping_offset(inst.len()).to_linear(), - inst.well_defined(), + crate::InstDetails { + inst_len: A::Address::zero().wrapping_offset(inst.len()).to_linear(), + well_defined: inst.well_defined(), inst, - ) + } }); printer.print_instr(rest, addr.to_linear(), generic_res); addr += advance_addr; -- cgit v1.1