use core::fmt::{Debug, Display};
#[derive(Debug, Copy, Clone)]
pub enum AssemblerError<L> {
Overflow,
UndefinedLabel(L),
DuplicateLabel(L),
InsufficientAlignment {
label: L,
offset: i32,
shift: u8,
},
}
impl<L> Display for AssemblerError<L>
where
L: Display,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
AssemblerError::Overflow => write!(f, "address space overflow"),
AssemblerError::UndefinedLabel(l) => write!(f, "undefined label {l}"),
AssemblerError::DuplicateLabel(l) => write!(f, "duplicate label {l}"),
AssemblerError::InsufficientAlignment {
label,
offset,
shift,
} => write!(
f,
"label {label} + offset {offset} is insufficiently aligned to be shifted by {shift}"
),
}
}
}
#[cfg(feature = "std")]
impl<L> std::error::Error for AssemblerError<L> where L: Debug + Display {}