aboutsummaryrefslogtreecommitdiff
path: root/src/long_mode
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2024-06-16 12:36:23 -0700
committeriximeow <me@iximeow.net>2024-06-16 12:36:23 -0700
commit2df5d55b4d87cec9ea618def24cee63997ba8c4c (patch)
tree0d9466d071769acb97159a90f521173e355a9c2d /src/long_mode
parentead58f66b9818c1ac01232b1e137c0d2a6ea06a2 (diff)
move to shared (safe) impl of RelativeBranchPrinter
Diffstat (limited to 'src/long_mode')
-rw-r--r--src/long_mode/display.rs169
1 files changed, 0 insertions, 169 deletions
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<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_deref(&mut self, reg: RegSpec) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_disp(&mut self, reg: RegSpec, disp: i32) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- #[cfg_attr(feature="profiling", inline(never))]
- fn visit_i8(&mut self, rel: i8) -> Result<Self::Ok, Self::Error> {
- 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::<u8>::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<u8>], &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<Self::Ok, Self::Error> {
- 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::<u8>::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<u8>], &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<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_i16(&mut self, imm: i16) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_u16(&mut self, imm: u16) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_u32(&mut self, imm: u32) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_i64(&mut self, imm: i64) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_u64(&mut self, imm: u64) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_abs_u32(&mut self, imm: u32) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_abs_u64(&mut self, imm: u64) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_reg_scale(&mut self, reg: RegSpec, scale: u8) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_index_base_scale(&mut self, base: RegSpec, index: RegSpec, scale: u8) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_reg_scale_disp(&mut self, reg: RegSpec, scale: u8, disp: i32) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_index_base_scale_disp(&mut self, base: RegSpec, index: RegSpec, scale: u8, disp: i32) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_other(&mut self) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_reg_mask_merge(&mut self, spec: RegSpec, mask: RegSpec, merge_mode: MergeMode) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_reg_mask_merge_sae(&mut self, spec: RegSpec, mask: RegSpec, merge_mode: MergeMode, sae_mode: crate::long_mode::SaeMode) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_reg_mask_merge_sae_noround(&mut self, spec: RegSpec, mask: RegSpec, merge_mode: MergeMode) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_reg_disp_masked(&mut self, spec: RegSpec, disp: i32, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_reg_deref_masked(&mut self, spec: RegSpec, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_reg_scale_masked(&mut self, spec: RegSpec, scale: u8, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_reg_scale_disp_masked(&mut self, spec: RegSpec, scale: u8, disp: i32, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_index_base_masked(&mut self, base: RegSpec, index: RegSpec, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_index_base_disp_masked(&mut self, base: RegSpec, index: RegSpec, disp: i32, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_index_base_scale_masked(&mut self, base: RegSpec, index: RegSpec, scale: u8, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- fn visit_index_base_scale_disp_masked(&mut self, base: RegSpec, index: RegSpec, scale: u8, disp: i32, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
- Ok(false)
- }
- }
-
if self.visit_operand(0, &mut RelativeBranchPrinter {
inst: &self,
colors,