diff options
-rw-r--r-- | src/lib.rs | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -7,7 +7,7 @@ extern crate serde; extern crate yaxpeax_arch; -use yaxpeax_arch::{Arch, Decodable, LengthedInstruction}; +use yaxpeax_arch::{Arch, Decoder, LengthedInstruction}; #[derive(Debug)] pub enum Opcode { @@ -29,18 +29,21 @@ impl LengthedInstruction for Instruction { } } -impl Decodable for Instruction { - fn decode<T: IntoIterator<Item=u8>>(bytes: T) -> Option<Self> { +#[derive(Default, Debug)] +pub struct InstDecoder {} + +impl Decoder<Instruction> for InstDecoder { + fn decode<T: IntoIterator<Item=u8>>(&self, bytes: T) -> Option<Instruction> { let mut blank = Instruction { opcode: Opcode::NOP }; - match blank.decode_into(bytes) { + match self.decode_into(&mut blank, bytes) { Some(_) => Some(blank), None => None } } - fn decode_into<T: IntoIterator<Item=u8>>(&mut self, bytes: T) -> Option<()> { + fn decode_into<T: IntoIterator<Item=u8>>(&self, instr: &mut Instruction, bytes: T) -> Option<()> { match bytes.into_iter().next() { Some(0x00) => { - self.opcode = Opcode::NOP; + instr.opcode = Opcode::NOP; Some(()) }, _ => None @@ -59,5 +62,6 @@ pub struct PIC24; impl Arch for PIC24 { type Address = u32; type Instruction = Instruction; + type Decoder = InstDecoder; type Operand = (); } |