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
//! Jump table implementation.

use crate::codegen::ExtFunc;
pub use table::JumpTable;

mod pc;
mod relocate;
mod table;

/// Jump types
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Jump {
    /// offset to the program counter.
    Offset(u16),
    /// Jump to the given label, the label here
    /// is the original program counter.
    Label(u16),
    /// Jump to function.
    Func(u32),
    /// External function.
    ExtFunc(ExtFunc),
}

impl Jump {
    /// If the target is a label.
    pub fn is_label(&self) -> bool {
        matches!(self, Jump::Label { .. })
    }

    /// If the target is fixed to offset of the program counter.
    pub fn is_offset(&self) -> bool {
        matches!(self, Jump::Offset(_))
    }
}