Skip to main content

fic/ccfg/
build.rs

1//! `tast → ccfg`: each program's entry points flattened into its graphs
2//! (`flatten.rs`), each buffered channel's ring sized (`ring.rs`), and each
3//! typed `Sync` channel's message (`message.rs`).
4
5use anyhow::Result;
6
7use crate::microkit::EntryPoints;
8use crate::tast::Tast;
9
10use super::flatten::to_ccfg;
11use super::message::messages;
12use super::ring::rings;
13use super::system::{Orchestration, System};
14
15/// Every program's graphs, and every channel's ring.
16///
17/// # Errors
18///
19/// A program that does not bind both Microkit entry points (the front
20/// end rejects it first); a channel whose region holds no ring of its
21/// payload; a `Sync` channel's value that does not fit its message.
22pub fn build(tast: &Tast) -> Result<System> {
23    let Tast { tenv, bodies } = tast;
24    let programs = bodies
25        .iter_enumerated()
26        .map(|(pd, body)| {
27            let entries = EntryPoints::resolve(&tenv.pds[pd].name, &body.entries)?;
28            Ok(Orchestration {
29                init: to_ccfg(body, entries.init),
30                notified: to_ccfg(body, entries.notified),
31                protected: entries.protected.map(|p| to_ccfg(body, p)),
32            })
33        })
34        .collect::<Result<_>>()?;
35    let (rings, warnings) = rings(tenv)?;
36    if !warnings.is_empty() {
37        eprintln!("{warnings}");
38    }
39    let messages = messages(tenv)?;
40    Ok(System {
41        programs,
42        rings,
43        messages,
44    })
45}