summaryrefslogtreecommitdiff
path: root/src/instructions/gen_tools.rs
blob: a3d45bc8737c3682c4cbf63277f61ac4a5397a1b (plain)
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
// Copyright (c) 2025 taitep
// SPDX-License-Identifier: MIT
//
// This file is part of TRVE (https://gitea.taitep.se/taitep/trve)
// See LICENSE file in the project root for full license text.

use std::hint::unreachable_unchecked;

use crate::instructions::{OpcodeHandler, Splitter};

pub fn insert_funct3_splitter(splitter: &mut Option<Splitter>) -> &mut [OpcodeHandler; 8] {
    match splitter {
        Some(Splitter::Funct3Splitter(s)) => s.as_mut(),
        Some(_) => panic!("Unexpected splitter variant"),
        None => {
            *splitter = Some(Splitter::Funct3Splitter(Box::new(std::array::from_fn(
                |_i| OpcodeHandler {
                    handler: None,
                    splitter: None,
                },
            ))));
            match splitter {
                Some(Splitter::Funct3Splitter(s)) => s.as_mut(),
                _ => unsafe { unreachable_unchecked() },
            }
        }
    }
}