1 | \documentclass[a4paper, 10pt]{article} |
---|
2 | |
---|
3 | \usepackage{a4wide} |
---|
4 | \usepackage{amsfonts} |
---|
5 | \usepackage{amsmath} |
---|
6 | \usepackage{amssymb} |
---|
7 | \usepackage[english]{babel} |
---|
8 | \usepackage{color} |
---|
9 | \usepackage{diagrams} |
---|
10 | \usepackage{graphicx} |
---|
11 | \usepackage[colorlinks]{hyperref} |
---|
12 | \usepackage[utf8x]{inputenc} |
---|
13 | \usepackage{listings} |
---|
14 | \usepackage{microtype} |
---|
15 | \usepackage{skull} |
---|
16 | \usepackage{stmaryrd} |
---|
17 | \usepackage{array} |
---|
18 | \newcolumntype{b}{@{}>{{}}} |
---|
19 | \newcolumntype{B}{@{}>{{}}c<{{}}@{}} |
---|
20 | \newcolumntype{h}[1]{@{\hspace{#1}}} |
---|
21 | \newcolumntype{L}{>{$}l<{$}} |
---|
22 | \newcolumntype{C}{>{$}c<{$}} |
---|
23 | \newcolumntype{R}{>{$}r<{$}} |
---|
24 | \newcolumntype{S}{>{$(}r<{)$}} |
---|
25 | \newcolumntype{n}{@{}} |
---|
26 | \usepackage{wasysym} |
---|
27 | |
---|
28 | |
---|
29 | \lstdefinelanguage{matita-ocaml} { |
---|
30 | mathescape=true |
---|
31 | } |
---|
32 | \lstset{ |
---|
33 | language=matita-ocaml,basicstyle=\tt,columns=flexible,breaklines=false, |
---|
34 | showspaces=false, showstringspaces=false, extendedchars=false, |
---|
35 | inputencoding=utf8x, tabsize=2 |
---|
36 | } |
---|
37 | |
---|
38 | \title{Proof outline for the correctness of the CerCo compiler} |
---|
39 | \date{\today} |
---|
40 | \author{The CerCo team} |
---|
41 | |
---|
42 | \begin{document} |
---|
43 | |
---|
44 | \maketitle |
---|
45 | |
---|
46 | \section{Introduction} |
---|
47 | \label{sect.introduction} |
---|
48 | |
---|
49 | In the last project review of the CerCo project, the project reviewers |
---|
50 | recommended us to quickly outline a paper-and-pencil correctness proof |
---|
51 | for each of the stages of the CerCo compiler in order to allow for an |
---|
52 | estimation of the complexity and time required to complete the formalization |
---|
53 | of the proof. This has been possible starting from month 18 when we have |
---|
54 | completed the formalization in Matita of the datastructures and code of |
---|
55 | the compiler. |
---|
56 | |
---|
57 | In this document we provide a very high-level, pen-and-paper |
---|
58 | sketch of what we view as the best path to completing the correctness proof |
---|
59 | for the compiler. In particular, for every translation between two intermediate languages, in both the front- and back-ends, we identify the key translation steps, and identify some invariants that we view as being important for the correctness proof. We sketch the overall correctness results, and also briefly describe the parts of the proof that have already |
---|
60 | been completed at the end of the First Period. |
---|
61 | |
---|
62 | In the last section we finally present an estimation of the effort required |
---|
63 | for the certification in Matita of the compiler and we draw conclusions. |
---|
64 | |
---|
65 | \section{Front-end: Clight to RTLabs} |
---|
66 | |
---|
67 | The front-end of the CerCo compiler consists of several stages: |
---|
68 | |
---|
69 | \begin{center} |
---|
70 | \begin{minipage}{.8\linewidth} |
---|
71 | \begin{tabbing} |
---|
72 | \quad \= $\downarrow$ \quad \= \kill |
---|
73 | \textsf{Clight}\\ |
---|
74 | \> $\downarrow$ \> cast removal\\ |
---|
75 | \> $\downarrow$ \> add runtime functions\footnote{Following the last project |
---|
76 | meeting we intend to move this transformation to the back-end}\\ |
---|
77 | \> $\downarrow$ \> cost labelling\\ |
---|
78 | \> $\downarrow$ \> loop optimizations\footnote{\label{lab:opt2}To be ported from the untrusted compiler and certified only in case of early completion of the certification of the other passes.} (an endo-transformation)\\ |
---|
79 | \> $\downarrow$ \> partial redundancy elimination$^{\mbox{\scriptsize \ref{lab:opt2}}}$ (an endo-transformation)\\ |
---|
80 | \> $\downarrow$ \> stack variable allocation and control structure |
---|
81 | simplification\\ |
---|
82 | \textsf{Cminor}\\ |
---|
83 | \> $\downarrow$ \> generate global variable initialisation code\\ |
---|
84 | \> $\downarrow$ \> transform to RTL graph\\ |
---|
85 | \textsf{RTLabs}\\ |
---|
86 | \> $\downarrow$ \> \\ |
---|
87 | \>\,\vdots |
---|
88 | \end{tabbing} |
---|
89 | \end{minipage} |
---|
90 | \end{center} |
---|
91 | |
---|
92 | Here, by `endo-transformation', we mean a mapping from language back to itself: |
---|
93 | the loop optimization step maps the Clight language to itself. |
---|
94 | |
---|
95 | %Our overall statements of correctness with respect to costs will |
---|
96 | %require a correctly labelled program |
---|
97 | There are three layers in most of the proofs proposed: |
---|
98 | \begin{enumerate} |
---|
99 | \item invariants closely tied to the syntax and transformations using |
---|
100 | dependent types (such as the presence of variable names in environments), |
---|
101 | \item a forward simulation proof relating each small-step of the |
---|
102 | source to zero or more steps of the target, and |
---|
103 | \item proofs about syntactic properties of the cost labelling. |
---|
104 | \end{enumerate} |
---|
105 | The first will support both functional correctness and allow us to |
---|
106 | show the totality of some of the compiler stages (that is, those |
---|
107 | stages of the compiler cannot fail). The second provides the main |
---|
108 | functional correctness result, including the preservation of cost |
---|
109 | labels in the traces, and the last will be crucial for applying |
---|
110 | correctness results about the costings from the back-end by showing |
---|
111 | that they appear in enough places so that we can assign all of the |
---|
112 | execution costs to them. |
---|
113 | |
---|
114 | We will also prove that a suitably labelled RTLabs trace can be turned |
---|
115 | into a \emph{structured trace} which splits the execution trace into |
---|
116 | cost-label to cost-label chunks with nested function calls. This |
---|
117 | structure was identified during work on the correctness of the |
---|
118 | back-end cost analysis as retaining important information about the |
---|
119 | structure of the execution that is difficult to reconstruct later in |
---|
120 | the compiler. |
---|
121 | |
---|
122 | \subsection{Clight cast removal} |
---|
123 | |
---|
124 | This transformation removes some casts inserted by the parser to make |
---|
125 | arithmetic promotion explicit but which are superfluous (such as |
---|
126 | \lstinline[language=C]'c = (short)((int)a + (int)b);' where |
---|
127 | \lstinline'a' and \lstinline'b' are \lstinline[language=C]'short'). |
---|
128 | This is necessary for producing good code for our target architecture. |
---|
129 | |
---|
130 | It only affects Clight expressions, recursively detecting casts that |
---|
131 | can be safely eliminated. The semantics provides a big-step |
---|
132 | definition for expression, so we should be able to show a lock-step |
---|
133 | forward simulation between otherwise identical states using a lemma |
---|
134 | showing that cast elimination does not change the evaluation of |
---|
135 | expressions. This lemma will follow from a structural induction on |
---|
136 | the source expression. We have already proved a few of the underlying |
---|
137 | arithmetic results necessary to validate the approach. |
---|
138 | |
---|
139 | \subsection{Clight cost labelling} |
---|
140 | |
---|
141 | This adds cost labels before and after selected statements and |
---|
142 | expressions, and the execution traces ought to be equivalent modulo |
---|
143 | the new cost labels. Hence it requires a simple forward simulation |
---|
144 | with a limited amount of stuttering whereever a new cost label is |
---|
145 | introduced. A bound can be given for the amount of stuttering allowed |
---|
146 | based on the statement or continuation to be evaluated next. |
---|
147 | |
---|
148 | We also intend to show three syntactic properties about the cost |
---|
149 | labelling: |
---|
150 | \begin{enumerate} |
---|
151 | \item every function starts with a cost label, |
---|
152 | \item every branching instruction is followed by a cost label (note that |
---|
153 | exiting a loop is treated as a branch), and |
---|
154 | \item the head of every loop (and any \lstinline'goto' destination) is |
---|
155 | a cost label. |
---|
156 | \end{enumerate} |
---|
157 | These can be shown by structural induction on the source term. |
---|
158 | |
---|
159 | \subsection{Clight to Cminor translation} |
---|
160 | |
---|
161 | This translation is the first to introduce some invariants, with the |
---|
162 | proofs closely tied to the implementation by dependent typing. These |
---|
163 | are largely complete and show that the generated code enjoys: |
---|
164 | \begin{itemize} |
---|
165 | \item some minimal type safety shown by explicit checks on the |
---|
166 | Cminor types during the transformation (a little more work remains |
---|
167 | to be done here, but follows the same form); |
---|
168 | \item that variables named in the parameter and local variable |
---|
169 | environments are distinct from one another, again by an explicit |
---|
170 | check; |
---|
171 | \item that variables used in the generated code are present in the |
---|
172 | resulting environment (either by checking their presence in the |
---|
173 | source environment, or from a list of freshly generated temporary variables); |
---|
174 | and |
---|
175 | \item that all \lstinline[language=C]'goto' labels are present (by |
---|
176 | checking them against a list of source labels and proving that all |
---|
177 | source labels are preserved). |
---|
178 | \end{itemize} |
---|
179 | |
---|
180 | The simulation will be similar to the relevant stages of CompCert |
---|
181 | (Clight to Csharpminor and Csharpminor to Cminor --- in the event that |
---|
182 | the direct proof is unwieldy we could introduce an intermediate |
---|
183 | language corresponding to Csharpminor). During early experimentation |
---|
184 | with porting CompCert definitions to the Matita proof assistant we |
---|
185 | found little difficulty reproving the results for the memory model, so |
---|
186 | we plan to port the memory injection properties and use them to relate |
---|
187 | Clight in-memory variables with either the value of the local variable or a |
---|
188 | stack slot, depending on how it was classified. |
---|
189 | |
---|
190 | This should be sufficient to show the equivalence of (big-step) |
---|
191 | expression evaluation. The simulation can then be shown by relating |
---|
192 | corresponding blocks of statement and continuations with their Cminor |
---|
193 | counterparts and proving that a few steps reaches the next matching |
---|
194 | state. |
---|
195 | |
---|
196 | The syntactic properties required for cost labels remain similar and a |
---|
197 | structural induction on the function bodies should be sufficient to |
---|
198 | show that they are preserved. |
---|
199 | |
---|
200 | \subsection{Cminor global initialisation code} |
---|
201 | |
---|
202 | This short phase replaces the global variable initialisation data with |
---|
203 | code that executes when the program starts. Each piece of |
---|
204 | initialisation data in the source is matched by a new statement |
---|
205 | storing that data. As each global variable is allocated a distinct |
---|
206 | memory block, the program state after the initialisation statements |
---|
207 | will be the same as the original program's state at the start of |
---|
208 | execution, and will proceed in the same manner afterwards. |
---|
209 | |
---|
210 | % Actually, the above is wrong... |
---|
211 | % ... this ought to be in a fresh main function with a fresh cost label |
---|
212 | |
---|
213 | \subsection{Cminor to RTLabs translation} |
---|
214 | |
---|
215 | In this part of the compiler we transform the program's functions into |
---|
216 | control flow graphs. It is closely related to CompCert's Cminorsel to |
---|
217 | RTL transformation, albeit with target-independent operations. |
---|
218 | |
---|
219 | We already enforce several invariants with dependent types: some type |
---|
220 | safety, mostly shown using the type information from Cminor; and |
---|
221 | that the graph is closed (by showing that each successor was recently |
---|
222 | added, or corresponds to a \lstinline[language=C]'goto' label which |
---|
223 | are all added before the end). Note that this relies on a |
---|
224 | monotonicity property; CompCert maintains a similar property in a |
---|
225 | similar way while building RTL graphs. We will also add a result |
---|
226 | showing that all of the pseudo-register names are distinct for use by |
---|
227 | later stages using the same method as Cminor. |
---|
228 | |
---|
229 | The simulation will relate Cminor states to RTLabs states which are about to |
---|
230 | execute the code corresponding to the Cminor statement or continuation. |
---|
231 | Each Cminor statement becomes zero or more RTLabs statements, with a |
---|
232 | decreasing measure based on the statement and continuations similar to |
---|
233 | CompCert's. We may also follow CompCert in using a relational |
---|
234 | specification of this stage so as to abstract away from the functional |
---|
235 | (and highly dependently typed) definition. |
---|
236 | |
---|
237 | The first two labelling properties remain as before; we will show that |
---|
238 | cost labels are preserved, so the function entry point will be a cost |
---|
239 | label, and successors to any statement that are cost labels map still |
---|
240 | map to cost labels, preserving the condition on branches. We replace |
---|
241 | the property for loops with the notion that we will always reach a |
---|
242 | cost label or the end of the function after following a bounded number of |
---|
243 | successors. This can be easily seen in Cminor using the requirement |
---|
244 | for cost labels at the head of loops and after gotos. It remains to |
---|
245 | show that this is preserved by the translation to RTLabs. % how? |
---|
246 | |
---|
247 | \subsection{RTLabs structured trace generation} |
---|
248 | |
---|
249 | This proof-only step incorporates the function call structure and cost |
---|
250 | labelling properties into the execution trace. As the function calls |
---|
251 | are nested within the trace, we need to distinguish between |
---|
252 | terminating and non-terminating function calls. Thus we use the |
---|
253 | excluded middle (specialised to a function termination property) to do |
---|
254 | this. |
---|
255 | |
---|
256 | Structured traces for terminating functions are built by following the |
---|
257 | flat trace, breaking it into chunks between cost labels and |
---|
258 | recursively processing function calls. The main difficulties here are |
---|
259 | the non-structurally recursive nature of the function (instead we use |
---|
260 | the size of the termination proof as a measure) and using the RTLabs |
---|
261 | cost labelling properties to show that the constraints of the |
---|
262 | structured traces are observed. We also show that the lower stack |
---|
263 | frames are preserved during function calls in order to prove that |
---|
264 | after returning from a function call we resume execution of the |
---|
265 | correct code. This part of the work has already been constructed, but |
---|
266 | still requires a simple proof to show that flattening the structured |
---|
267 | trace recreates the original flat trace. |
---|
268 | |
---|
269 | The non-terminating case follows the trace like the terminating |
---|
270 | version to build up chunks of trace from cost-label to cost-label |
---|
271 | (which, by the finite distance to a cost label property shown before, |
---|
272 | can be represented by an inductive type). These chunks are chained |
---|
273 | together in a coinductive data structure that can represent |
---|
274 | non-terminating traces. The excluded middle is used to decide whether |
---|
275 | function calls terminate, in which case the function described above |
---|
276 | constructs an inductive terminating structured trace which is nested |
---|
277 | in the caller's trace. Otherwise, another coinductive constructor is |
---|
278 | used to embed the non-terminating trace of the callee, generated by |
---|
279 | corecursion. This part of the trace transformation is currently under |
---|
280 | construction, and will also need a flattening result to show that it |
---|
281 | is correct. |
---|
282 | |
---|
283 | |
---|
284 | \section{Backend: RTLabs to machine code} |
---|
285 | \label{sect.backend.rtlabs.machine.code} |
---|
286 | |
---|
287 | The compiler backend consists of the following intermediate languages, and stages of translation: |
---|
288 | |
---|
289 | \begin{center} |
---|
290 | \begin{minipage}{.8\linewidth} |
---|
291 | \begin{tabbing} |
---|
292 | \quad \=\,\vdots\= \\ |
---|
293 | \> $\downarrow$ \>\\ |
---|
294 | \> $\downarrow$ \quad \= \kill |
---|
295 | \textsf{RTLabs}\\ |
---|
296 | \> $\downarrow$ \> copy propagation\footnote{\label{lab:opt}To be ported from the untrusted compiler and certified only in case of early completion of the certification of the other passes.} (an endo-transformation) \\ |
---|
297 | \> $\downarrow$ \> instruction selection\\ |
---|
298 | \> $\downarrow$ \> change of memory models in compiler\\ |
---|
299 | \textsf{RTL}\\ |
---|
300 | \> $\downarrow$ \> constant propagation$^{\mbox{\scriptsize \ref{lab:opt}}}$ (an endo-transformation) \\ |
---|
301 | \> $\downarrow$ \> calling convention made explicit \\ |
---|
302 | \> $\downarrow$ \> layout of activation records \\ |
---|
303 | \textsf{ERTL}\\ |
---|
304 | \> $\downarrow$ \> register allocation and spilling\\ |
---|
305 | \> $\downarrow$ \> dead code elimination\\ |
---|
306 | \textsf{LTL}\\ |
---|
307 | \> $\downarrow$ \> function linearisation\\ |
---|
308 | \> $\downarrow$ \> branch compression (an endo-transformation) \\ |
---|
309 | \textsf{LIN}\\ |
---|
310 | \> $\downarrow$ \> relabeling\\ |
---|
311 | \textsf{ASM}\\ |
---|
312 | \> $\downarrow$ \> pseudoinstruction expansion\\ |
---|
313 | \textsf{MCS-51 machine code}\\ |
---|
314 | \end{tabbing} |
---|
315 | \end{minipage} |
---|
316 | \end{center} |
---|
317 | |
---|
318 | \subsection{Graph translations} |
---|
319 | RTLabs and most intermediate languages in the back-end have a graph |
---|
320 | representation: |
---|
321 | the code of each function is represented by a graph of instructions. |
---|
322 | The graph maps a set of labels (the names of the nodes) to the instruction |
---|
323 | stored at that label (the nodes of the graph). |
---|
324 | Instructions reference zero or more additional labels that are the immediate |
---|
325 | successors of the instruction: zero for return from functions; more than one |
---|
326 | for conditional jumps and calls; one in all other cases. The references |
---|
327 | from one instruction to its immediates are the arcs of the graph. |
---|
328 | |
---|
329 | Status of graph languages always have a program counter that holds a |
---|
330 | representation of a reference to the current instruction. |
---|
331 | |
---|
332 | A translation between two consecutive graph languages maps each instruction |
---|
333 | stored at location $l$ in the first graph and with immediate successors |
---|
334 | $\{l_1,\ldots,l_n\}$ to a subgraph of the output graph that has a single |
---|
335 | entry point at location $l$ and exit arcs to $\{l_1,\ldots,l_n\}$. Moreover, |
---|
336 | the labels of all non entry nodes in the subgraph are distinct from all the |
---|
337 | labels in the source graph. |
---|
338 | |
---|
339 | In order to simplify the translations and the relative proofs of forward |
---|
340 | simulation, after the release of D4.2 and D4.3, we have provided: |
---|
341 | \begin{itemize} |
---|
342 | \item a new data type (called \texttt{blist}) that represents a |
---|
343 | sequence of instructions to be added to the output graph. |
---|
344 | The ``b'' in the name stands for binder, since a \texttt{blist} is |
---|
345 | either empty, an extension of a \texttt{blist} with an instruction |
---|
346 | at the front, or the generation of a fresh quantity followed by a |
---|
347 | \texttt{blist}. The latter feature is used, for instance, to generate |
---|
348 | fresh register names. The instructions in the list are unlabelled and |
---|
349 | all of them but the last one are also sequential, like in a linear program. |
---|
350 | \item a new iterator (called \texttt{b\_graph\_translate}) of type |
---|
351 | \begin{displaymath} |
---|
352 | \mathtt{b\_graph\_translate}: (\mathtt{label} \rightarrow \mathtt{blist}) |
---|
353 | \rightarrow \mathtt{graph} \rightarrow \mathtt{graph} |
---|
354 | \end{displaymath} |
---|
355 | The iterator transform the input graph in the output graph by replacing |
---|
356 | each node with the graph that corresponds to the linear \texttt{blist} |
---|
357 | obtained by applying the function in input to the node label. |
---|
358 | \end{itemize} |
---|
359 | |
---|
360 | Using the iterator above, the code can be written in such a way that |
---|
361 | the programmer does not see any distinction between writing a transformation |
---|
362 | on linear or graph languages. |
---|
363 | |
---|
364 | In order to prove simulations for translations obtained using the iterator, |
---|
365 | we will prove the following theorem: |
---|
366 | |
---|
367 | \begin{align*} |
---|
368 | \mathtt{theorem} &\ \mathtt{b\_graph\_translate\_ok}: \\ |
---|
369 | & \forall f.\forall G_{i}.\mathtt{let}\ G_{\sigma} := \mathtt{b\_graph\_translate}\ f\ G_{i}\ \mathtt{in} \\ |
---|
370 | & \forall l \in G_{i}.\mathtt{subgraph}\ (f\ l)\ l\ (next \ l \ G_i)\ G_{\sigma} |
---|
371 | \end{align*} |
---|
372 | |
---|
373 | Here \texttt{subgraph} is a computational predicate that given a \texttt{blist} |
---|
374 | $[i_1, \ldots, i_n]$, an entry label $l$, an exit label $l'$ and a graph $G$ |
---|
375 | expands to the fact that fetching from $G$ at address $l$ one retrieves a node |
---|
376 | $i_1$ with a successor $l_1$ that, when fetched, yields a node $i_2$ with a |
---|
377 | successor $l_2$ such that \ldots. The successor of $i_n$ is $l'$. |
---|
378 | |
---|
379 | Proving a forward simulation diagram of the following kind using the theorem |
---|
380 | above is now as simple as doing the same using standard small step operational |
---|
381 | semantics over linear languages. |
---|
382 | |
---|
383 | \begin{align*} |
---|
384 | \mathtt{lemma} &\ \mathtt{execute\_1\_step\_ok}: \\ |
---|
385 | & \forall s. \mathtt{let}\ s' := s\ \sigma\ \mathtt{in} \\ |
---|
386 | & \mathtt{let}\ l := pc\ s\ \mathtt{in} \\ |
---|
387 | & s \stackrel{1}{\rightarrow} s^{*} \Rightarrow \exists n. s' \stackrel{n}{\rightarrow} s'^{*} \wedge s'^{*} = s'\ \sigma |
---|
388 | \end{align*} |
---|
389 | |
---|
390 | Because of the fact that graph translation preserves entry and exit labels of |
---|
391 | translated statements, the state translation function $\sigma$ will simply |
---|
392 | preserve the value of the program counter. The program code, which is |
---|
393 | part of the state, is translated using the iterator. |
---|
394 | |
---|
395 | The proof is then roughly the following. Let $l$ be the program counter of the |
---|
396 | input state $s$. We proceed by cases on the current instruction of $s$. |
---|
397 | Let $[i_1, \ldots, i_n]$ be the \texttt{blist} associated to $l$ and $s$ |
---|
398 | by the translation function. The witness required for the existential |
---|
399 | statement is simply $n$. By applying the theorem above we know that the |
---|
400 | next $n$ instructions that will be fetched from $s\ \sigma$ will be |
---|
401 | $[i_1, \ldots, i_n]$ and it is now sufficient to prove that they simulate |
---|
402 | the original instruction. |
---|
403 | |
---|
404 | \subsection{The RTLabs to RTL translation} |
---|
405 | \label{subsect.rtlabs.rtl.translation} |
---|
406 | |
---|
407 | The RTLabs to RTL translation pass marks the frontier between the two memory models used in the CerCo project. |
---|
408 | As a result, we require some method of translating between the values that the two memory models permit. |
---|
409 | Suppose we have such a translation, $\sigma$. |
---|
410 | Then the translation between values of the two memory models may be pictured with: |
---|
411 | |
---|
412 | \begin{displaymath} |
---|
413 | \mathtt{Value} ::= \bot \mid \mathtt{int(size)} \mid \mathtt{float} \mid \mathtt{null} \mid \mathtt{ptr} \quad\stackrel{\sigma}{\longrightarrow}\quad \mathtt{BEValue} ::= \bot \mid \mathtt{byte} \mid \mathtt{null}_i \mid \mathtt{ptr}_i |
---|
414 | \end{displaymath} |
---|
415 | |
---|
416 | In the front-end, we have both integer and float values, where integer values are `sized', along with null values and pointers. Some frontenv values are |
---|
417 | representables in a byte, but some others require more bits. |
---|
418 | |
---|
419 | In the back-end model all values are meant to be represented in a single byte. |
---|
420 | Values can thefore be undefined, be one byte long integers or be indexed |
---|
421 | fragments of a pointer, null or not. Floats values are no longer present, as floating point arithmetic is not supported by the CerCo compiler. |
---|
422 | |
---|
423 | The $\sigma$ map implements a one-to-many relation: a single front-end value |
---|
424 | is mapped to a sequence of back-end values when its size is more then one byte. |
---|
425 | |
---|
426 | We further require a map, $\sigma$, which maps the front-end \texttt{Memory} and the back-end's notion of \texttt{BEMemory}. Both kinds of memory can be |
---|
427 | thought as an instance of a generic \texttt{Mem} data type parameterized over |
---|
428 | the kind of values stored in memory. |
---|
429 | |
---|
430 | \begin{displaymath} |
---|
431 | \mathtt{Mem}\ \alpha = \mathtt{Block} \rightarrow (\mathbb{Z} \rightarrow \alpha) |
---|
432 | \end{displaymath} |
---|
433 | |
---|
434 | Here, \texttt{Block} consists of a \texttt{Region} paired with an identifier. |
---|
435 | |
---|
436 | \begin{displaymath} |
---|
437 | \mathtt{Block} ::= \mathtt{Region} \times \mathtt{ID} |
---|
438 | \end{displaymath} |
---|
439 | |
---|
440 | We now have what we need for defining what is meant by the `memory' in the backend memory model. |
---|
441 | Namely, we instantiate the previously defined \texttt{Mem} type with the type of back-end memory values. |
---|
442 | |
---|
443 | \begin{displaymath} |
---|
444 | \mathtt{BEMem} = \mathtt{Mem}~\mathtt{BEValue} |
---|
445 | \end{displaymath} |
---|
446 | |
---|
447 | Memory addresses consist of a pair of back-end memory values: |
---|
448 | |
---|
449 | \begin{displaymath} |
---|
450 | \mathtt{Address} = \mathtt{BEValue} \times \mathtt{BEValue} \\ |
---|
451 | \end{displaymath} |
---|
452 | |
---|
453 | The back- and front-end memory models differ in how they represent sized integeer values in memory. |
---|
454 | In particular, the front-end stores integer values as a header, with size information, followed by a string of `continuation' blocks, marking out the full representation of the value in memory. |
---|
455 | In contrast, the layout of sized integer values in the back-end memory model consists of a series of byte-sized `chunks': |
---|
456 | |
---|
457 | \begin{center} |
---|
458 | \begin{picture}(0, 25) |
---|
459 | \put(-125,0){\framebox(25,25)[c]{\texttt{v,4}}} |
---|
460 | \put(-100,0){\framebox(25,25)[c]{\texttt{cont}}} |
---|
461 | \put(-75,0){\framebox(25,25)[c]{\texttt{cont}}} |
---|
462 | \put(-50,0){\framebox(25,25)[c]{\texttt{cont}}} |
---|
463 | \put(-15,10){\vector(1, 0){30}} |
---|
464 | \put(25,0){\framebox(25,25)[c]{\texttt{\texttt{v$_1$}}}} |
---|
465 | \put(50,0){\framebox(25,25)[c]{\texttt{\texttt{v$_2$}}}} |
---|
466 | \put(75,0){\framebox(25,25)[c]{\texttt{\texttt{v$_3$}}}} |
---|
467 | \put(100,0){\framebox(25,25)[c]{\texttt{\texttt{v$_4$}}}} |
---|
468 | \end{picture} |
---|
469 | \end{center} |
---|
470 | |
---|
471 | Chunks for pointers are pairs made of the original pointer and the index of the chunk. |
---|
472 | Therefore, when assembling the chunks together, we can always recognize if all chunks refer to the same value or if the operation is meaningless. |
---|
473 | |
---|
474 | The differing memory representations of values in the two memory models imply the need for a series of lemmas on the actions of \texttt{load} and \texttt{store} to ensure correctness. |
---|
475 | The first lemma required has the following statement: |
---|
476 | \begin{displaymath} |
---|
477 | \mathtt{load}\ s\ a\ M = \mathtt{Some}\ v \rightarrow \forall i \leq s.\ \mathtt{load}\ s\ (a + i)\ \sigma(M) = \mathtt{Some}\ v_i |
---|
478 | \end{displaymath} |
---|
479 | That is, if we are successful in reading a value of size $s$ from memory at address $a$ in front-end memory, then we should successfully be able to read all of its chunks from memory in the back-end memory at appropriate address (from address $a$ up to and including address $a + i$, where $i \leq s$). |
---|
480 | |
---|
481 | Next, we must show that \texttt{store} properly commutes with the $\sigma$-map between memory spaces: |
---|
482 | \begin{displaymath} |
---|
483 | \sigma(\mathtt{store}\ a\ v\ M) = \mathtt{store}\ \sigma(v)\ \sigma(a)\ \sigma(M) |
---|
484 | \end{displaymath} |
---|
485 | That is, if we store a value \texttt{v} in the front-end memory \texttt{M} at address \texttt{a} and transform the resulting memory with $\sigma$, then this is equivalent to storing a transformed value $\mathtt{\sigma(v)}$ at address $\mathtt{\sigma(a)}$ into the back-end memory $\mathtt{\sigma(M)}$. |
---|
486 | |
---|
487 | Finally, the commutation properties between \texttt{load} and \texttt{store} are weakened in the $\sigma$-image of the memory. |
---|
488 | Writing \texttt{load}$^*$ for the multiple consecutive iterations of \texttt{load} used to fetch all chunks of a value, we must prove that, when $a \neq a'$: |
---|
489 | \begin{displaymath} |
---|
490 | \texttt{load}^* \sigma(a)\ (\mathtt{store}\ \sigma(a')\ \sigma(v)\ \sigma(M)) = \mathtt{load}^*\ \sigma(s)\ \sigma(a)\ \sigma(M) |
---|
491 | \end{displaymath} |
---|
492 | That is, suppose we store a transformed value $\mathtt{\sigma(v)}$ into a back-end memory $\mathtt{\sigma(M)}$ at address $\mathtt{\sigma(a')}$, using \texttt{store}, and then load from the address $\sigma(a)$. Even if $a$ and $a'$ are |
---|
493 | distinct by hypothesis, there is a priori no guarantee that the consecutive |
---|
494 | bytes for the value stored at $\sigma(a)$ are disjoint from those for the |
---|
495 | values stored at $\sigma(a')$. The fact that this holds is a non-trivial |
---|
496 | property of $\sigma$ to be proved. |
---|
497 | |
---|
498 | RTLabs states come in three flavours: |
---|
499 | \begin{displaymath} |
---|
500 | \begin{array}{rll} |
---|
501 | \mathtt{State} & ::= & (\mathtt{State} : \mathtt{Frame}^* \times \mathtt{Frame} \\ |
---|
502 | & \mid & \mathtt{Call} : \mathtt{Frame}^* \times \mathtt{Args} \times \mathtt{Return} \times \mathtt{Fun} \\ |
---|
503 | & \mid & \mathtt{Return} : \mathtt{Frame}^* \times \mathtt{Value} \times \mathtt{Return}) \times \mathtt{Mem} |
---|
504 | \end{array} |
---|
505 | \end{displaymath} |
---|
506 | \texttt{State} is the default state in which RTLabs programs are almost always in. |
---|
507 | The \texttt{Call} state is only entered when a call instruction is being executed, and then we immediately return to being in \texttt{State}. |
---|
508 | Similarly, \texttt{Return} is only entered when a return instruction is being executed, before returning immediately to \texttt{State}. |
---|
509 | All RTLabs states are accompanied by a memory, \texttt{Mem}, with \texttt{Call} and \texttt{Return} keeping track of arguments, return addresses and the results of functions. |
---|
510 | \texttt{State} keeps track of a list of stack frames. |
---|
511 | |
---|
512 | RTL states differ from their RTLabs counterparts, in including a program counter \texttt{PC}, stack-pointer \texttt{SP}, internal stack pointer \texttt{ISP}, a carry flag \texttt{CARRY} and a set of registers \texttt{REGS}: |
---|
513 | \begin{displaymath} |
---|
514 | \mathtt{State} ::= \mathtt{Frame}^* \times \mathtt{PC} \times \mathtt{SP} \times \mathtt{ISP} \times \mathtt{CARRY} \times \mathtt{REGS} |
---|
515 | \end{displaymath} |
---|
516 | The internal stack pointer \texttt{ISP}, and its relationship with the stack pointer \texttt{SP}, needs some comment. |
---|
517 | Due to the design of the MCS-51, and its minuscule stack, it was decided that the compiler would implement an emulated stack in external memory. |
---|
518 | As a result, we have two stack pointers in our state: \texttt{ISP}, which is the real, hardware stack, and \texttt{SP}, which is the stack pointer of the emulated stack in memory. |
---|
519 | The emulated stack is used for pushing and popping stack frames when calling or returning from function calls, however this is done using the hardware stack, indexed by \texttt{ISP} as an intermediary. |
---|
520 | Instructions like \texttt{LCALL} and \texttt{ACALL} are hardwired by the processor's design to push the return address on to the hardware stack. Therefore after a call has been made, and before a call returns, the compiler emits code to move the return address back and forth the two stacks. Parameters, return values |
---|
521 | and local variables are only present in the external stack. |
---|
522 | As a result, for most of the execution of the processor, the hardware stack is empty, or contains a single item ready to be moved into external memory. |
---|
523 | |
---|
524 | Once more, we require a relation $\sigma$ between RTLabs states and RTL states. |
---|
525 | Because $\sigma$ is one-to-many and, morally, a multi-function, |
---|
526 | we use in the following the functional notation for $\sigma$, using $\star$ |
---|
527 | in the output of $\sigma$ to mean that any value is accepted. |
---|
528 | \begin{displaymath} |
---|
529 | \mathtt{State} \stackrel{\sigma}{\longrightarrow} \mathtt{State} |
---|
530 | \end{displaymath} |
---|
531 | |
---|
532 | Translating an RTLabs state to an RTL state proceeds by cases on the particular type of state we are trying to translate, either a \texttt{State}, \texttt{Call} or a \texttt{Return}. |
---|
533 | For \texttt{State} we perform a further case analysis of the top stack frame, which decomposes into a tuple holding the current program counter value, the current stack pointer and the value of the registers: |
---|
534 | \begin{displaymath} |
---|
535 | \sigma(\mathtt{State} (\mathtt{Frame}^* \times \mathtt{\langle PC, REGS, SP \rangle})) \longrightarrow ((\sigma(\mathtt{Frame}^*), \sigma(\mathtt{PC}), \sigma(\mathtt{SP}), \star, \star, \sigma(\mathtt{REGS})), \sigma(\mathtt{Mem})) |
---|
536 | \end{displaymath} |
---|
537 | Translation then proceeds by translating the remaining stack frames, as well as the contents of the top stack frame. Any value for the internal stack pointer |
---|
538 | and the carry bit is admitted. |
---|
539 | |
---|
540 | Translating \texttt{Call} and \texttt{Return} states is more involved, as a commutation between a single step of execution and the translation process must hold: |
---|
541 | \begin{displaymath} |
---|
542 | \sigma(\mathtt{Return}(-)) \longrightarrow \sigma \circ \text{return one step} |
---|
543 | \end{displaymath} |
---|
544 | |
---|
545 | \begin{displaymath} |
---|
546 | \sigma(\mathtt{Call}(-)) \longrightarrow \sigma \circ \text{call one step} |
---|
547 | \end{displaymath} |
---|
548 | |
---|
549 | Here \emph{return one step} and \emph{call one step} refer to a pair of commuting diagrams relating the one-step execution of a call and return state and translation of both. |
---|
550 | We provide the one step commuting diagrams in Figure~\ref{fig.commuting.diagrams}. The fact that one execution step in the source language is not performed |
---|
551 | in the target language is not problematic for preservation of divergence |
---|
552 | because it is easy to show that every step from a \texttt{Call} or |
---|
553 | \texttt{Return} state is always preceeded/followed by one step that is always |
---|
554 | simulated. |
---|
555 | |
---|
556 | \begin{figure} |
---|
557 | \begin{displaymath} |
---|
558 | \begin{diagram} |
---|
559 | s & \rTo^{\text{one step of execution}} & s' \\ |
---|
560 | & \rdTo & \dTo \\ |
---|
561 | & & \llbracket s'' \rrbracket |
---|
562 | \end{diagram} |
---|
563 | \end{displaymath} |
---|
564 | |
---|
565 | \begin{displaymath} |
---|
566 | \begin{diagram} |
---|
567 | s & \rTo^{\text{one step of execution}} & s' \\ |
---|
568 | & \rdTo & \dTo \\ |
---|
569 | & & \llbracket s'' \rrbracket |
---|
570 | \end{diagram} |
---|
571 | \end{displaymath} |
---|
572 | \caption{The one-step commuting diagrams for \texttt{Call} and \texttt{Return} state translations} |
---|
573 | \label{fig.commuting.diagrams} |
---|
574 | \end{figure} |
---|
575 | |
---|
576 | The forward simulation proof for all steps that do not involve function calls are lengthy, but routine. |
---|
577 | They consist of simulating a front-end operation on front-end pseudo-registers and the front-end memory with sequences of back-end operations on the back-end pseudo-registers and back-end memory. |
---|
578 | The properties of $\sigma$ presented before that relate values and memories will need to be heavily exploited. |
---|
579 | |
---|
580 | The simulation of invocation of functions and returns from functions is less obvious. |
---|
581 | We sketch here what happens on the source code and on its translation. |
---|
582 | |
---|
583 | \begin{displaymath} |
---|
584 | \begin{array}{rcl} |
---|
585 | \mathtt{Call(id,\ args,\ dst,\ pc),\ State(Frame^*, Frame)} & \longrightarrow & \mathtt{Call(M(args), dst)}, \\ |
---|
586 | & & \mathtt{PUSH(Frame[PC := after\_return])} |
---|
587 | \end{array} |
---|
588 | \end{displaymath} |
---|
589 | Suppose we are given a \texttt{State} with a list of stack frames, with the top frame being \texttt{Frame}. |
---|
590 | Suppose also that the program counter in \texttt{Frame} points to a \texttt{Call} instruction, complete with arguments and destination address. |
---|
591 | Then this is executed by entering into a \texttt{Call} state where the arguments are loaded from memory, and the address pointing to the instruction immediately following the \texttt{Call} instruction is filled in, with the current stack frame being pushed on top of the stack with the return address substituted for the program counter. |
---|
592 | |
---|
593 | Now, what happens next depends on whether we are executing an internal or an external function. |
---|
594 | In the case where the call is to an external function, we have: |
---|
595 | \begin{displaymath} |
---|
596 | \begin{array}{rcl} |
---|
597 | \mathtt{Call(M(args), dst)}, & \stackrel{\mathtt{ret\_val = f(M(args))}}{\longrightarrow} & \mathtt{Return(ret\_val,\ dst,\ PUSH(...))} \\ |
---|
598 | \mathtt{PUSH(current\_frame[PC := after\_return])} & & |
---|
599 | \end{array} |
---|
600 | \end{displaymath} |
---|
601 | That is, the call to the external function enters a return state after first computing the return value by executing the external function on the arguments. |
---|
602 | Then the return state restores the program counter by popping the stack, and execution proceeds in a new \texttt{State}: |
---|
603 | \begin{displaymath} |
---|
604 | \begin{array}{rcl} |
---|
605 | \mathtt{Return(ret\_val,\ dst,\ PUSH(...))} & \longrightarrow & \mathtt{pc = POP\_STACK(regs[dst := M(ret\_val)],\ pc)} \\ |
---|
606 | & & \mathtt{State(regs[dst := M(ret\_val),\ pc)} |
---|
607 | \end{array} |
---|
608 | \end{displaymath} |
---|
609 | |
---|
610 | Suppose we are executing an internal function, however: |
---|
611 | \begin{displaymath} |
---|
612 | \begin{array}{rcl} |
---|
613 | \mathtt{Call(M(args), dst)} & \longrightarrow & \mathtt{SP = alloc,\ regs = \emptyset[- := params]} \\ |
---|
614 | \mathtt{PUSH(current\_frame[PC := after\_return])} & & \mathtt{State(regs,\ sp,\ pc_\emptyset,\ dst)} |
---|
615 | \end{array} |
---|
616 | \end{displaymath} |
---|
617 | Here, execution of the \texttt{Call} state first pushes the current frame with the program counter set to the address following the function call. |
---|
618 | The stack pointer allocates more space, the register map is initialized first to the empty map, assigning an undefined value to all register, before the value of the parameters is inserted into the map into the argument registers, and a new \texttt{State} follows. |
---|
619 | After this, the stack pointer is freed and a \texttt{Return} state is entered: |
---|
620 | \begin{displaymath} |
---|
621 | \begin{array}{rcl} |
---|
622 | \mathtt{sp = alloc,\ regs = \emptyset[- := PARAMS]} & \longrightarrow & \mathtt{free(sp)} \\ |
---|
623 | \mathtt{State(regs,\ sp,\ pc_\emptyset,\ dst)} & & \mathtt{Return(M(ret\_val), dst, Frames)} |
---|
624 | \end{array} |
---|
625 | \end{displaymath} |
---|
626 | Then the return state restores the program counter by popping the stack, and execution proceeds in a new \texttt{State}, like the case for external functions: |
---|
627 | \begin{displaymath} |
---|
628 | \begin{array}{rcl} |
---|
629 | \mathtt{free(sp)} & \longrightarrow & \mathtt{pc = POP\_STACK(regs[dst := M(ret\_val)],\ pc)} \\ |
---|
630 | \mathtt{Return(M(ret\_val), dst, frames)} & & \mathtt{State(regs[dst := M(ret\_val),\ pc)} |
---|
631 | \end{array} |
---|
632 | \end{displaymath} |
---|
633 | |
---|
634 | Translation from RTLabs to RTL states proceeds as follows. |
---|
635 | Return states are translated as is: |
---|
636 | \begin{displaymath} |
---|
637 | \mathtt{Return} \longrightarrow \mathtt{Return} |
---|
638 | \end{displaymath} |
---|
639 | |
---|
640 | \texttt{Call} states are translated to \texttt{Call\_ID} states: |
---|
641 | \begin{displaymath} |
---|
642 | \mathtt{Call(id,\ args,\ dst,\ pc)} \longrightarrow \mathtt{Call\_ID(id,\ \sigma'(args),\ \sigma(dst),\ pc)} |
---|
643 | \end{displaymath} |
---|
644 | Here, $\sigma$ and $\sigma'$ are two maps to be defined between pseudo-registers and lists of pseudo-registers, of the type: |
---|
645 | |
---|
646 | \begin{displaymath} |
---|
647 | \sigma: \mathtt{register} \rightarrow \mathtt{list\ register} |
---|
648 | \end{displaymath} |
---|
649 | |
---|
650 | and: |
---|
651 | |
---|
652 | \begin{displaymath} |
---|
653 | \sigma': \mathtt{list\ register} \rightarrow \mathtt{list\ register} |
---|
654 | \end{displaymath} |
---|
655 | |
---|
656 | where $\sigma'$ is implemented as: |
---|
657 | |
---|
658 | \begin{displaymath} |
---|
659 | \sigma' = \mathtt{flatten} \circ \sigma |
---|
660 | \end{displaymath} |
---|
661 | |
---|
662 | In the case of RTL, execution proceeds as follows. |
---|
663 | Suppose we are executing a \texttt{CALL\_ID} instruction. |
---|
664 | Then a case split occurs depending on whether we are executing an internal or an external function, as in the RTLabs case: |
---|
665 | \begin{displaymath} |
---|
666 | \begin{diagram} |
---|
667 | & & \llbracket \mathtt{CALL\_ID}(\mathtt{id}, \mathtt{args}, \mathtt{dst}, \mathtt{pc})\rrbracket & & \\ |
---|
668 | & \ldTo^{\text{external}} & & \rdTo^{\text{internal}} & \\ |
---|
669 | \skull & & & & \mathtt{regs} = [\mathtt{params}/-] \\ |
---|
670 | & & & & \mathtt{sp} = \mathtt{ALLOC} \\ |
---|
671 | & & & & \mathtt{PUSH}(\mathtt{carry}, \mathtt{regs}, \mathtt{dst}, \mathtt{return\_addr}), \mathtt{pc}_{0}, \mathtt{regs}, \mathtt{sp} \\ |
---|
672 | \end{diagram} |
---|
673 | \end{displaymath} |
---|
674 | Here, however, we differ from RTLabs when we attempt to execute an external function, in that we use a daemon (i.e. an axiom that can close any goal) to artificially close the case, as we have not yet implemented external functions in the backend. |
---|
675 | The reason for this lack of implementation is as follows. |
---|
676 | Though we have implemented an optimising assembler as the target of the compiler's backend, we have not yet implemented a linker for that assembler, so external functions can not yet be called. |
---|
677 | Whilst external functions are carried forth throughout the entirety of the compiler's frontend, we choose not to do the same for the backend, instead eliminating them in RTL. |
---|
678 | However, it is plausible that we could have carried external functions forth, in order to eliminate them at a later stage (i.e. when translating from LIN to assembly). |
---|
679 | |
---|
680 | In the case of an internal function being executed, we proceed as follows. |
---|
681 | The register map is initialized to the empty map, where all registers are assigned the undefined value, and then the registers corresponding to the function parameters are assigned the value of the parameters. |
---|
682 | Further, the stack pointer is reallocated to make room for an extra stack frame, then a frame is pushed onto the stack with the correct address to jump back to in place of the program counter. |
---|
683 | |
---|
684 | Note, in particular, that this final act of pushing a frame on the stack leaves us in an identical state to the RTLabs case, where the instruction |
---|
685 | \begin{displaymath} |
---|
686 | \mathtt{PUSH(current\_frame[PC := after\_return])} |
---|
687 | \end{displaymath} |
---|
688 | |
---|
689 | was executed. |
---|
690 | |
---|
691 | The execution of \texttt{Return} in RTL is similarly straightforward, with the return address, stack pointer, and so on, being computed by popping off the top of the stack, and the return value computed by the function being retrieved from memory: |
---|
692 | \begin{align*} |
---|
693 | \mathtt{return\_addr} & := \mathtt{top}(\mathtt{stack}) \\ |
---|
694 | v* & := M(\mathtt{rv\_regs}) \\ |
---|
695 | \mathtt{dst}, \mathtt{sp}, \mathtt{carry}, \mathtt{regs} & := \mathtt{pop} \\ |
---|
696 | \mathtt{regs}[v* / \mathtt{dst}] \\ |
---|
697 | \end{align*} |
---|
698 | |
---|
699 | \begin{displaymath} |
---|
700 | \begin{diagram} |
---|
701 | s & \rTo^1 & s' & \rTo^1 & s'' \\ |
---|
702 | \dTo & & & \rdTo & \dTo \\ |
---|
703 | \llbracket s \rrbracket & \rTo(1,3)^1 & & & \llbracket s'' \rrbracket \\ |
---|
704 | \mathtt{CALL} \\ |
---|
705 | \end{diagram} |
---|
706 | \end{displaymath} |
---|
707 | |
---|
708 | \begin{displaymath} |
---|
709 | \begin{diagram} |
---|
710 | s & \rTo^1 & s' & \rTo^1 & s'' \\ |
---|
711 | \dTo & & & \rdTo & \dTo \\ |
---|
712 | \ & \rTo(1,3) & & & \ \\ |
---|
713 | \mathtt{RETURN} \\ |
---|
714 | \end{diagram} |
---|
715 | \end{displaymath} |
---|
716 | |
---|
717 | \begin{align*} |
---|
718 | \mathrm{RTL\ status} & \ \ \mathrm{ERTL\ status} \\ |
---|
719 | \mathtt{sp} & = \mathtt{spl} / \mathtt{sph} \\ |
---|
720 | \mathtt{graph} & \mathtt{graph} + \mathtt{prologue}(s) + \mathtt{epilogue}(s) \\ |
---|
721 | & \mathrm{where}\ s = \mathrm{callee\ saved} + \nu \mathrm{RA} \\ |
---|
722 | \end{align*} |
---|
723 | |
---|
724 | \begin{displaymath} |
---|
725 | \begin{diagram} |
---|
726 | \mathtt{CALL} & \rTo^1 & \mathtt{inside\ function} \\ |
---|
727 | \dTo & & \dTo \\ |
---|
728 | \underbrace{\ldots}_{\llbracket \mathtt{CALL} \rrbracket} & \rTo & |
---|
729 | \underbrace{\ldots}_{\mathtt{prologue}} \\ |
---|
730 | \end{diagram} |
---|
731 | \end{displaymath} |
---|
732 | |
---|
733 | \begin{displaymath} |
---|
734 | \begin{diagram} |
---|
735 | \mathtt{RETURN} & \rTo^1 & \mathtt{.} \\ |
---|
736 | \dTo & & \dTo \\ |
---|
737 | \underbrace{\ldots}_{\mathtt{epilogue}} & \rTo & |
---|
738 | \underbrace{\ldots} \\ |
---|
739 | \end{diagram} |
---|
740 | \end{displaymath} |
---|
741 | |
---|
742 | \begin{align*} |
---|
743 | \mathtt{prologue}(s) = & \mathtt{create\_new\_frame}; \\ |
---|
744 | & \mathtt{pop\ ra}; \\ |
---|
745 | & \mathtt{save\ callee\_saved}; \\ |
---|
746 | & \mathtt{get\_params} \\ |
---|
747 | & \ \ \mathtt{reg\_params}: \mathtt{move} \\ |
---|
748 | & \ \ \mathtt{stack\_params}: \mathtt{push}/\mathtt{pop}/\mathtt{move} \\ |
---|
749 | \end{align*} |
---|
750 | |
---|
751 | \begin{align*} |
---|
752 | \mathtt{epilogue}(s) = & \mathtt{save\ return\ to\ tmp\ real\ regs}; \\ |
---|
753 | & \mathtt{restore\_registers}; \\ |
---|
754 | & \mathtt{push\ ra}; \\ |
---|
755 | & \mathtt{delete\_frame}; \\ |
---|
756 | & \mathtt{save return} \\ |
---|
757 | \end{align*} |
---|
758 | |
---|
759 | \begin{displaymath} |
---|
760 | \mathtt{CALL}\ id \mapsto \mathtt{set\_params};\ \mathtt{CALL}\ id;\ \mathtt{fetch\_result} |
---|
761 | \end{displaymath} |
---|
762 | |
---|
763 | \subsection{The ERTL to LTL translation} |
---|
764 | \label{subsect.ertl.ltl.translation} |
---|
765 | \newcommand{\declsf}[1]{\expandafter\newcommand\expandafter{\csname #1\endcsname}{\mathop{\mathsf{#1}}\nolimits}} |
---|
766 | \declsf{Livebefore} |
---|
767 | \declsf{Liveafter} |
---|
768 | \declsf{Defined} |
---|
769 | \declsf{Used} |
---|
770 | \declsf{Eliminable} |
---|
771 | \declsf{StatementSem} |
---|
772 | For the liveness analysis, we aim at a map |
---|
773 | $\ell \in \mathtt{label} \mapsto $ live registers at $\ell$. |
---|
774 | We define the following operators on ERTL statements. |
---|
775 | $$ |
---|
776 | \begin{array}{lL>{(ex. $}L<{)$}} |
---|
777 | \Defined(s) & registers defined at $s$ & r_1\leftarrow r_2+r_3 \mapsto \{r_1,C\}, \mathtt{CALL}~id\mapsto \text{caller-save} |
---|
778 | \\ |
---|
779 | \Used(s) & registers used at $s$ & r_1\leftarrow r_2+r_3 \mapsto \{r_2,r_3\}, \mathtt{CALL}~id\mapsto \text{parameters} |
---|
780 | \end{array} |
---|
781 | $$ |
---|
782 | Given $LA:\mathtt{label}\to\mathtt{lattice}$ (where $\mathtt{lattice}$ |
---|
783 | is the type of sets of registers\footnote{More precisely, it is thethe lattice |
---|
784 | of pairs of sets of pseudo-registers and sets of hardware registers, |
---|
785 | with pointwise operations.}, we also have have the following |
---|
786 | predicates: |
---|
787 | $$ |
---|
788 | \begin{array}{lL} |
---|
789 | \Eliminable_{LA}(\ell) & iff $s(\ell)$ has side-effects only on $r\notin LA(\ell)$ |
---|
790 | \\& |
---|
791 | (ex.\ $\ell : r_1\leftarrow r_2+r_3 \mapsto (\{r_1,C\}\cap LA(\ell)\neq\emptyset, |
---|
792 | \mathtt{CALL}id\mapsto \text{never}$) |
---|
793 | \\ |
---|
794 | \Livebefore_{LA}(\ell) &$:= |
---|
795 | \begin{cases} |
---|
796 | LA(\ell) &\text{if $\Eliminable_{LA}(\ell)$,}\\ |
---|
797 | (LA(\ell)\setminus \Defined(s(\ell)))\cup \Used(s(\ell) &\text{otherwise}. |
---|
798 | \end{cases}$ |
---|
799 | \end{array} |
---|
800 | $$ |
---|
801 | In particular, $\Livebefore$ has type $(\mathtt{label}\to\mathtt{lattice})\to |
---|
802 | \mathtt{label}\to\mathtt{lattice}$. |
---|
803 | |
---|
804 | The equation on which we build the fixpoint is then |
---|
805 | $$\Liveafter(\ell) \doteq \bigcup_{\ell' >_1 \ell} \Livebefore_{\Liveafter}(\ell')$$ |
---|
806 | where $\ell' >_1 \ell$ denotes that $\ell'$ is an immediate successor of $\ell$ |
---|
807 | in the graph. We do not require the fixpoint to be the least one, so the hypothesis |
---|
808 | on $\Liveafter$ that we require is |
---|
809 | $$\Liveafter(\ell) \supseteq \bigcup_{\ell' >_1 \ell} \Livebefore(\ell')$$ |
---|
810 | (for shortness we drop the subscript from $\Livebefore$). |
---|
811 | \subsection{The LTL to LIN translation} |
---|
812 | \label{subsect.ltl.lin.translation} |
---|
813 | Ad detailed elsewhere in the reports, due to the parameterized representation of |
---|
814 | the back-end languages, the pass described here is actually much more generic |
---|
815 | than the translation from LTL to LIN. It consists in a linearization pass |
---|
816 | that maps any graph-based back-end language to its corresponding linear form, |
---|
817 | preserving its semantics. In the rest of the section, however, we will keep |
---|
818 | the names LTL and LIN for the two partial instantiations of the parameterized |
---|
819 | language. |
---|
820 | |
---|
821 | We require a map, $\sigma$, from LTL statuses, where program counters are represented as labels in a graph data structure, to LIN statuses, where program counters are natural numbers: |
---|
822 | \begin{displaymath} |
---|
823 | \mathtt{pc : label} \stackrel{\sigma}{\longrightarrow} \mathbb{N} |
---|
824 | \end{displaymath} |
---|
825 | |
---|
826 | The LTL to LIN translation pass also linearises the graph data structure into a list of instructions. |
---|
827 | Pseudocode for the linearisation process is as follows: |
---|
828 | |
---|
829 | \begin{lstlisting} |
---|
830 | let rec linearise graph visited required generated todo := |
---|
831 | match todo with |
---|
832 | | l::todo -> |
---|
833 | if l $\in$ visited then |
---|
834 | let generated := generated $\cup\ \{$ Goto l $\}$ in |
---|
835 | let required := required $\cup$ l in |
---|
836 | linearise graph visited required generated todo |
---|
837 | else |
---|
838 | -- Get the instruction at label `l' in the graph |
---|
839 | let lookup := graph(l) in |
---|
840 | let generated := generated $\cup\ \{$ lookup $\}$ in |
---|
841 | -- Find the successor of the instruction at label `l' in the graph |
---|
842 | let successor := succ(l, graph) in |
---|
843 | let todo := successor::todo in |
---|
844 | linearise graph visited required generated todo |
---|
845 | | [] -> (required, generated) |
---|
846 | \end{lstlisting} |
---|
847 | |
---|
848 | It is easy to see that this linearisation process eventually terminates. |
---|
849 | In particular, the size of the visited label set is monotonically increasing, and is bounded above by the size of the graph that we are linearising. |
---|
850 | |
---|
851 | The initial call to \texttt{linearise} sees the \texttt{visited}, \texttt{required} and \texttt{generated} sets set to the empty set, and \texttt{todo} initialized with the singleton list consisting of the entry point of the graph. |
---|
852 | We envisage needing to prove the following invariants on the linearisation function above: |
---|
853 | |
---|
854 | \begin{enumerate} |
---|
855 | \item |
---|
856 | $\mathtt{visited} \approx \mathtt{generated}$, where $\approx$ is \emph{multiset} equality, as \texttt{generated} is a set of instructions where instructions may mention labels multiple times, and \texttt{visited} is a set of labels, |
---|
857 | \item |
---|
858 | $\forall \mathtt{l} \in \mathtt{generated}.\ \mathtt{succ(l,\ graph)} \subseteq \mathtt{required} \cup \mathtt{todo}$, |
---|
859 | \item |
---|
860 | $\mathtt{required} \subseteq \mathtt{visited}$, |
---|
861 | \item |
---|
862 | $\mathtt{visited} \cap \mathtt{todo} = \emptyset$. |
---|
863 | \end{enumerate} |
---|
864 | |
---|
865 | The invariants collectively imply the following properties, crucial to correctness, about the linearisation process: |
---|
866 | |
---|
867 | \begin{enumerate} |
---|
868 | \item |
---|
869 | Every graph node is visited at most once, |
---|
870 | \item |
---|
871 | Every instruction that is generated is generated due to some graph node being visited, |
---|
872 | \item |
---|
873 | The successor instruction of every instruction that has been visited already will eventually be visited too. |
---|
874 | \end{enumerate} |
---|
875 | |
---|
876 | Note, because the LTL to LIN transformation is the first time the code of |
---|
877 | a function is linearised in the back-end, we must discover a notion of `well formed function code' suitable for linearised forms. |
---|
878 | In particular, we see the notion of well formedness (yet to be formally defined) resting on the following conditions: |
---|
879 | |
---|
880 | \begin{enumerate} |
---|
881 | \item |
---|
882 | For every jump to a label in a linearised function code, the target label exists at some point in the function code, |
---|
883 | \item |
---|
884 | Each label is unique, appearing only once in the function code, |
---|
885 | \item |
---|
886 | The final instruction of a function code must be a return or an unconditional |
---|
887 | jump. |
---|
888 | \end{enumerate} |
---|
889 | |
---|
890 | We assume that these properties will be easy consequences of the invariants on the linearisation function defined above. |
---|
891 | |
---|
892 | The final condition above is potentially a little opaque, so we explain further. |
---|
893 | The only instructions that can reasonably appear in final position at the end of a function code are returns or backward jumps, as any other instruction would cause execution to `fall out' of the end of the program (for example, when a function invoked with \texttt{CALL} returns, it returns to the next instruction past the \texttt{CALL} that invoked it). |
---|
894 | |
---|
895 | \subsection{The LIN to ASM and ASM to MCS-51 machine code translations} |
---|
896 | \label{subsect.lin.asm.translation} |
---|
897 | |
---|
898 | The LIN to ASM translation step is trivial, being almost the identity function. |
---|
899 | The only non-trivial feature of the LIN to ASM translation is that all labels are `named apart' so that there is no chance of freshly generated labels from different namespaces clashing with labels from another namespace. |
---|
900 | |
---|
901 | The ASM to MCS-51 machine code translation step, and the required statements of correctness, are found in an unpublished manuscript attached to this document. |
---|
902 | This is the most complex translation because of the huge number of cases |
---|
903 | to be addressed and because of the complexity of the two semantics. |
---|
904 | Moreover, in the assembly code we have conditional and unconditional jumps |
---|
905 | to arbitrary locations in the code, which are not supported by the MCS-51 |
---|
906 | instruction set. The latter has several kind of jumps characterized by a |
---|
907 | different instruction size and execution time, but limited in range. For |
---|
908 | instance, conditional jumps to locations whose destination is more than |
---|
909 | $2^7$ bytes away from the jump instruction location are not supported at |
---|
910 | all and need to be emulated with a code transformation. The problem, which |
---|
911 | is known in the litterature as branch displacement and that applies also |
---|
912 | to modern architectures, is known to be hard and is often NP. As far as we |
---|
913 | know, we will provide the first formally verified proof of correctness for |
---|
914 | an assembler that implements branch displacement. We are also providing |
---|
915 | the first verified proof of correctness of a mildly optimizing branch |
---|
916 | displacement algorithm that, at the moment, is almost finished, but not |
---|
917 | described in the companion paper. This proof by itself took about 6 men |
---|
918 | months. |
---|
919 | |
---|
920 | \section{Correctness of cost prediction} |
---|
921 | Roughly speaking, |
---|
922 | the proof of correctness of cost prediction shows that the cost of executing |
---|
923 | a labelled object code program is the same as the sum over all labels in the |
---|
924 | program execution trace of the cost statically associated to the label and |
---|
925 | computed on the object code itself. |
---|
926 | |
---|
927 | In presence of object level function calls, the previous statement is, however, |
---|
928 | incorrect. The reason is twofold. First of all, a function call may diverge. |
---|
929 | To the last labels that comes before the call, however, we also associate |
---|
930 | the cost of the instructions that follow the call. Therefore, in the |
---|
931 | sum over all labels, when we meet a label we pre-pay for the instructions |
---|
932 | after function calls, assuming all calls to be terminating. This choice is |
---|
933 | driven by considerations on the source code. Functions can be called also |
---|
934 | inside expressions and it would be too disruptive to put labels inside |
---|
935 | expressions to capture the cost of instructions that follow a call. Moreover, |
---|
936 | adding a label after each call would produce a much higher number of proof |
---|
937 | obligations in the certification of source programs using Frama-C. The |
---|
938 | proof obligations, moreover, would be guarded by termination of all functions |
---|
939 | involved, that also generates lots of additional complex proof obligations |
---|
940 | that have little to do with execution costs. With our approach, instead, we |
---|
941 | put less burden on the user, at the price of proving a weaker statement: |
---|
942 | the estimated and actual costs will be the same if and only if the high level |
---|
943 | program is converging. For prefixes of diverging programs we can provide |
---|
944 | a similar result where the equality is replaced by an inequality (loss of |
---|
945 | precision). |
---|
946 | |
---|
947 | Assuming totality of functions is however not sufficient yet at the object |
---|
948 | level. Even if a function returns, there is no guarantee that it will transfer |
---|
949 | control back to the calling point. For instance, the function could have |
---|
950 | manipulated the return address from its stack frame. Moreover, an object level |
---|
951 | program can forge any address and transfer control to it, with no guarantee |
---|
952 | on the execution behaviour and labelling properties of the called program. |
---|
953 | |
---|
954 | To solve the problem, we introduced the notion of \emph{structured trace} |
---|
955 | that come in two flavours: structured traces for total programs (an inductive |
---|
956 | type) and structured traces for diverging programs (a co-inductive type based |
---|
957 | on the previous one). Roughly speaking, a structured trace represents the |
---|
958 | execution of a well behaved program that is subject to several constraints |
---|
959 | like |
---|
960 | \begin{enumerate} |
---|
961 | \item All function calls return control just after the calling point |
---|
962 | \item The execution of all function bodies start with a label and end with |
---|
963 | a RET (even the ones reached by invoking a function pointer) |
---|
964 | \item All instructions are covered by a label (required by correctness of |
---|
965 | the labelling approach) |
---|
966 | \item The target of all conditional jumps must be labelled (a sufficient |
---|
967 | but not necessary condition for precision of the labelling approach) |
---|
968 | \item \label{prop5} Two structured traces with the same structure yield the same |
---|
969 | cost traces. |
---|
970 | \end{enumerate} |
---|
971 | |
---|
972 | Correctness of cost predictions is proved only for structured execution traces, |
---|
973 | i.e. well behaved programs. The forward simulation proof for all back-end |
---|
974 | passes will actually be a proof of preservation of the structure of |
---|
975 | the structured traces that, because of property \ref{prop5}, will imply |
---|
976 | correctness of the cost prediction for the back-end. The Clight to RTLabs |
---|
977 | will also include a proof that associates to each converging execution its |
---|
978 | converging structured trace and to each diverging execution its diverging |
---|
979 | structured trace. |
---|
980 | |
---|
981 | There are also other two issues that invalidate the naive statement of |
---|
982 | correctness of cost prediciton given above. The algorithm that statically |
---|
983 | computes the cost of blocks is correct only when the object code is \emph{well |
---|
984 | formed} and the program counter is \emph{reachable}. |
---|
985 | A well formed object code is such that |
---|
986 | the program counter will never overflow after the execution step of |
---|
987 | the processor. An overflow that occurs during fetching but is overwritten |
---|
988 | during execution is, however, correct and necessary to accept correct |
---|
989 | programs that are as large as the program memory. Temporary overflows add |
---|
990 | complications to the proof. A reachable address is an address that can be |
---|
991 | obtained by fetching (not executing!) a finite number of times from the |
---|
992 | beginning of the code memory without ever overflowing. The complication is that |
---|
993 | the static prediction traverses the code memory assuming that the memory will |
---|
994 | be read sequentially from the beginning and that all jumps jump only to |
---|
995 | reachable addresses. When this property is violated, the way the code memory |
---|
996 | is interpreted is uncorrect and the cost computed is totally meaningless. |
---|
997 | The reachability relation is closed by fetching for well formed programs. |
---|
998 | The property that calls to function pointers only target reachable and |
---|
999 | well labelled locations, however, is not statically predictable and it is |
---|
1000 | enforced in the structured trace. |
---|
1001 | |
---|
1002 | The proof of correctness of cost predictions has been quite complex. Setting |
---|
1003 | up the good invariants (structured traces, well formed programs, reachability) |
---|
1004 | and completing the proof has required more than 3 men months while the initally |
---|
1005 | estimated effort was much lower. In the paper-and-pencil proof for IMP, the |
---|
1006 | corresponding proof was obvious and only took two lines. |
---|
1007 | |
---|
1008 | The proof itself is quite involved. We |
---|
1009 | basically need to show as an important lemma that the sum of the execution |
---|
1010 | costs over a structured trace, where the costs are summed in execution order, |
---|
1011 | is equivalent to the sum of the execution costs in the order of pre-payment. |
---|
1012 | The two orders are quite different and the proof is by mutual recursion over |
---|
1013 | the definition of the converging structured traces, which is a family of three |
---|
1014 | mutual inductive types. The fact that this property only holds for converging |
---|
1015 | function calls in hidden in the definition of the structured traces. |
---|
1016 | Then we need to show that the order of pre-payment |
---|
1017 | corresponds to the order induced by the cost traces extracted from the |
---|
1018 | structured trace. Finally, we need to show that the statically computed cost |
---|
1019 | for one block corresponds to the cost dinamically computed in pre-payment |
---|
1020 | order. |
---|
1021 | |
---|
1022 | \section{Overall results} |
---|
1023 | |
---|
1024 | Functional correctness of the compiled code can be shown by composing |
---|
1025 | the simulations to show that the target behaviour matches the |
---|
1026 | behaviour of the source program, if the source program does not `go |
---|
1027 | wrong'. More precisely, we show that there is a forward simulation |
---|
1028 | between the source trace and a (flattened structured) trace of the |
---|
1029 | output, and conclude equivalence because the target's semantics are |
---|
1030 | in the form of an executable function, and hence |
---|
1031 | deterministic. |
---|
1032 | |
---|
1033 | Combining this with the correctness of the assignment of costs to cost |
---|
1034 | labels at the ASM level for a structured trace, we can show that the |
---|
1035 | cost of executing any compiled function (including the main function) |
---|
1036 | is equal to the sum of all the values for cost labels encountered in |
---|
1037 | the \emph{source code's} trace of the function. |
---|
1038 | |
---|
1039 | \section{Estimated effort} |
---|
1040 | Based on the rough analysis performed so far we can estimate the total |
---|
1041 | effort for the certification of the compiler. We obtain this estimation by |
---|
1042 | combining, for each pass: 1) the number of lines of code to be certified; |
---|
1043 | 2) the ratio of number of lines of proof to number of lines of code from |
---|
1044 | the CompCert project~\cite{compcert} for the CompCert pass that is closest to |
---|
1045 | ours; 3) an estimation of the complexity of the pass according to the |
---|
1046 | analysis above. The result is shown in Table~\ref{table}. |
---|
1047 | |
---|
1048 | \begin{table}{h} |
---|
1049 | \begin{tabular}{lrlrr} |
---|
1050 | Pass origin & Code lines & CompCert ratio & Estimated effort & Estimated effort \\ |
---|
1051 | & & & (based on CompCert) & \\ |
---|
1052 | \hline |
---|
1053 | Common & 4864 & 4.25 \permil & 20.67 & 17.0 \\ |
---|
1054 | Cminor & 1057 & 5.23 \permil & 5.53 & 6.0 \\ |
---|
1055 | Clight & 1856 & 5.23 \permil & 9.71 & 10.0 \\ |
---|
1056 | RTLabs & 1252 & 1.17 \permil & 1.48 & 5.0 \\ |
---|
1057 | RTL & 469 & 4.17 \permil & 1.95 & 2.0 \\ |
---|
1058 | ERTL & 789 & 3.01 \permil & 2.38 & 2.5 \\ |
---|
1059 | LTL & 92 & 5.94 \permil & 0.55 & 0.5 \\ |
---|
1060 | LIN & 354 & 6.54 \permil & 2.31 & 1.0 \\ |
---|
1061 | ASM & 984 & 4.80 \permil & 4.72 & 10.0 \\ |
---|
1062 | \hline |
---|
1063 | Total common & 4864 & 4.25 \permil & 20.67 & 17.0 \\ |
---|
1064 | Total front-end & 2913 & 5.23 \permil & 15.24 & 16.0 \\ |
---|
1065 | Total back-end & 6853 & 4.17 \permil & 13.39 & 21.0 \\ |
---|
1066 | \hline |
---|
1067 | Total & 14630 & 3.75 \permil & 49.30 & 54.0 \\ |
---|
1068 | \end{tabular} |
---|
1069 | \caption{\label{table}Estimated effort} |
---|
1070 | \end{table} |
---|
1071 | |
---|
1072 | We provide now some additional informations on the methodology used in the |
---|
1073 | computation. The passes in Cerco and CompCert front-end closely match each |
---|
1074 | other. However, there is no clear correspondence between the two back-ends. |
---|
1075 | For instance, we enforce the calling convention immediately after instruction |
---|
1076 | selection, whereas in CompCert this is performed in a later phase. Or we |
---|
1077 | linearize the code at the very end, whereas CompCert performs linearization |
---|
1078 | as soon as possible. Therefore, the first part of the exercise has consisted |
---|
1079 | in shuffling and partitioning the CompCert code in order to assign to each |
---|
1080 | CerCo pass the CompCert code that performs the same transformation. |
---|
1081 | |
---|
1082 | After this preliminary step, using the data given in~\cite{compcert} (which |
---|
1083 | are relative to an early version of CompCert) we computed the ratio between |
---|
1084 | men months and lines of code in CompCert for each CerCo pass. This is shown |
---|
1085 | in the third column of Table~\ref{wildguess}. For those CerCo passes that |
---|
1086 | have no correspondence in CompCert (like the optimizing assembler) or where |
---|
1087 | we have insufficient data, we have used the average of the ratios computed |
---|
1088 | above. |
---|
1089 | |
---|
1090 | The first column of the table shows the number of lines of code for each |
---|
1091 | pass in CerCo. The third column is obtained multiplying the first with the |
---|
1092 | CompCert ratio. It provides an estimate of the effort required (in men months) |
---|
1093 | if the complexity of the proofs for CerCo and Compcert would be the same. |
---|
1094 | |
---|
1095 | The two proof styles, however, are on purpose completely different. Where |
---|
1096 | CompCert uses non executable semantics, describing the various semantics with |
---|
1097 | inductive types, we have preferred executable semantics. Therefore, CompCert |
---|
1098 | proofs by induction and inversion become proof by functional inversion, |
---|
1099 | performed using the Russel methodology (now called Program in Coq, but whose |
---|
1100 | behaviour differs from Matita's one). Moreover, CompCert code is written using |
---|
1101 | only types that belong to the Hindley-Milner fragment, whereas we have |
---|
1102 | heavily exploited dependent types all over the code. The dependent type |
---|
1103 | discipline offers many advantages from the point of view of clarity of the |
---|
1104 | invariants involved and early detection of errors and it naturally combines |
---|
1105 | well with the Russel approach which is based on dependent types. However, it |
---|
1106 | is also well known to introduce technical problems all over the code, like |
---|
1107 | the need to explicitly prove type equalities to be able to manipulate |
---|
1108 | expressions in certain ways. In many situations, the difficulties encountered |
---|
1109 | with manipulating dependent types are better addressed by improving the Matita |
---|
1110 | system, according to the formalization driven system development. For this |
---|
1111 | reason, and assuming a pessimistic point of view on our performance, the |
---|
1112 | fourth columns presents the final estimation of the effort required, that also |
---|
1113 | takes in account the complexity of the proof suggested by the informal proofs |
---|
1114 | sketched in the previous section. |
---|
1115 | |
---|
1116 | \subsection{Contingency plan} |
---|
1117 | On the basis of the proof strategy sketched in this document and the |
---|
1118 | estimated effort, we can refine our contingency plan. In case we will end |
---|
1119 | the certification of the basic compiler in advance we will have the choice |
---|
1120 | of either proving loop optimizations and/or partial redundancy elimination |
---|
1121 | correct (both tasks that seem difficult to achieve in a short time) or |
---|
1122 | considering the MCS-51 specific extensions introduced during the first period |
---|
1123 | and under-used in the formalized prototype. Yet another possibility would be |
---|
1124 | to better study retargeting of the code and the commutation property between |
---|
1125 | different compiler passes. The latter study is easily enabled by our |
---|
1126 | approach where all back-end languages are instances of the same parameterized |
---|
1127 | language. |
---|
1128 | |
---|
1129 | In the case of a consistent delay in the certification of some |
---|
1130 | components, we will address first the passes that are more likely to have |
---|
1131 | undetected bugs and we will follow a top-down approach, axiomatizing |
---|
1132 | the properties of the data structured used in the compiler to focus more |
---|
1133 | on the algorithms. The rational is that data structures are easier then |
---|
1134 | algorithms to test using well known methodologies. |
---|
1135 | The effort table clearly shows that commond definitions |
---|
1136 | and data structures are 1/4th of the size of the code and require slightly |
---|
1137 | less than 1/3rd of the total effort. At least half of this effort really goes |
---|
1138 | into simple data structures (vectors, bounded and unbounded integers, tries |
---|
1139 | and maps) whose certification is not interesting and whose code could be |
---|
1140 | taken without re-proving it from the library of any other theorem prover. |
---|
1141 | |
---|
1142 | \section{Conclusions} |
---|
1143 | The overall exercise, whose details have been only minimally reported here, |
---|
1144 | has been very useful. It has allowed to spot in an early moment some criticities |
---|
1145 | of the proof that have required major changes in the proof plan. It has also |
---|
1146 | shown that the last passes of the compilation (e.g. assembly) and cost |
---|
1147 | prediction on the object code are much more involved than more high level |
---|
1148 | passes. |
---|
1149 | |
---|
1150 | The final estimation for the effort is surely affected by a low degree of |
---|
1151 | confidence. It is however sufficient to conclude that the effort required |
---|
1152 | is in line with the man power that was scheduled for the second half of the |
---|
1153 | second period and for the third period. Compared to the number of men months |
---|
1154 | declared in Annex I of the contract, we will need more men months. However, |
---|
1155 | both at UNIBO and UEDIN there have been major differences in hiring with |
---|
1156 | respect to the Annex. Therefore both sites have now an higher number of men |
---|
1157 | months available, with the trade-off of a lower level of maturity of the |
---|
1158 | people employed. |
---|
1159 | |
---|
1160 | The reviewers suggested that we use this estimation to compare two possible |
---|
1161 | scenarios: a) proceed as planned, porting all the CompCert proofs to Matita |
---|
1162 | or b) port D3.1 and D4.1 to Coq and re-use the CompCert proofs. |
---|
1163 | We remark here again that the back-end of the two compilers, from the |
---|
1164 | memory model on, are sensibly different: we are not re-proving correctness |
---|
1165 | of the same piece of code. Moreover, the proof techniques are different for |
---|
1166 | the front-end too. Switching to the CompCert formalization would imply |
---|
1167 | the abandon of the untrusted compiler, the abandon of the experiment with |
---|
1168 | a different proof technique, the abandon of the quest for an open source |
---|
1169 | proof, and the abandon of the co-development of the formalization and the |
---|
1170 | Matita proof assistant. In the Commitment Letter~\cite{letter} delivered |
---|
1171 | to the Officer in May we clarified our personal perspective on the project |
---|
1172 | goals and objectives. We do not re-describe here the point of view presented |
---|
1173 | in the letter that we can condense in ``we value diversity''. |
---|
1174 | |
---|
1175 | Clearly, if the execise would have suggested the infeasability in terms of |
---|
1176 | effort of concluding the formalization or getting close to that, we would have |
---|
1177 | abandoned our path and embraced the reviewer's suggestion. However, we |
---|
1178 | have been comforted in the analysis we did in autumn and further progress done |
---|
1179 | during the winter does not show yet any major delay with respect to the |
---|
1180 | proof schedule. We are thus planning to continue the certification according |
---|
1181 | to the more detailed proof plan that came out from the exercise reported in |
---|
1182 | this manuscript. |
---|
1183 | |
---|
1184 | \begin{thebibliography}{2} |
---|
1185 | \bibitem{compcert} X. Leroy, ``A Formally Verified Compiler back-end'', |
---|
1186 | Journal of Automated Reasoning 43(4)):363-446, 2009. |
---|
1187 | |
---|
1188 | \bibitem{letter}The CerCo team, ``Commitment to the Consideration of Reviewer's Reccomendation'', 16/05/2011. |
---|
1189 | \end{thebibliography} |
---|
1190 | |
---|
1191 | |
---|
1192 | \end{document} |
---|