ATC tutorial: ACL2 events generated by ATC.
(This page may be skipped at first reading.)
As briefly mentioned in atc-tutorial-int-programs, ATC generates some events, besides the C file. This page describes these events in more detail.
These events are generated only if the
These events are generated in an encapsulate,
from which they are exported.
The encapsulate also includes
some locally generated events that support the exported events.
The option
ATC generates a named constant whose value is
the AST of the generated C program.
More precisely, it is the AST of the generated C file,
which is a value of the fixtype file in the abstract syntax of C. More precisely, it is the content of the generated file on disk:
the AST is pretty-printed to the
The
The reason for generating this constant is so that it can be used in the generated theorems described next, making the theorems more readable.
ATC generates a theorem asserting that the generated C program is statically correct, according to the formal static semantics of C.
More precisely, ATC generates a theorem of the form
(defthm <constant>-well-formed (equal (check-file <constant>) :wellformed))
This asserts that
when check-fileset is applied
to the named constant described above
(i.e. the abstract syntax of the generated C program),
the result is the value
Since the program AST is a constant and check-fileset is executable, the theorem is proved easily by execution.
The name of the theorem is obtained by appending
ATC generates theorems asserting that the generated C program is dynamically correct, according to the C dynamic semantics.
More precisely, for each target function
(defthm <constant>-<fn>-correct (implies (and <guard-of-fn> (compustatep compst) (integerp limit) (>= limit <number>)) (equal (exec-fun (ident "<fn>") (list <x1> ... <xn>) compst (init-fun-env (preprocess <constant>)) limit) (<fn> <x1> ... <xn>))))
This asserts that, under the guard of
The variable
The term
The variable
We remark that the form of the theorem above is accurate when none of the function's arguments are pointers. When they are, the theorem has a slightly more general form, which will be described in upcoming tutorial pages.
Note that, since
The guard satisfaction hypothesis is critical.
Without it, the C code may return some error,
e.g. if the result of an
The dynamic semantics of C is formalized in terms of a deep embedding of C in ACL2: C ASTs are explicitly modeled in ACL2, and (static and dynamic) semantics is defined on the ASTs. In contrast, the ACL2 representation of C programs, e.g. as described in atc-tutorial-int-representation, is like a shallow embedding of C in ACL2. Thus, the correctness theorem above provides a bridge between shallow and deep embedding. The two embeddings are in close correspondence by design, but the proofs are still not trivial, because the two embeddings are actually quite different in nature and details.
The correctness theorem above is proved by
expanding
These correctness proofs for functions are modular with respect to the function call graph: theorems about the correctness of callees are used to prove theorems about the correctness of callers. This is achieved via locally generated theorems that are more general than the exported ones (the latter are not compositional). Future versions of ATC may export these theorems from the encapsulate.
See atc-implementation for details on the generated theorems and their proofs.
The actual code is generated (i.e. written into the file)
after the events above have been successfully processed by ACL2.
Thus, if one of the theorems above fails for some reason,
no code is generated.
The rationale is that, unless the code can be proved correct,
it should not be generated.
Of course, this is easily defated by setting
This deferral is achieved by having ATC not generate the code directly, but by having ATC generate an event that generates the code. Thus, ATC generates this and the events above, putting the latter before the former, and submits the events, in that order. The effect is as desired.
Previous: ACL2 representation and generation of multiple C functions