diff options
-rw-r--r-- | Cargo.toml | 11 | ||||
-rw-r--r-- | src/lib.rs | 40 |
2 files changed, 51 insertions, 0 deletions
diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..768bcdc --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,11 @@ +[package] + +name = "yaxpeax-arch" +version = "0.0.1" +authors = [ "iximeow <me@iximeow.net>" ] +license = "0BSD" +repository = "yaxpeax-arch" +description = "fundamental traits to describe an architecture in the yaxpeax project" + +[dependencies] +"num-traits" = "0.2" 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<Output=Self> + Sub<Output=Self> + From<u16> + Bounded + WrappingAdd { + fn to_linear(&self) -> usize; +} +/* +impl <T> Address for T where T: Sized + Ord + Add<Output=Self> + From<u16> + Into<usize> { + 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<Item=&'a u8>>(bytes: T) -> Option<Self>; + fn decode_into<'a, T: IntoIterator<Item=&'a u8>>(&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; +} |