# Changeset 395 for Deliverables

Ignore:
Timestamp:
Dec 9, 2010, 3:33:55 PM (10 years ago)
Message:

Lots added from this afternoon to report. Implemented nearly all improvements CSC suggested.

File:
1 edited

### Legend:

Unmodified
 r394 \textbf{ Report n. D4.1\\ Verified Compiler---Back End} Executable Formal Semantics of Machine Code} \end{LARGE} \end{center} We discuss the implementation of a prototype O'Caml emulator for the Intel 8051/8052 eight bit processor, and its subsequent formalisation in the dependently typed proof assistant Matita. In particular, we focus on the decisions made during the design of both emulators, and how the design of the O'Caml emulator had to be modified in order to fit into the more stringent type system of Matita. Both emulators provide an executable formal semantics of machine code' for our target processor, per the description of the Deliverable in the \textsf{CerCo} Grant Agreement. \newpage \label{sect.task} The Grant Agreement states the D4.1/D4.2 deliverables consist of the following tasks: The Grant Agreement states that Task T4.1, entitled Executable Formal Semantics of Machine Code' has associated deliverable D4.1 consisting of the following: \begin{quotation} \textbf{Executable Formal Semantics of Machine Code}: Formal definition of the semantics of the target language. The semantics will be given in a functional (and hence executable) form, useful for testing, validation and project assessment. \end{quotation} \begin{quotation} \textbf{CIC encoding: Back-end}: Functional Specification in the internal language of the Proof Assistant (the Calculus of Inductive Construction) of the back end of the compiler. This unit is meant to be composable with the front-end of deliverable D3.2, to obtain a full working compiler for Milestone M2. A first validation of the design principles and implementation choices for the Untrusted Cost-annotating OCaml Compiler D2.2 is achieved and reported in the deliverable, possibly triggering updates of the Untrusted Cost-annotating OCaml Compiler sources. \end{quotation} We now report on our implementation of these deliverables. This report details our implementation of this deliverable. \subsection{Connection with other deliverables} \label{subsect.connection.other.deliverables} Deliverable D4.1 is an executable formal semantics of the machine code of our target processor (a brief overview of the processor architecture is provided in Section~\ref{sect.brief.overview.target.processor}). We provide an executable semantics in both O'Caml and the internal language of the Matita proof assistant. The C compiler delivered by Work Package 3 will eventually produce machine code executable by our emulator, and we expect that the emulator will be useful as a debugging aid for the compiler writers. Further, additional deliverables listed under Work Package 4 will later make use of the work reported in this document. In particular, Deliverables D4.2 and D4.3 entail the implementation of a formalised version of the intermediate language of the compiler, along with an executable formal semantics of these languages. We expect our emulator will be of great use in the implementation of both of these deliverables for debugging and testing purposes. \section{A brief overview of the target processor} The Matita emulator is executable from within Matita (naturally, the speed of execution is only a fraction of the speed of the O'Caml emulator). In particular, we provide a function \texttt{execute\_trace} which executes a fixed number of steps of an 8051 assembly program, returning a trace of the instructions executed, in the form of a list. This trace may then be compared with the trace produced by the O'Caml emulator when executing a program for validation purposes. \subsection{Future work} \newpage \section{Listing of O'Caml files} \label{sect.listing.ocaml.files} \begin{center} \begin{tabular*}{0.9\textwidth}{lp{10cm}} \section{Listing of O'Caml files and functions} \label{sect.listing.ocaml.files.functions} \subsection{Listing of O'Caml files} \label{subsect.listing.ocaml.files} \begin{center} \begin{tabular*}{0.9\textwidth}{p{3cm}p{9cm}} Title & Description \\ \hline \label{subsect.selected.important.functions} \subsubsection{From \texttt{ASMInterpret.mli}} \begin{center} \begin{tabular*}{0.9\textwidth}{lp{10cm}} \subsubsection{From \texttt{ASMInterpret.ml(i)}} \begin{center} \begin{tabular*}{0.85\textwidth}{p{3cm}@{\quad}p{9cm}} Name & Description \\ \hline \end{center} \subsubsection{From \texttt{IntelHex.ml(i)}} \begin{center} \begin{tabular*}{0.85\textwidth}{p{3cm}@{\quad}p{9cm}} Name & Description \\ \hline \texttt{intel\_hex\_of\_file} & Reads in a file and parses it if in Intel IHX format, otherwise raises an exception. \\ \texttt{process\_intel\_hex} & Accepts a parsed Intel IHX file and populates a hashmap (of the same type as code memory) with the contents. \end{tabular*} \end{center} \subsubsection{From \texttt{Physical.ml(i)}} \begin{center} \begin{tabular*}{0.85\textwidth}{p{3cm}@{\quad}p{9cm}} Name & Description \\ \hline \texttt{subb8\_with\_c} & Performs an eight bit subtraction on bitvectors.  The function also returns the most important PSW flags for the 8051: carry, auxiliary carry and overflow. \\ \texttt{add8\_with\_c} & Performs an eight bit addition on bitvectors.  The function also returns the most important PSW flags for the 8051: carry, auxiliary carry and overflow. \\ \texttt{dec} & Decrements an eight bit bitvector with underflow, if necessary. \\ \texttt{inc} & Increments an eight bit bitvector with overflow, if necessary. \end{tabular*} \end{center} \newpage \section{Listing of Matita files} \label{sect.listing.matita.files} \begin{center} \begin{tabular}{ll} Title & Description \\ \hline \end{tabular} \end{center} \section{Listing of Matita files and functions} \label{sect.listing.matita.files.functions} \subsection{Listing of Matita files} \label{subsect.listing.files} \begin{center} \begin{tabular*}{0.75\textwidth}{p{3cm}p{9cm}} Title & Description \\ \hline \texttt{Arithmetic.ma} & Contains functions implementing arithmetical operations on bitvectors. \\ \texttt{ASM.ma} & Contains inductive datatypes for representing abstract syntax trees of 8051 assembly language. \\ \texttt{Assembly.ma} & Contains functions related to the assembly of 8051 assembly programs into a list of bytes. \\ \texttt{BitVector.ma} & Contains functions specific to bitvectors. \\ \texttt{BitVectorTrie.ma} & Contains an implementation of a sparse bitvector trie, which we use for implementing memory in the processor. \\ \texttt{Bool.ma} & Implementation of Booleans, and related functions. \\ \texttt{Cartesian.ma} & Implementation of Cartesian products, and related functions. \\ \texttt{Char.ma} & Hypothesises a type of characters. \\ \texttt{Connectives.ma} & Implementation of logical connectives. \\ \texttt{DoTest.ma} & Contains experiments and debugging code for testing the emulator. \\ \texttt{Either.ma} & Implementation of disjoint union types. \\ \texttt{Exponential.ma} & Functions implementating the Natural exponential, and related lemmas. \\ \texttt{Fetch.ma} & Contains functions relating to the fetch' function of the emulator, and related functions. \\ \texttt{Interpret.ma} & Contains the main emulator function, as well as ancillary definitions and functions. \\ \texttt{List.ma} & An implementation of polymorphic lists, and related functions. \\ \texttt{Maybe.ma} & Implementation of the maybe' type. \\ \texttt{Nat.ma} & Implementation of Natural numbers, and related functions and lemmas. \\ \texttt{Status.ma} & Contains the definition of the `status' record, and related definitions. \\ \texttt{String.ma} & Contains a type for representing strings. \\ \texttt{Test.ma} & Contains definitions useful for debugging and testing the emulator. \\ \texttt{Universes.ma} & Infrastructure file related to Matita's universe hierarchy. \\ \texttt{Util.ma} & Contains miscellaneous utility functions that do not fit anywhere else. \\ \texttt{Vector.ma} & Contains an implementation of polymorphic vectors, and related definitions. \end{tabular*} \end{center} \subsection{Selected important functions} \label{subsect.matita.selected.important.functions} \subsubsection{From \texttt{Arithmetic.ma}} \begin{center} \begin{tabular*}{0.75\textwidth}{p{3cm}p{9cm}} Title & Description \\ \hline \texttt{add\_n\_with\_carry} & Performs an $n$ bit addition on bitvectors.  The function also returns the most important PSW flags for the 8051: carry, auxiliary carry and overflow. \\ \texttt{sub\_8\_with\_carry} & Performs an eight bit subtraction on bitvectors. The function also returns the most important PSW flags for the 8051: carry, auxiliary carry and overflow. \\ \texttt{half\_add} & Performs a standard half addition on bitvectors, returning the result and carry bit. \\ \texttt{full\_add} & Performs a standard full addition on bitvectors and a carry bit, returning the result and a carry bit. \end{tabular*} \end{center} \subsubsection{From \texttt{Assembly.ma}} \begin{center} \begin{tabular*}{0.75\textwidth}{p{3cm}p{9cm}} Title & Description \\ \hline \texttt{assemble1} & Assembles a single 8051 assembly instruction into its encoded counterpart. \\ \texttt{assemble} & Assembles a list of 8051 assembly instructions into their encoded counterpart. \end{tabular*} \end{center} \subsubsection{From \texttt{BitVectorTrie.ma}} \begin{center} \begin{tabular*}{0.75\textwidth}{p{3cm}p{9cm}} Title & Description \\ \hline \texttt{lookup} & Returns the data stored at the end of a particular path (a bitvector) from the trie.  If no data exists, returns a default value. \\ \texttt{insert} & Inserts data into a tree at the end of the path (a bitvector) indicated.  Automatically expands the tree (by filling in stubs) if necessary. \end{tabular*} \end{center} \subsubsection{From \texttt{DoTest.ma}} \begin{center} \begin{tabular*}{0.75\textwidth}{p{3cm}p{9cm}} Title & Description \\ \hline \texttt{execute\_trace} & Executes an assembly program for a fixed number of steps, recording in a trace which instructions were executed. \end{tabular*} \end{center} \subsubsection{From \texttt{Fetch.ma}} \begin{center} \begin{tabular*}{0.75\textwidth}{p{3cm}p{9cm}} Title & Description \\ \hline \texttt{fetch} & Decodes and returns the instruction currently pointed to by the program counter and automatically increments the program counter the required amount to point to the next instruction. \\ \end{tabular*} \end{center} \subsubsection{From \texttt{Interpret.ma}} \begin{center} \begin{tabular*}{0.75\textwidth}{p{3cm}p{9cm}} Title & Description \\ \hline \texttt{execute\_1} & Executes a single step of an 8051 assembly program. \\ \texttt{execute} & Executes a fixed number of steps of an 8051 assembly program. \end{tabular*} \end{center} \subsubsection{From \texttt{Status.ma}} \begin{center} \begin{tabular*}{0.75\textwidth}{p{3cm}p{9cm}} Title & Description \\ \hline \texttt{load} & Loads an assembled 8051 assembly program into code memory. \end{tabular*} \end{center} \end{document}