Skip to main content

vyre_libs/scan/
scan_program.rs

1//! Neutral NFA scan composition artifact.
2//!
3//! This module owns program and immutable table construction only. Dispatch,
4//! resident allocation, readback, and timing adapters live above `vyre-libs`.
5
6use vyre_foundation::ir::Program;
7
8use super::nfa;
9
10/// Typed program plus immutable inputs required by the NFA scan composition.
11#[derive(Debug, Clone)]
12pub struct ScanProgram {
13    /// Substrate-neutral scan program.
14    pub program: Program,
15    /// Lane-major transition table consumed by `nfa_transition`.
16    pub transition_table: Vec<u32>,
17    /// Lane-major epsilon table consumed by `nfa_epsilon`.
18    pub epsilon_table: Vec<u32>,
19    /// Typed NFA plan describing state and input bounds.
20    pub plan: nfa::NfaPlan,
21}
22
23/// Build a neutral NFA program artifact and its immutable table inputs.
24#[must_use]
25pub fn build(patterns: &[&str], input_buf: &str, hit_buf: &str, input_len: u32) -> ScanProgram {
26    let plan = nfa::compile(patterns).for_input_len(input_len);
27    let program = nfa::nfa_scan(patterns, input_buf, hit_buf, input_len);
28    let transition_table = nfa::build_transition_table(patterns);
29    let epsilon_table = nfa::build_epsilon_table(patterns);
30    ScanProgram {
31        program,
32        transition_table,
33        epsilon_table,
34        plan,
35    }
36}