summaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: 2da8e1ffc1e7d284e9dd4794644454725bfdf8b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
extern crate yaxpeax_arch;

use yaxpeax_arch::{Arch, Decodable, LengthedInstruction};

#[derive(Debug)]
pub enum Opcode {
    NOP
}

#[derive(Debug)]
pub struct Instruction {
    pub opcode: Opcode
}

impl LengthedInstruction for Instruction {
    type Unit = <PIC24 as Arch>::Address;
    fn min_size() -> Self::Unit {
        3
    }
    fn len(&self) -> Self::Unit {
        3 // ish
    }
}

impl Decodable for Instruction {
    fn decode<T: IntoIterator<Item=u8>>(bytes: T) -> Option<Self> {
        let mut blank = Instruction { opcode: Opcode::NOP };
        match blank.decode_into(bytes) {
            Some(_) => Some(blank),
            None => None
        }
    }
    fn decode_into<T: IntoIterator<Item=u8>>(&mut self, bytes: T) -> Option<()> {
        match bytes.into_iter().next() {
            Some(0x00) => {
                self.opcode = Opcode::NOP;
                Some(())
            },
            _ => None
        }
    }
}

pub struct PIC24;
impl Arch for PIC24 {
    type Address = u32;
    type Instruction = Instruction;
    type Operand = ();
}