Expand description
Foreign declarations: the functions a program can call through an
import "file" as alias;, and the readers that produce them from
the imported source. No toolchain is embedded beyond what a reader
itself needs (libclang for C; the Pancake reader and this module’s own
types need nothing).
fic reads the imported source itself and records each exported function
as an AST node (rustc’s ast::ForeignMod/ForeignItemKind::Fn, but
derived rather than hand-written). One ForeignModule per imported
file is loaded into ForeignModules, beside the AST, numbered by its
ModuleId, with each program’s imported files (links). rast resolves
an alias.f to the export and keeps each called function once, by
FfnId: its name and signature, lowered to fic’s types
(ty::foreign, one lowering per language), in Env.ffis, and where it
is, in the store’s ffis. The backends read the files, the called
functions and the links from the store.
Signatures are kept in a surface form (ForeignType): the type as
the foreign language spells it, reduced to what any C-ABI boundary can
express. Lowering to fic types (uint8_t → a fic scalar, a pointer →
Address, struct Slot → a fic struct) is ty::foreign’s, which
rast runs on each called function, not this module’s.
Which files can be imported, what counts as exported, and how each is read:
| file | language | reader | exported functions |
|---|---|---|---|
.h/.c | C | c: libclang, the real C front end | non-static, non-inline prototypes/definitions |
.pnk | Pancake | pnk: a text scanner, no external tool run; its /@ … @/ contracts parsed by the pancake2viper crate (linked in) and lifted in pnk::annotation | export fun (≤ 4 word arguments, one word return), with its /@ … @/ annotations |
Every language has a reader, so every module is complete: a call
resolves to one of its functions or is an error (rast).
Calling convention, layout, symbol location and any runtime set-up
(Pancake’s heap initialisation) are the backend’s concern, not this
module’s. This module keeps what the reader found — a ForeignContract
beside each signature; pnk::annotation and c::acsl give it meaning.
Modules§
- c
- C: the reader (libclang), and ACSL contracts read through Frama-C.
- calls
- Call sites of imported functions in a
.fiprogram, with how each call’s value is used — the information both the C backend (prototypes) and the contract checks need. - contract
- The contract IR: an imported function’s annotations, whichever language
they were written in (Viper for
.pnk, ACSL for.c). ATermover parameters, constants andretval, aFnContractper function, and aContractTablekeyed by the foreign function. The readers produce it;xta_backend::contractrenders it. - pnk
- Pancake: the reader (
pnk.rs, a scanner running no external tool) and the lifting of its/@ … @/annotations through thepancake2vipercrate (annotation.rs).pancake2viperproves the contracts against the code; the model assumes them (seedemo/pingpongpan/README.md).
Structs§
- Annotation
- One verifier annotation of a foreign declaration, as written.
- Foreign
Contract - The verifier side of a
ForeignFn: its contract as written, and why it is impure. Lifted into the neutral IR at extraction. - Foreign
Fn - A foreign function as the imported file declares it.
- Foreign
FnRef - Where a foreign function is: its file, and its position among that file’s exports.
- Foreign
Module - One imported file and the functions it exports. Shared by every program
that imports the same file: it is read and parsed once, into
ForeignModules, which keeps it. - Foreign
Modules - The foreign files a project has loaded, one
ForeignModuleper distinct file — the loaded-modules store, not part of the AST. - Foreign
Param - One parameter of a
ForeignFn. The name is informational — C prototypes may omit it (int f(int)). - Link
- A file a program imports, as its first import of it writes it.
Enums§
- Foreign
Kind - What an imported file is, decided from its extension in one place
(the front end, as it binds a program’s imports): its language, and for
C whether it is a header (a separately compiled driver, its
.clinked beside the unit) or a source (inlined into the unit). - Foreign
Lang - The language an imported file is written in — decided by its extension.
- Foreign
Type - A type at a C-ABI boundary, as spelled in the foreign language and
reduced to what fic can reason about. Qualifiers (
const,volatile) are dropped; they do not change the call.
Constants§
- INCLUDE_
DIR - The include directory, relative to the project.
- MARKER
- The first line of every file fic writes.
Traits§
- Header
- One foreign language’s data-layer header.
- Lift
- One foreign language’s contract lifting.
- Reader
- One foreign language’s reader.
Functions§
- export
- Write each header
rawastneeds, from its data layertenv(typed bytast::build_data). Returns<project>/include. - extract
- The contract of every foreign function a program calls, each file lifted once, and the call-site checks.
- load
- Load every import of
rawast’s programs, one libclang for all its C files, then record each program’s files (ForeignModules::bind). A C file is read with the include path the image build compiles it with: the project directorydir, theninclude, thenextra. - parse
- Read one imported file with its language’s
Reader.