From 83f07b4e70efc45b2495d66a58f5d6ff0e5b7221 Mon Sep 17 00:00:00 2001 From: iximeow Date: Sun, 22 Aug 2021 14:43:06 -0700 Subject: move annotation stuff to its own module --- src/lib.rs | 63 ++++---------------------------------------------------------- 1 file changed, 4 insertions(+), 59 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 0fe090e..88370bc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,8 @@ pub use address::{AddressDisplayUsize, AddressDisplayU64, AddressDisplayU32, Add #[cfg(feature="address-parse")] pub use address::AddrParse; +pub mod annotation; + mod color; pub use color::{Colorize, NoColors, YaxColors}; @@ -136,14 +138,14 @@ impl fmt::Display for NoDescription { /// an interface to decode [`Arch::Instruction`] words from a reader of [`Arch::Word`]s. errors are /// the architecture-defined [`DecodeError`] implemention. pub trait Decoder { - /// decode one instruction for this architecture from the [`yaxpeax_arch::Reader`] of this + /// decode one instruction for this architecture from the [`crate::Reader`] of this /// architecture's `Word`. fn decode>(&self, words: &mut T) -> Result { let mut inst = A::Instruction::default(); self.decode_into(&mut inst, words).map(|_: ()| inst) } - /// decode one instruction for this architecture from the [`yaxpeax_arch::Reader`] of this + /// decode one instruction for this architecture from the [`crate::Reader`] of this /// architecture's `Word`, writing into the provided `inst`. /// /// SAFETY: @@ -155,63 +157,6 @@ pub trait Decoder { fn decode_into>(&self, inst: &mut A::Instruction, words: &mut T) -> Result<(), A::DecodeError>; } -/// implementors of `DescriptionSink` receive descriptions of an instruction's disassembly process -/// and relevant offsets in the bitstream being decoded. descriptions are archtecture-specific, and -/// architectures are expected to be able to turn the bit-level `start` and `width` values into a -/// meaningful description of bits in the original instruction stream. -pub trait DescriptionSink { - /// inform this `DescriptionSink` of a `description` that was informed by bits `start` to - /// `end` from the start of an instruction's decoding. `start` and `end` are only relative the - /// instruction being decoded when this sink `DescriptionSink` provided, so they will have no - /// relation to the position in an underlying data stream used for past or future instructions. - fn record(&mut self, start: u32, end: u32, description: Descriptor); -} - -pub struct NullSink; - -impl DescriptionSink for NullSink { - fn record(&mut self, _start: u32, _end: u32, _description: T) { } -} - -#[cfg(feature = "std")] -pub struct VecSink { - pub records: std::vec::Vec<(u32, u32, T)> -} - -#[cfg(feature = "std")] -impl VecSink { - pub fn new() -> Self { - VecSink { records: std::vec::Vec::new() } - } -} - -#[cfg(feature = "std")] -impl DescriptionSink for VecSink { - fn record(&mut self, start: u32, end: u32, description: T) { - self.records.push((start, end, description)); - } -} - -pub trait FieldDescription { - fn id(&self) -> u32; - fn is_separator(&self) -> bool; -} - -/// an interface to decode [`Arch::Instruction`] words from a reader of [`Arch::Word`]s, with the -/// decoder able to report descriptions of bits or fields in the instruction to a sink implementing -/// [`DescriptionSink`]. the sink may be [`NullSink`] which discards provided data. decoding with a -/// `NullSink` should behave identically to `Decoder::decode_into`. implementors are recommended to -/// implement `Decoder::decode_into` as a call to `AnnotatingDecoder::decode_with_fields` if -/// implementing both traits. -pub trait AnnotatingDecoder { - type FieldDescription: FieldDescription + Clone + Display + PartialEq; - - fn decode_with_annotation< - T: Reader, - S: DescriptionSink - >(&self, inst: &mut A::Instruction, words: &mut T, sink: &mut S) -> Result<(), A::DecodeError>; -} - #[cfg(feature = "use-serde")] pub trait AddressBounds: Address + Debug + Hash + PartialEq + Eq + Serialize + for<'de> Deserialize<'de> {} #[cfg(not(feature = "use-serde"))] -- cgit v1.1