summaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: 7dc48728e0d294c2ca4c55db56b2c4480ae4bd79 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#[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};

#[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
    }
}

#[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 self.decode_into(&mut blank, bytes) {
            Some(_) => Some(blank),
            None => None
        }
    }
    fn decode_into<T: IntoIterator<Item=u8>>(&self, instr: &mut Instruction, bytes: T) -> Option<()> {
        match bytes.into_iter().next() {
            Some(0x00) => {
                instr.opcode = Opcode::NOP;
                Some(())
            },
            _ => None
        }
    }
}

#[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 Decoder = InstDecoder;
    type Operand = ();
}