use crate::codegen::ExtFunc;
use core::fmt::Display;
pub use table::JumpTable;
mod pc;
mod relocate;
mod table;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Jump {
Offset(u16),
Label(u16),
Func(u32),
ExtFunc(ExtFunc),
}
impl Display for Jump {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Jump::Offset(offset) => write!(f, "Offset(0x{offset:x})"),
Jump::Label(offset) => write!(f, "Label(0x{offset:x})"),
Jump::Func(index) => write!(f, "Func({index})"),
Jump::ExtFunc(_) => write!(f, "ExtFunc"),
}
}
}
impl Jump {
pub fn is_label(&self) -> bool {
matches!(self, Jump::Label { .. })
}
pub fn is_offset(&self) -> bool {
matches!(self, Jump::Offset(_))
}
pub fn is_call(&self) -> bool {
!self.is_label() && !self.is_offset()
}
}