Skip to main content

fic/foreign/pnk/
mod.rs

1//! Pancake: the reader (`pnk.rs`, a scanner running no external tool) and the lifting
2//! of its `/@ … @/` annotations through the `pancake2viper` crate
3//! (`annotation.rs`). `pancake2viper` proves the contracts against the code;
4//! the model assumes them (see `demo/pingpongpan/README.md`).
5//!
6//! Contract extraction is easy for Pancake specifically: an exported
7//! function takes and returns only words and can't see the generated C's
8//! state, so its whole effect on the model is its return value — exactly
9//! the `ensures` on `retval`.
10
11pub mod annotation;
12mod header;
13// The reader, named for the language.
14#[allow(clippy::module_inception)]
15mod pnk;
16
17pub(crate) use pnk::Pancake;
18
19use crate::ast::{Program, RawAst};
20use crate::foreign::ForeignKind;
21
22/// The `.pnk` imports of a program, in import order: `(alias, path)`.
23pub fn pancake_imports(program: &Program) -> Vec<(&str, &std::path::Path)> {
24    program
25        .imports
26        .iter()
27        .filter(|i| ForeignKind::of(&i.path) == Some(ForeignKind::Pancake))
28        .map(|i| (i.alias.as_str(), i.path.as_path()))
29        .collect()
30}
31
32/// `true` when some PD imports a `.pnk` file.
33pub fn has_pancake_imports(rawast: &RawAst) -> bool {
34    rawast
35        .programs
36        .iter()
37        .any(|p| !pancake_imports(p).is_empty())
38}
39
40/// The most parameters `CakeML` lets an exported function take from C.
41pub const MAX_EXPORT_ARGS: usize = 4;
42
43/// Microkit entry points the generated C defines: a Pancake export of the
44/// same name would be a second global definition in the PD's ELF.
45pub const ENTRY_POINTS: [&str; 3] = ["init", "notified", "protected"];