summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2019-11-28 02:22:47 -0800
committeriximeow <me@iximeow.net>2020-01-12 17:23:02 -0800
commit05b4ccbbc19f98a97e23e5acd3252ac0a48afc48 (patch)
tree515a933bf7773639d8fc656708b04929bb1a1951
parentb4439a5e8d080e9a33f91f9646e774e89b1ac978 (diff)
update pic24 to revised decoder trait
-rw-r--r--src/lib.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 20786d9..7dc4872 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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 = ();
}