1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use crate::modules::riscv::basic::interface::parser::{ParserRISCVImmediate, ParserRISCVLabel};

impl From<ParserRISCVImmediate> for i32 {
    fn from(imm: ParserRISCVImmediate) -> Self {
        match imm {
            ParserRISCVImmediate::Imm(imm) => imm,
            ParserRISCVImmediate::Lbl((label, handler)) => u32::from(label) as i32,
        }
    }
}

impl From<ParserRISCVLabel> for u32 {
    fn from(label: ParserRISCVLabel) -> Self {
        match label {
            ParserRISCVLabel::Text(pos) => pos as u32 * 4,
            ParserRISCVLabel::Data(pos) => pos as u32,
            ParserRISCVLabel::Unknown(_) => 0,
        }
    }
}