#[cfg(feature="use-serde")] #[macro_use] extern crate serde_derive; #[cfg(feature="use-serde")] extern crate serde; //#[cfg(feature="use-serde")] //use serde::{Serialize, Deserialize}; extern crate yaxpeax_arch; use yaxpeax_arch::{Arch, Decoder, LengthedInstruction}; use std::fmt; #[derive(Debug)] pub enum Opcode { NOP } #[derive(Debug)] pub struct Instruction { pub opcode: Opcode } impl Default for Instruction { fn default() -> Self { Instruction { opcode: Opcode::NOP } } } impl LengthedInstruction for Instruction { type Unit = ::Address; fn min_size() -> Self::Unit { 3 } fn len(&self) -> Self::Unit { 3 // ish } } #[derive(Debug, PartialEq)] pub enum DecodeError { ExhaustedInput, InvalidOpcode, InvalidOperand, } impl fmt::Display for DecodeError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { DecodeError::ExhaustedInput => write!(f, "exhausted input"), DecodeError::InvalidOpcode => write!(f, "invalid opcode"), DecodeError::InvalidOperand => write!(f, "invalid operand"), } } } impl yaxpeax_arch::DecodeError for DecodeError { fn data_exhausted(&self) -> bool { self == &DecodeError::ExhaustedInput } fn bad_opcode(&self) -> bool { self == &DecodeError::InvalidOpcode } fn bad_operand(&self) -> bool { self == &DecodeError::InvalidOperand } } impl yaxpeax_arch::Instruction for Instruction { // TODO: this is wrong!! fn well_defined(&self) -> bool { true } } #[derive(Default, Debug)] pub struct InstDecoder {} impl Decoder for InstDecoder { type Error = DecodeError; fn decode_into>(&self, instr: &mut Instruction, bytes: T) -> Result<(), Self::Error> { match bytes.into_iter().next() { Some(0x00) => { instr.opcode = Opcode::NOP; Ok(()) }, _ => Err(DecodeError::ExhaustedInput) } } } #[cfg(feature="use-serde")] #[derive(Debug, Serialize, Deserialize)] pub struct PIC24; #[cfg(not(feature="use-serde"))] #[derive(Debug)] pub struct PIC24; impl Arch for PIC24 { type Address = u32; type Instruction = Instruction; type DecodeError = DecodeError; type Decoder = InstDecoder; type Operand = (); }