Generated Headers
A struct or const declared in the data layer
is the one definition both sides of the foreign boundary use. fic writes
it out for each foreign language, from the typed .fis, before any import
is read.
| File | For | Written when |
|---|---|---|
include/gen/types.h | C imports | the .fis declares a struct or a const |
include/gen/types.pnk | Pancake imports | some program imports a .pnk file |
include/gen/mem.h | C imports | some program imports a .c or .h file; see Foreign Functions |
Both live under <project>/include/gen/; <project>/include is on every
tool’s include path, so a foreign file writes #include "gen/types.h" (or
.pnk). The rest of include/ is yours. Each generated file opens with a
Generated by fic ... Do not edit. marker and is rewritten on every
build. fic refuses to overwrite a file in that place that it did not
write. fire clean removes include/gen/.
types.h
Each struct is written in field order, followed by an assertion on its size:
struct Message {
uint16_t length;
uint16_t kind;
uint32_t offset;
};
_Static_assert(sizeof(struct Message) == 8, "fic: struct Message layout");
struct Slot {
uint16_t flags;
uint16_t seq;
struct Message msg;
};
_Static_assert(sizeof(struct Slot) == 12, "fic: struct Slot layout");
A Fiducia struct has C’s layout on the target: each field at its natural
alignment, padding included; an @attr(packed) struct is declared
struct __attribute__((packed)) Name, with no padding. The assertion makes a C compiler that would
lay the struct out differently fail the build, rather than disagree
silently with the model.
A constant is a #define, except under Frama-C, where it is a static const object so that a contract keeps the constant’s name instead of its
value:
#ifdef __FRAMAC__
static const uint64_t SLOT_SIZE = 2048;
#else
#define SLOT_SIZE 2048
#endif
Fiducia scalars are spelled as the fixed-width C types (int as
int64_t, uint as uint64_t, Address as uintptr_t, bool as
bool). An array field is written with its length: the constant, when
the .fis named one (uint8_t buf[SLOT_SIZE]), else the number.
types.pnk
Pancake has no structs here: types.pnk carries the folded constants as
#defines, which the CakeML preprocessor and pancake2viper both read.
#define ROUNDS 5
Structs are not translated.