From a3cf49ad33fd4a967035c48ff1d04033364707fa Mon Sep 17 00:00:00 2001 From: iximeow Date: Wed, 16 Jan 2019 03:49:40 -0800 Subject: base definition of an arch to yaxpeax --- src/lib.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/lib.rs (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..77d3df2 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,40 @@ +extern crate num_traits; + +use std::fmt::Debug; + +use std::ops::{Add, Sub}; + +use num_traits::{Bounded, WrappingAdd}; + // This is pretty wonk.. +pub trait Address where Self: Debug + Copy + Clone + Sized + Ord + Add + Sub + From + Bounded + WrappingAdd { + fn to_linear(&self) -> usize; +} +/* +impl Address for T where T: Sized + Ord + Add + From + Into { + fn to_linear(&self) -> usize { *self.into() } +} +*/ + +impl Address for u16 { + fn to_linear(&self) -> usize { *self as usize } +} + +impl Address for u32 { + fn to_linear(&self) -> usize { *self as usize } +} + +pub trait Decodable where Self: Sized { + fn decode<'a, T: IntoIterator>(bytes: T) -> Option; + fn decode_into<'a, T: IntoIterator>(&mut self, bytes: T) -> Option<()>; +} + +pub trait Arch { + type Address: Address + Debug; + type Instruction: Decodable + LengthedInstruction; + type Operand; +} + +pub trait LengthedInstruction { + type Unit; + fn len(&self) -> Self::Unit; +} -- cgit v1.1