From 2df5d55b4d87cec9ea618def24cee63997ba8c4c Mon Sep 17 00:00:00 2001 From: iximeow Date: Sun, 16 Jun 2024 12:36:23 -0700 Subject: move to shared (safe) impl of RelativeBranchPrinter --- src/long_mode/display.rs | 169 ----------------------------------------------- 1 file changed, 169 deletions(-) (limited to 'src') diff --git a/src/long_mode/display.rs b/src/long_mode/display.rs index ba20c1c..6d9969d 100644 --- a/src/long_mode/display.rs +++ b/src/long_mode/display.rs @@ -4140,175 +4140,6 @@ impl Instruction { if self.operand_count > 0 { danger_anguished_string_write(out, " "); -// let x = Operand::from_spec(self, self.operands[0]); - - struct RelativeBranchPrinter<'a, Y: YaxColors> { - inst: &'a Instruction, - colors: &'a Y, - out: &'a mut alloc::string::String, - } - - impl<'a, Y: YaxColors> crate::long_mode::OperandVisitor for RelativeBranchPrinter<'a, Y> { - // return true if we printed a relative branch offset, false otherwise - type Ok = bool; - // but errors are errors - type Error = fmt::Error; - - fn visit_reg(&mut self, reg: RegSpec) -> Result { - Ok(false) - } - fn visit_deref(&mut self, reg: RegSpec) -> Result { - Ok(false) - } - fn visit_disp(&mut self, reg: RegSpec, disp: i32) -> Result { - Ok(false) - } - #[cfg_attr(feature="profiling", inline(never))] - fn visit_i8(&mut self, rel: i8) -> Result { - if RELATIVE_BRANCHES.contains(&self.inst.opcode) { - danger_anguished_string_write(self.out, "$"); - let mut v = rel as u8; - if rel < 0 { - danger_anguished_string_write(&mut self.out, "-"); - v = -rel as u8; - } else { - danger_anguished_string_write(&mut self.out, "+"); - } - danger_anguished_string_write(self.out, "0x"); - let mut buf = [MaybeUninit::::uninit(); 2]; - let mut curr = buf.len(); - loop { - let digit = v % 16; - let c = c_to_hex(digit as u8); - curr -= 1; - buf[curr].write(c); - v = v / 16; - if v == 0 { - break; - } - } - let buf = &buf[curr..]; - let s = unsafe { - core::mem::transmute::<&[MaybeUninit], &str>(buf) - }; - - anguished_string_write(&mut self.out, s); - Ok(true) - } else { - Ok(false) - } - } - #[cfg_attr(feature="profiling", inline(never))] - fn visit_i32(&mut self, rel: i32) -> Result { - if RELATIVE_BRANCHES.contains(&self.inst.opcode) || self.inst.opcode == Opcode::XBEGIN { - danger_anguished_string_write(self.out, "$"); - let mut v = rel as u32; - if rel < 0 { - danger_anguished_string_write(&mut self.out, "-"); - v = -rel as u32; - } else { - danger_anguished_string_write(&mut self.out, "+"); - } - danger_anguished_string_write(self.out, "0x"); - let mut buf = [MaybeUninit::::uninit(); 8]; - let mut curr = buf.len(); - loop { - let digit = v % 16; - let c = c_to_hex(digit as u8); - curr -= 1; - buf[curr].write(c); - v = v / 16; - if v == 0 { - break; - } - } - let buf = &buf[curr..]; - let s = unsafe { - core::mem::transmute::<&[MaybeUninit], &str>(buf) - }; - -// danger_anguished_string_write(&mut self.out, s); - - danger_anguished_variable_length_bstring_write(unsafe { self.out.as_mut_vec() }, s.as_bytes()); - Ok(true) - } else { - Ok(false) - } - } - fn visit_u8(&mut self, imm: u8) -> Result { - Ok(false) - } - fn visit_i16(&mut self, imm: i16) -> Result { - Ok(false) - } - fn visit_u16(&mut self, imm: u16) -> Result { - Ok(false) - } - fn visit_u32(&mut self, imm: u32) -> Result { - Ok(false) - } - fn visit_i64(&mut self, imm: i64) -> Result { - Ok(false) - } - fn visit_u64(&mut self, imm: u64) -> Result { - Ok(false) - } - fn visit_abs_u32(&mut self, imm: u32) -> Result { - Ok(false) - } - fn visit_abs_u64(&mut self, imm: u64) -> Result { - Ok(false) - } - fn visit_reg_scale(&mut self, reg: RegSpec, scale: u8) -> Result { - Ok(false) - } - fn visit_index_base_scale(&mut self, base: RegSpec, index: RegSpec, scale: u8) -> Result { - Ok(false) - } - fn visit_reg_scale_disp(&mut self, reg: RegSpec, scale: u8, disp: i32) -> Result { - Ok(false) - } - fn visit_index_base_scale_disp(&mut self, base: RegSpec, index: RegSpec, scale: u8, disp: i32) -> Result { - Ok(false) - } - fn visit_other(&mut self) -> Result { - Ok(false) - } - fn visit_reg_mask_merge(&mut self, spec: RegSpec, mask: RegSpec, merge_mode: MergeMode) -> Result { - Ok(false) - } - fn visit_reg_mask_merge_sae(&mut self, spec: RegSpec, mask: RegSpec, merge_mode: MergeMode, sae_mode: crate::long_mode::SaeMode) -> Result { - Ok(false) - } - fn visit_reg_mask_merge_sae_noround(&mut self, spec: RegSpec, mask: RegSpec, merge_mode: MergeMode) -> Result { - Ok(false) - } - fn visit_reg_disp_masked(&mut self, spec: RegSpec, disp: i32, mask_reg: RegSpec) -> Result { - Ok(false) - } - fn visit_reg_deref_masked(&mut self, spec: RegSpec, mask_reg: RegSpec) -> Result { - Ok(false) - } - fn visit_reg_scale_masked(&mut self, spec: RegSpec, scale: u8, mask_reg: RegSpec) -> Result { - Ok(false) - } - fn visit_reg_scale_disp_masked(&mut self, spec: RegSpec, scale: u8, disp: i32, mask_reg: RegSpec) -> Result { - Ok(false) - } - fn visit_index_base_masked(&mut self, base: RegSpec, index: RegSpec, mask_reg: RegSpec) -> Result { - Ok(false) - } - fn visit_index_base_disp_masked(&mut self, base: RegSpec, index: RegSpec, disp: i32, mask_reg: RegSpec) -> Result { - Ok(false) - } - fn visit_index_base_scale_masked(&mut self, base: RegSpec, index: RegSpec, scale: u8, mask_reg: RegSpec) -> Result { - Ok(false) - } - fn visit_index_base_scale_disp_masked(&mut self, base: RegSpec, index: RegSpec, scale: u8, disp: i32, mask_reg: RegSpec) -> Result { - Ok(false) - } - } - if self.visit_operand(0, &mut RelativeBranchPrinter { inst: &self, colors, -- cgit v1.1