msp430_asm/
decode_error.rs

1/// Catch all error type that contains any error that can occur during the
2/// decoding process
3#[derive(Debug, Clone, Copy, PartialEq)]
4pub enum DecodeError {
5    /// Present when an instruction expects an additional source argument
6    /// (after the instruction) but none is present
7    MissingSource,
8    /// Present when an instruction expects an additional destination argument
9    /// (after the instruction) but none is present
10    MissingDestination,
11    /// Present when the combination of the AS (source addressing mode) field
12    /// and the register are an invalid combination
13    InvalidSource((u16, u8)),
14    /// Present when the combination of the AD (destination addressing mode) field
15    /// and the register are an invalid combination
16    InvalidDestination((u16, u8)),
17    /// Present when there is not instruction available to read
18    MissingInstruction,
19    /// Present when the opcode specified for a type 1 or type 2 instruction
20    /// is invalid
21    InvalidOpcode(u16),
22    /// Present when the condition of a jxx instruction is invalid
23    InvalidJumpCondition(u16),
24}
25
26impl std::fmt::Display for DecodeError {
27    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28        match self {
29            Self::MissingSource => {
30                write!(f, "source operand is missing")
31            }
32            Self::MissingDestination => {
33                write!(f, "destination operand is missing")
34            }
35            Self::InvalidSource((source, register)) => {
36                write!(
37                    f,
38                    "source addressing mode ({}) for register ({}) is invalid",
39                    source, register
40                )
41            }
42            Self::InvalidDestination((source, register)) => {
43                write!(
44                    f,
45                    "destination addressing mode ({}) for register ({}) is invalid",
46                    source, register
47                )
48            }
49            Self::MissingInstruction => {
50                write!(f, "not enough data to decode instruction")
51            }
52            Self::InvalidOpcode(opcode) => {
53                write!(f, "invalid opcode {}", opcode)
54            }
55            Self::InvalidJumpCondition(condition) => {
56                write!(f, "invalid jump condition {}", condition)
57            }
58        }
59    }
60}
61
62impl std::error::Error for DecodeError {}