1use core::fmt::{Debug, Display};
7
8#[derive(Debug, Copy, Clone)]
9pub enum AssemblerError<L> {
11 Overflow,
13 UndefinedLabel(L),
15 DuplicateLabel(L),
17 InsufficientAlignment {
19 label: L,
21 offset: i32,
23 shift: u8,
25 },
26}
27
28impl<L> Display for AssemblerError<L>
29where
30 L: Display,
31{
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 match self {
34 AssemblerError::Overflow => write!(f, "address space overflow"),
35 AssemblerError::UndefinedLabel(l) => write!(f, "undefined label {l}"),
36 AssemblerError::DuplicateLabel(l) => write!(f, "duplicate label {l}"),
37 AssemblerError::InsufficientAlignment {
38 label,
39 offset,
40 shift,
41 } => write!(
42 f,
43 "label {label} + offset {offset} is insufficiently aligned to be shifted by {shift}"
44 ),
45 }
46 }
47}
48
49#[cfg(feature = "std")]
50impl<L> std::error::Error for AssemblerError<L> where L: Debug + Display {}