From db3bbf69116b003a69ef3bbe7f30d3d084ac0984 Mon Sep 17 00:00:00 2001 From: iximeow Date: Sun, 27 Sep 2026 21:56:44 +0000 Subject: first swing at generic display rules, lets see how this goes.. --- src/display/display_rules.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/display/display_rules.rs') diff --git a/src/display/display_rules.rs b/src/display/display_rules.rs index e6da133..abf4f95 100644 --- a/src/display/display_rules.rs +++ b/src/display/display_rules.rs @@ -1,3 +1,5 @@ +use crate::address::AddressBase; + /// `ArchDisplayRules` allows client code to control some aspects of instruction formatting. there /// are relatively few elements of instruction formatting that generalize across architectures, so /// the expected use of this trait is with additional architecture-specific `DisplayRules` traits @@ -84,3 +86,41 @@ pub trait ArchDisplayRules ArchDisplayRules for DefaultRules {} + +impl DefaultRules { + pub fn new() -> Self { Self { _pad: () } } +} + +pub struct AbsoluteAddressFormatter { + addr: A::Address, +} + +impl ArchDisplayRules for AbsoluteAddressFormatter { + fn instr_addr(&self) -> Option { + Some(self.addr) + } + + fn emit_address(&self, addr: A::Address, s: &mut S) -> Result { + s.span_start_immediate(); + s.span_end_immediate(); + s.write_fixed_size("0x")?; + s.write_u64(addr.to_linear() as u64)?; + s.span_end_immediate(); + Ok(true) + } +} + +impl AbsoluteAddressFormatter { + pub fn new(addr: A::Address) -> Self { + Self { addr } + } + + pub fn advance(&mut self, instr: &A::Instruction) { + use crate::LengthedInstruction; + self.addr += instr.len(); + } +} -- cgit v1.1