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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use std::str::FromStr;

use once_cell::sync::Lazy;
use strum::VariantArray;

use super::{
    super::super::{
        basic::{
            interface::parser::{ParserRISCVCsr, ParserRISCVInstOp, ParserRISCVRegister},
            parser::{lexer::Symbol, parser::RISCVSymbolList},
        },
        rv32f::constants::{RV32FCsr, RV32FInstruction, RV32FRegister, RV32F_REGISTER_VALID_NAME},
    },
    lexer::RV32FOpToken,
};

pub static RV32F_SYMBOL_LIST: Lazy<RISCVSymbolList> = Lazy::new(|| vec![&OP_TOKEN, &REG_TOKEN]);

pub static OP_TOKEN: Lazy<Vec<(&'static str, Symbol<'static>)>> = Lazy::new(|| {
    OP_TOKEN_STASH
        .iter()
        .map(|op| (op.0.as_str(), op.1))
        .collect()
});

pub static REG_TOKEN: Lazy<Vec<(&'static str, Symbol<'static>)>> = Lazy::new(|| {
    RV32F_REGISTER_VALID_NAME
        .iter()
        .map(|reg| {
            (
                *reg,
                Symbol::Reg(RV32FRegister::from_str(reg).unwrap().into()),
            )
        })
        .collect()
});

static OP_TOKEN_STASH: Lazy<Vec<(String, Symbol<'static>)>> = Lazy::new(|| {
    RV32FOpToken::VARIANTS
        .iter()
        .map(|&op| (op.name(), Symbol::Op((op).into())))
        .collect()
});

impl From<RV32FRegister> for ParserRISCVRegister {
    fn from(reg: RV32FRegister) -> Self {
        ParserRISCVRegister::RV32F(reg)
    }
}

impl From<RV32FInstruction> for ParserRISCVInstOp {
    fn from(inst: RV32FInstruction) -> Self {
        ParserRISCVInstOp::RV32F(inst)
    }
}

impl From<RV32FCsr> for ParserRISCVCsr {
    fn from(csr: RV32FCsr) -> Self {
        ParserRISCVCsr::RV32F(csr)
    }
}