rtlola_hir/
config.rs

1//! Defines the configuration for the analysis stages of the RTLola Hir.
2
3use rtlola_parser::ParserConfig;
4
5/// Represents the configuration for the whole frontend.
6///
7/// This includes the configuration of the parser, as well as
8/// configuration for the analysis stages.
9#[derive(Debug)]
10pub struct FrontendConfig<'a> {
11    parser_config: &'a ParserConfig,
12    memory_bound_mode: MemoryBoundMode,
13}
14
15#[derive(Default, Clone, Copy, Debug, PartialEq, Eq)]
16/// The way the memory bound is computed.
17pub enum MemoryBoundMode {
18    #[default]
19    /// All values, including values that only exist during a cycle, are counted towards the memory.
20    /// (all streams have a memory bound of at least 1).
21    Static,
22    /// Counts only values that need to be retained between cycles
23    /// (streams with direct sync accesses have memory bound of 0).
24    Dynamic,
25}
26
27impl<'a> From<&'a ParserConfig> for FrontendConfig<'a> {
28    fn from(parser_config: &'a ParserConfig) -> Self {
29        Self {
30            parser_config,
31            memory_bound_mode: MemoryBoundMode::default(),
32        }
33    }
34}
35
36/// Extension to provide additional methods to the ParserConfig.
37pub trait ParserConfigExt<'a> {
38    /// Specifies whether to compute the memory bound in dynamic or static way.
39    fn with_memory_bound_mode(&'a self, memory_bound_mode: MemoryBoundMode) -> FrontendConfig<'a>;
40
41    /// Returns a reference to the underlying parser config.
42    fn parser_config(&self) -> &ParserConfig;
43}
44
45impl<'a> ParserConfigExt<'a> for ParserConfig {
46    fn with_memory_bound_mode(&'a self, memory_bound_mode: MemoryBoundMode) -> FrontendConfig<'a> {
47        FrontendConfig::from(self).with_memory_bound_mode(memory_bound_mode)
48    }
49
50    fn parser_config(&self) -> &ParserConfig {
51        self
52    }
53}
54
55impl<'a> FrontendConfig<'a> {
56    fn with_memory_bound_mode(self, memory_bound_mode: MemoryBoundMode) -> FrontendConfig<'a> {
57        Self {
58            memory_bound_mode,
59            ..self
60        }
61    }
62
63    /// Returns the configuration for the parser
64    pub fn parser_config(&self) -> &ParserConfig {
65        self.parser_config
66    }
67}
68
69impl FrontendConfig<'_> {
70    pub(crate) fn memory_bound_mode(&self) -> MemoryBoundMode {
71        self.memory_bound_mode
72    }
73}