diff options
author | iximeow <me@iximeow.net> | 2019-11-28 02:22:47 -0800 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2020-01-12 17:23:02 -0800 |
commit | 05b4ccbbc19f98a97e23e5acd3252ac0a48afc48 (patch) | |
tree | 515a933bf7773639d8fc656708b04929bb1a1951 /src | |
parent | b4439a5e8d080e9a33f91f9646e774e89b1ac978 (diff) |
update pic24 to revised decoder trait
Diffstat (limited to 'src')
-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 = (); } |