source: Deliverables/D1.2/CompilerProofOutline/outline.tex @ 1785

Last change on this file since 1785 was 1785, checked in by tranquil, 8 years ago

finished ERTL to LTL sketch

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