diff options
| author | iximeow <me@iximeow.net> | 2026-09-27 21:56:44 +0000 |
|---|---|---|
| committer | iximeow <me@iximeow.net> | 2026-09-27 21:56:44 +0000 |
| commit | db3bbf69116b003a69ef3bbe7f30d3d084ac0984 (patch) | |
| tree | 53125c6b5c1bfc97c4a958fe5ae334a47e9418a7 /src/display | |
| parent | e927e4e0d5267a0d51128e95abe4236a91da439a (diff) | |
first swing at generic display rules, lets see how this goes..instruction-alias-handling
Diffstat (limited to 'src/display')
| -rw-r--r-- | src/display/display_rules.rs | 40 |
1 files changed, 40 insertions, 0 deletions
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<A: crate::Arch, S: crate::display::DisplaySink + ?Siz Ok(false) } } + +pub struct DefaultRules { _pad: () } + +impl<A: crate::Arch, S: crate::display::DisplaySink + ?Sized> ArchDisplayRules<A, S> for DefaultRules {} + +impl DefaultRules { + pub fn new() -> Self { Self { _pad: () } } +} + +pub struct AbsoluteAddressFormatter<A: crate::Arch> { + addr: A::Address, +} + +impl<A: crate::Arch, S: crate::display::DisplaySink + ?Sized> ArchDisplayRules<A, S> for AbsoluteAddressFormatter<A> { + fn instr_addr(&self) -> Option<A::Address> { + Some(self.addr) + } + + fn emit_address(&self, addr: A::Address, s: &mut S) -> Result<bool, core::fmt::Error> { + 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<A: crate::Arch> AbsoluteAddressFormatter<A> { + pub fn new(addr: A::Address) -> Self { + Self { addr } + } + + pub fn advance(&mut self, instr: &A::Instruction) { + use crate::LengthedInstruction; + self.addr += instr.len(); + } +} |
