Theory Compiler
section "Compiler formalization"
theory Compiler
imports
"HOL-IMP.BExp"
"HOL-IMP.Star"
begin
subsection "Introduction"
text ‹
This paper presents a compiler correctness proof for the didactic imperative programming language
IMP, introduced in \<^cite>‹"Nipkow14"›, shorter than the proof described in \<^cite>‹"Nipkow14"› and
included in the Isabelle2021 distribution \<^cite>‹"Klein21"›. Actually, the size of the presented
proof is just two thirds of the book's proof in the number of formal text lines, and as such it
promises to constitute a further enhanced reference for the formal verification of compilers meant
for larger, real-world programming languages.
Given compiler \emph{completeness}, viz. the simulation of source code execution by compiled code,
"in a deterministic language like IMP", compiler correctness "reduces to preserving termination: if
the machine program terminates, so must the source program", even though proving this "is not much
easier" (\<^cite>‹"Nipkow14"›, section 8.4). However, the presented proof does not depend on language
determinism, so that the proposed approach is applicable to non-deterministic languages as well.
As a confirmation, this paper extends IMP with an additional command @{text "c⇩1 OR c⇩2"}, standing
for the non-deterministic choice between commands @{text c⇩1} and @{text c⇩2}, and proves compiler
\emph{correctness}, viz. the simulation of compiled code execution by source code, for such extended
language. Of course, the aforesaid comparison between proof sizes does not consider the lines in the
proof of lemma @{text ccomp_correct} (which proves compiler correctness for commands) pertaining to
non-deterministic choice, since this command is not included in the original language IMP. Anyway,
non-deterministic choice turns out to extend that proof just by a modest number of lines.
For further information about the formal definitions and proofs contained in this paper, see
Isabelle documentation, particularly \<^cite>‹"Paulson21"›, \<^cite>‹"Nipkow21"›, \<^cite>‹"Krauss21"›,
and \<^cite>‹"Nipkow11"›.
›
subsection "Definitions"
text ‹
Here below are the definitions of IMP commands, extended with non-deterministic choice, as well as
of their big-step semantics.
As in the original theory file \<^cite>‹"Klein21"›, program counter's values are modeled using type
@{typ int} rather than @{typ nat}. As a result, the same declarations and definitions used in
\<^cite>‹"Klein21"› to deal with this modeling choice are adopted here as well.
\null
›
declare [[coercion_enabled]]
declare [[coercion "int :: nat ⇒ int"]]
declare [[syntax_ambiguity_warning = false]]