rtlola_hir/
lib.rs

1//! The high-level intermediate representation of the RTLola Monitoring Framework
2//!
3//! This crate offers functionality to transform the abstract syntax tree (See [RtLolaAst]) of an RTLola specification into a high-level intermediate representation.
4//! It contains more convenient methods than the Ast, enables different analysis steps and provides their reports.  The Hir traverses several modes representing the level to which it was analyzed and refined.
5//!
6//! # HIR Modes
7//! * `RtLolaHir<BaseMode>` is the base mode of the Hir. In this state, the hir contains multiple convenience methods to work with the specification.
8//! * `RtLolaHir<DepAnaMode>` additionally features the dependency analysis.
9//! * `RtLolaHir<TypedMode>` annotates the streams with value and pacing type information.
10//! * `RtLolaHir<OrderedMode>` orders the streams into layers of streams which can be evaluated at the same time.
11//! * `RtLolaHir<MemBoundMode>` enriches the streams with their memory requirements.
12//! * `RtLolaHir<CompleteMode>` finalizes the Hir to its fully analyzed state.
13//!
14//! Refer to [RtLolaHir] for more details.
15
16#![forbid(unused_must_use)] // disallow discarding errors
17#![warn(
18    missing_docs,
19    missing_debug_implementations,
20    missing_copy_implementations,
21    trivial_casts,
22    trivial_numeric_casts,
23    unsafe_code,
24    unstable_features,
25    unused_import_braces,
26    unused_qualifications
27)]
28
29pub mod config;
30mod features;
31pub mod hir;
32mod modes;
33mod stdlib;
34mod type_check;
35
36use config::FrontendConfig;
37use hir::Hir;
38pub use hir::RtLolaHir;
39pub use modes::{BaseMode, CompleteMode};
40use rtlola_parser::RtLolaAst;
41use rtlola_reporting::RtLolaError;
42
43/// Transforms a [RtLolaAst] into the [RtLolaHir].
44///
45/// For a given specification the [parse](rtlola_parser::parse) function parses the input into the [RtLolaAst].
46/// The [RtLolaHir] is the result of the first transformation and is used for all following analyses and transformations.
47pub fn from_ast(ast: RtLolaAst) -> Result<Hir<BaseMode>, RtLolaError> {
48    Hir::<BaseMode>::from_ast(ast)
49}
50
51/// Transforms a [RtLolaAst] into the [RtLolaHir] and completes all mode transformations.
52///
53/// The [RtLolaAst] can be obtained by [parse](rtlola_parser::parse)  and its sibling functions.
54/// Analyses are performed sequentially in the following order:
55/// - Initial conversion (see [from_ast])
56/// - Dependency analysis (see [determine_evaluation_order](crate::hir::RtLolaHir::<TypeMode>::determine_evaluation_order)).
57/// - Type analysis (see [check_types](crate::hir::RtLolaHir::<DepAnaMode>::check_types)):
58/// - Layer analysis (see [determine_evaluation_order](crate::hir::RtLolaHir::<TypedMode>::determine_evaluation_order)):
59/// - Memory analysis (see [determine_memory_bounds](crate::hir::RtLolaHir::<OrderedMode>::determine_memory_bounds)):
60///
61/// This function returns the fully analysed [RtLolaHir]  which can be lowered into the [Mir](rtlola-frontend::Mir).
62pub fn fully_analyzed(
63    ast: RtLolaAst,
64    cfg: &FrontendConfig,
65) -> Result<Hir<CompleteMode>, RtLolaError> {
66    Hir::<BaseMode>::from_ast(ast)?
67        .check_types(cfg)?
68        .analyze_dependencies(cfg)?
69        .determine_evaluation_order(cfg)?
70        .determine_memory_bounds(cfg)?
71        .finalize(cfg)
72}
73
74#[macro_use]
75extern crate rtlola_macros;