fic/lib.rs
1//! Fiducia Language Compiler
2//!
3//! A Rust compiler for the Fiducia language, targeting [seL4 Microkit](https://trustworthy.systems/projects/microkit/) systems.
4//! Fiducia describes system architecture (memory regions, protection domains, channels) in
5//! `.fis` files and per-PD implementations (imports, memory mappings) in `.fi` files, then
6//! compiles them to the System Description Format (SDF) XML consumed by Microkit.
7//!
8//! # Fiducia Language Specification
9//!
10//! Fiducia is a system-architecture language for [seL4 Microkit](https://trustworthy.systems/projects/microkit/)
11//! embedded systems. It separates *system structure* (memory, isolation domains, channels) from
12//! *per-domain behaviour* (imported C/Pancake code, memory mappings, boot-time initialisation).
13//!
14//! ## Project Layout
15//!
16//! A Fiducia project is a directory containing:
17//!
18//! - Exactly **one** `.fis` file — the system description
19//! - **One** `.fi` file per protection domain named in the `System` declaration
20//! (filename stem must match the PD name, e.g. `eth_outer.fi` implements `eth_outer`)
21//! - The **foreign sources** the programs import (`import "c/eth.h" as eth;`):
22//! `.h`/`.c` (C), `.rs` (Rust crate root), `.pnk` (Pancake). fic reads them
23//! to learn their exported functions, so `eth.send(..)` is checked against
24//! `c/eth.h` at `--check` time
25//!
26//! ```text
27//! my_project/
28//! system.fis # system description
29//! eth_outer.fi # implements PD eth_outer
30//! eth_inner.fi # implements PD eth_inner
31//! dd.fi # implements PD dd
32//! c/eth.h, c/eth.c # a driver: the header is the interface, the .c is linked
33//! ```
34//!
35//! ## Comments
36//!
37//! Both `.fis` and `.fi` files support C-style comments:
38//!
39//! ```text
40//! // line comment
41//! /* block comment */
42//! ```
43//!
44//! ## Numeric Literals
45//!
46//! All addresses, sizes, and priorities are written as integer literals:
47//!
48//! - **Decimal** — `100`, `254`, `1000`
49//! - **Hexadecimal** — `0x1000`, `0x200000`, `0xFE00_0000`
50//! - Underscores are allowed as digit separators in hex literals: `0x3_000_000`
51//!
52//! # Quick Start
53//!
54//! Parse a system description:
55//!
56//! ```
57//! let input = r#"
58//! MemoryRegion uart(0x1000);
59//! ProtectionDomain driver(100);
60//! ProtectionDomain app(200);
61//! Chan notify = driver <-> app;
62//! System = driver ||| app;
63//! "#;
64//!
65//! let system = fic::parser::parse_system(input).unwrap();
66//! assert_eq!(system.protection_domains.len(), 2);
67//! ```
68//!
69//! Lower to SDF IR and inspect:
70//!
71//! ```
72//! let system = fic::parser::parse_system("ProtectionDomain test(100, 7); MemoryRegion buf(0x1000);").unwrap();
73//! // One program per protection domain, by position; every program binds
74//! // both kernel entry points, its handler here awaiting the PD's IRQ.
75//! let programs = vec![fic::parser::parse_program(
76//! "@bind(microkit.init) proc Init() { Skip; }\n\
77//! @bind(microkit.notified) proc Notified() { irq?7 -> Notified(); }",
78//! ).unwrap()];
79//! let rawast = fic::ast::RawAst { system, programs };
80//! let (env, tenv) = fic::frontend::data_layer(&rawast).unwrap();
81//! let front = fic::frontend::front_end(&rawast, &mut fic::foreign::ForeignModules::new(), env, tenv).unwrap();
82//! let args = microkit_tool::argparse::Args {
83//! sdf_path: std::path::Path::new("").to_path_buf(),
84//! board: "qemu_virt_aarch64".to_string(),
85//! config: "debug".to_string(),
86//! report_path: std::path::Path::new("report.txt").to_path_buf(),
87//! capdl_json_path: None,
88//! viper_output_dir: None,
89//! output_path: std::path::Path::new("test.img").to_path_buf(),
90//! search_paths: vec![],
91//! requested_image_type: microkit_tool::argparse::RequestedImageType::Unspecified,
92//! override_kernel: None,
93//! };
94//!let sdk = microkit_tool::sdk::Sdk::discover().unwrap();
95//!let config = microkit_tool::sel4::Config::build_kernel_config(&args, &sdk).unwrap();
96//!
97//! let sdf = fic::microkit::to_sdf(&config, &front.tenv).unwrap();
98//! assert_eq!(sdf.memory_regions.len(), 1);
99//! assert_eq!(sdf.memory_regions[0].name, "buf");
100//! ```
101//!
102//! Parse a program implementation:
103//!
104//! ```
105//! let input = r#"
106//! import "eth.c" as eth;
107//! Mapping ring_buffer(ring_buffer_outer, "rw", false);
108//! "#;
109//!
110//! let program = fic::parser::parse_program(input).unwrap();
111//! assert_eq!(program.imports.len(), 1);
112//! assert_eq!(program.mappings.len(), 1);
113//! ```
114
115#![warn(missing_docs)]
116
117pub mod ast;
118pub mod base;
119pub mod c_backend;
120pub mod ccfg;
121pub mod emit;
122pub mod error;
123pub mod foreign;
124pub mod frontend;
125pub mod microkit;
126pub mod middle;
127pub mod parser;
128pub mod rast;
129pub mod tast;
130pub mod ty;
131pub mod wfcheck;
132pub mod xta_backend;