aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2021-08-22 14:43:06 -0700
committeriximeow <me@iximeow.net>2021-08-22 14:43:06 -0700
commit83f07b4e70efc45b2495d66a58f5d6ff0e5b7221 (patch)
tree513162f9ce3e9bd766f36332058ecc53685d3a56 /src/lib.rs
parenta6db35d444af1d2af5fc55961aa8785e17a90e30 (diff)
move annotation stuff to its own module
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs63
1 files changed, 4 insertions, 59 deletions
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<A: Arch + ?Sized> {
- /// 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<T: Reader<A::Address, A::Word>>(&self, words: &mut T) -> Result<A::Instruction, A::DecodeError> {
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<A: Arch + ?Sized> {
fn decode_into<T: Reader<A::Address, A::Word>>(&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<Descriptor> {
- /// 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<T> DescriptionSink<T> for NullSink {
- fn record(&mut self, _start: u32, _end: u32, _description: T) { }
-}
-
-#[cfg(feature = "std")]
-pub struct VecSink<T: Clone + Display> {
- pub records: std::vec::Vec<(u32, u32, T)>
-}
-
-#[cfg(feature = "std")]
-impl<T: Clone + Display> VecSink<T> {
- pub fn new() -> Self {
- VecSink { records: std::vec::Vec::new() }
- }
-}
-
-#[cfg(feature = "std")]
-impl<T: Clone + Display> DescriptionSink<T> for VecSink<T> {
- 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<A: Arch + ?Sized> {
- type FieldDescription: FieldDescription + Clone + Display + PartialEq;
-
- fn decode_with_annotation<
- T: Reader<A::Address, A::Word>,
- S: DescriptionSink<Self::FieldDescription>
- >(&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"))]