Fil-C on Nix

Filnix wiki

the formal campaign

rocq/backend/EmitModule.v

# The lines of a module

As filc_amd64.pl's module_emit/4 with every temporary in its stack slot: the lines of each item in order, then those of each weak thunk, then the end of the file. The gate (emit.sh) holds each list to the Prolog compiler's.

From Stdlib Require Import String ZArith List Bool
From Nanofil Require Import Term Syntax Maps
From Backend Require Import Text Asm Plan Abi Layout Emit EmitData EmitThunk
Import ListNotations
Open Scope list_scope

The lines of an item, a function's with selected branches or not. Nothing for a function the model keeps outside the core subset, or one the backend builds no plan for.

17Definition item_codeselected : bool sy : symbols it : item : optionlistline ≔
match it with
⇒
option_mapfunction_codeselected lower_functionsy f
⇒
None
IDatan lk align items
⇒
Somedata_linesn lk align items
IAliasn lk target
⇒
Somealias_linessy n lk target

The end of the file: the stack is not executable.

26Definition end_lines: listline ≔

The last piece of every module. It stands alone, with its type written out, because a C++ extraction cannot type a Some inside a function that is an element of a list.

31Definition end_piece_ : unit : optionlistlistline ≔

A module's lists of lines, a piece at a time, in the order module_emit/4 gives them: a piece for each item, one for all the weak thunks and one for the end of the file. A driver asks for a piece, prints its lists and drops them before it asks for the next, so the lines of a whole module are never all alive. A piece is nothing if its item or a thunk has no lines.

39Definition module_codeselected : bool md : module : listunit → optionlistlistline ≔
let sy ≔ module_symbolsmd in
mapλit _ ⇒ option_mapλls ⇒ ls item_codeselected sy it md ++ λ_ ⇒ option_mapmapthunk_lines lower_thunkssy md; end_piece

The reference: no branch is selected.

47Definition item_lines: symbols → item → optionlistline ≔
48Definition module_pieces: module → listunit → optionlistlistline ≔

The lists of lines of a module: every piece's. Nothing if some piece is nothing.

53Definition module_linesmd : module : optionlistlistline ≔
option_map@concat_ all_someλpiece ⇒ piecett module_piecesmd