From bebdead98a9fa6510e30dbde6cc694f52a346a1e Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 22 Jun 2024 15:18:31 -0700 Subject: NoColorsSink has a decent name now --- src/long_mode/display.rs | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'src/long_mode') diff --git a/src/long_mode/display.rs b/src/long_mode/display.rs index 18314ab..e8000ed 100644 --- a/src/long_mode/display.rs +++ b/src/long_mode/display.rs @@ -163,22 +163,20 @@ impl fmt::Display for Operand { } impl Colorize for Operand { - fn colorize(&self, colors: &Y, f: &mut T) -> fmt::Result { - let mut f = yaxpeax_arch::display::NoColorsSink { - out: f - }; - let mut visitor = ColorizingOperandVisitor { + fn colorize(&self, _colors: &Y, f: &mut T) -> fmt::Result { + let mut f = yaxpeax_arch::display::FmtSink::new(f); + let mut visitor = DisplayingOperandVisitor { f: &mut f }; self.visit(&mut visitor) } } -struct ColorizingOperandVisitor<'a, T> { +struct DisplayingOperandVisitor<'a, T> { f: &'a mut T, } -impl crate::long_mode::OperandVisitor for ColorizingOperandVisitor<'_, T> { +impl crate::long_mode::OperandVisitor for DisplayingOperandVisitor<'_, T> { type Ok = (); type Error = core::fmt::Error; @@ -3536,8 +3534,17 @@ impl <'instr, T: fmt::Write, Y: YaxColors> Colorize for InstructionDisplay struct NoContext; impl Instruction { + /// format this instruction into `out` as a plain text string. #[cfg_attr(feature="profiling", inline(never))] - pub fn write_to(&self, out: &mut T) -> fmt::Result { + pub fn write_to(&self, out: &mut T) -> fmt::Result { + let mut out = yaxpeax_arch::display::FmtSink::new(out); + contextualize_intel(self, &mut out) + } + + /// format this instruction into `out`, which may perform additional styling based on its + /// `DisplaySink` implementation. + #[cfg_attr(feature="profiling", inline(never))] + pub fn display_into(&self, out: &mut T) -> fmt::Result { contextualize_intel(self, out) } } @@ -3590,7 +3597,7 @@ pub(crate) fn contextualize_intel(instr: &Instruction, out: &mut } } - let mut displayer = ColorizingOperandVisitor { + let mut displayer = DisplayingOperandVisitor { f: out, }; instr.visit_operand(0 as u8, &mut displayer)?; @@ -3619,7 +3626,7 @@ pub(crate) fn contextualize_intel(instr: &Instruction, out: &mut } } - let mut displayer = ColorizingOperandVisitor { + let mut displayer = DisplayingOperandVisitor { f: out, }; @@ -3732,9 +3739,7 @@ pub(crate) fn contextualize_c(instr: &Instruction, out: &mut T) } fn write_jmp_operand(op: Operand, out: &mut T) -> fmt::Result { - let mut out = yaxpeax_arch::display::NoColorsSink { - out, - }; + let mut out = yaxpeax_arch::display::FmtSink::new(out); use core::fmt::Write; match op { Operand::ImmediateI8(rel) => { @@ -4036,9 +4041,7 @@ impl <'instr, T: fmt::Write, Y: YaxColors> ShowContextual style, } = self; - let mut out = yaxpeax_arch::display::NoColorsSink { - out: out, - }; + let mut out = yaxpeax_arch::display::FmtSink::new(out); match style { DisplayStyle::Intel => { @@ -4054,9 +4057,7 @@ impl <'instr, T: fmt::Write, Y: YaxColors> ShowContextual #[cfg(feature="std")] impl ShowContextual], T, Y> for Instruction { fn contextualize(&self, colors: &Y, _address: u64, context: Option<&[Option]>, out: &mut T) -> fmt::Result { - let mut out = yaxpeax_arch::display::NoColorsSink { - out, - }; + let mut out = yaxpeax_arch::display::FmtSink::new(out); let out = &mut out; use core::fmt::Write; @@ -4092,7 +4093,7 @@ impl ShowContextual ShowContextual { write!(out, ", ")?; - let mut displayer = ColorizingOperandVisitor { + let mut displayer = DisplayingOperandVisitor { f: out, }; self.visit_operand(i as u8, &mut displayer)?; -- cgit v1.1