#![deny(missing_docs)]
mod arch;
pub use arch::*;
#[non_exhaustive]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum Architecture {
#[cfg(feature = "6502")]
_6502,
}
#[doc(inline)]
pub use decode::Decode;
pub mod decode {
use std::io::SeekFrom;
pub trait Decode {
type Instruction: core::fmt::Debug;
type Error: core::fmt::Debug + std::error::Error;
fn decode(&mut self) -> Result<Self::Instruction, Self::Error>;
fn into_iter(self) -> Iter<Self>
where
Self: Sized,
{
Iter(Some(self))
}
}
pub trait Seek: Decode {
fn seek_bytes(&mut self, pos: SeekFrom) -> Result<u64, Self::Error>;
fn seek_insts(&mut self, pos: SeekFrom) -> Result<u64, Self::Error>;
}
pub struct Iter<D>(Option<D>);
impl<D: Decode> Iterator for Iter<D> {
type Item = D::Instruction;
fn next(&mut self) -> Option<Self::Item> {
match self.0 {
Some(ref mut x) => match x.decode() {
Ok(item) => Some(item),
Err(_) => {
self.0 = None;
None
}
},
None => None,
}
}
}
}
pub trait Encode {
type Instruction: core::fmt::Debug;
type Error: core::fmt::Debug + std::error::Error;
fn encode(&mut self, inst: Self::Instruction) -> Result<(), Self::Error>;
}