Synchronous_reactive_systems/beamer/beamer.tex

219 lines
6.8 KiB
TeX
Raw Normal View History

2022-12-15 11:40:29 +01:00
\documentclass{beamer}
2022-12-16 15:45:40 +01:00
\usepackage{listings}
\lstset{
basicstyle=\ttfamily,
columns=fullflexible,
frame=single,
breaklines=true,
}
2022-12-15 11:40:29 +01:00
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetheme{Darmstadt}
\begin{document}
2022-12-16 05:06:27 +01:00
\title{Presentation of our Lustre-to-C compiler}
2022-12-16 16:03:47 +01:00
\subtitle{github.com/Benjamin-Loison/Synchronous-reactive-systems}
2022-12-16 05:06:27 +01:00
\date{16 December 2022}
\author{Benjamin Loison, Arnaud Daby-Seesaram, Antoine Grimod}
\frame{\titlepage}
2022-12-15 11:40:29 +01:00
\section{Structure of the compiler}
\begin{frame}{Main ideas}
\begin{figure}
\begin{tikzpicture}
\node (sf) {Source file};
\node[right =2cm of sf] (ast) {Typed AST};
\node[right =2cm of ast] (C) {C program};
\draw
(sf) edge[->] node[above] {parser} (ast)
(ast) edge[->] node[above] {compiler} (C);
\end{tikzpicture}
\caption{Structure of the compiler}
\end{figure}
\end{frame}
\begin{frame}{Testing}
\begin{block}{Passes}
The passes can be split into:
\begin{itemize}
\item those checking the program validity
\item those modifying the AST of the program
\end{itemize}
\end{block}
\end{frame}
\section{Typed AST}
\subsection{First attempt using GADTs}
\begin{frame}
\begin{block}{Main idea}
Using GADTs to represent nodes and expressions allows to ensure the
well-typedness of a program.
\end{block}
\begin{figure}
\centering
\includegraphics[width=.75\textwidth]{imgs/gadt.png}
\end{figure}
\end{frame}
\begin{frame}
\begin{block}{Pros of using GADTs}
\begin{itemize}
\item Any term of the GADT represents a well-typed program
\item Extending the language to support more types consists of adding
constructors to variables and constants
\item The types are easy to read and understand
\end{itemize}
\end {block}
\begin{block}{Cons of using GADTs}
\begin{itemize}
\item
They cannot be dynamically generated (hence it is impossible to
implement a parser that gives back a GADT)
\item
One should think about the isomorphism between
\texttt{a $\ast$ (b $\ast$ c)} and \texttt{(a $\ast$ b) $\ast$ c}.
\end{itemize}
\end{block}
\end{frame}
\subsection{Second attempt: using explicit types in the variables, expressions,
\dots{} constructors}
\begin{frame}
\begin{block}{Idea}
Explicitly collect typing information while parsing.
\end{block}
\begin{figure}
\centering
\includegraphics[width=.6\textwidth]{imgs/explicit_types.png}
\end{figure}
\end{frame}
\begin{frame}
\begin{block}{Pros of using explicit types}
\begin{itemize}
\item Programs can be built dynamically, hence a parser can be
written
\item While parsing, the parser has all the required information on
the sub-variables/nodes/expressions to check the well-typedness
\end{itemize}
\end{block}
\begin{block}{Cons of these definitions}
\begin{itemize}
\item The typing information on terms is very redundant.
\item The rejection of ill-typed programs depends on the correctness
of the parser
\end{itemize}
\end{block}
\end{frame}
\section{Passes}
\begin{frame}{Passes}
\begin{block}{Sanity checks}
2022-12-15 11:40:29 +01:00
\begin{itemize}
\item Check the well-typedness of a program
\item Check that there are no assignment conflicts in a programs
2022-12-15 11:40:29 +01:00
\end{itemize}
\end{block}
\begin{block}{AST modification}
2022-12-15 11:40:29 +01:00
\begin{itemize}
\item Rewrite automata into \texttt{if-then-else} constructs
\item Linearization of the equations
\item (no longer required) Push the \texttt{pre} to variables
2022-12-15 11:40:29 +01:00
\end{itemize}
\end{block}
\end{frame}
2022-12-16 15:45:40 +01:00
\begin{frame}[fragile]{Translation of automaton}
\only<1>{\lstinputlisting[language=ml, firstline=1, lastline=7]{code/example_automaton.lus}}
\only<2>{\lstinputlisting[language=ml, firstline=9, lastline=14]{code/example_automaton.lus}}
\end{frame}
\begin{frame}{Restriction on automaton}
The patterns that appears on the left of equations must be the
same in all branches
\only<2>{\lstinputlisting[language=ml, firstline=16, lastline=22]{code/example_automaton.lus}}
\end{frame}
\begin{frame}{Clock unification}
Derived from the rules provided in \emph{Clock-directed Modular Code Generation for Synchronous
Data-flow Languages}
\end{frame}
\section{Translation to C}
\begin{frame}
2022-12-16 15:33:39 +01:00
\texttt{ast\_to\_c.ml} architecture similar to Arnaud's AST pretty-printer.
2022-12-16 15:33:39 +01:00
\pause
For instance, go from \texttt{counting.lus} to \texttt{counting.c}.
\pause
Use of three tricks, as our compiler only manages \texttt{bool}s, \texttt{int}s and \texttt{float}s:
2022-12-16 15:07:46 +01:00
\begin{enumerate}
\item \texttt{0} can be interpreted as a \texttt{bool}, an \texttt{int} and a \texttt{float}
\pause
\item A \texttt{float} correctly encode \texttt{bool}s (\texttt{true} and \texttt{false}) and \texttt{int}s (between $[-2^{24} + 1; 2^{24} + 1]$)
\pause
\item To run an assignment of \texttt{value} to \texttt{variable} within the condition of a \texttt{if} and also make the cases of the \texttt{if} depends on a condition \texttt{condition}, we can do \texttt{if(((variable = value) \&\& false) || condition)}\\
\pause
We can also use this trick to execute an assignment and \textit{return} a value \texttt{value\_to\_return} without using any \texttt{;}, by using \texttt{((variable = value) || true) ? value\_to\_return : 0} (thanks to the first trick)
\end{enumerate}
\end{frame}
2022-12-16 16:02:03 +01:00
\begin{frame}
\begin{itemize}
\item
\begin{itemize}
\item \texttt{pp\_varlist (Base | Arg | Dec)}
\item \texttt{pp\_retvarlist}
\item \texttt{pp\_prevarlist}
\item \texttt{pp\_asnprevarlist}
\end{itemize}
\pause
\item \texttt{when} implementation error: division by zero for instance, so used the first trick (\texttt{when\_merge.node})
2022-12-16 16:02:03 +01:00
\pause
\item \texttt{->}: use global variable \texttt{init\_\{NODE\_NAME\}}\\
\texttt{1 -> 2 -> 3} returns \texttt{0} on first run and only \texttt{3} on the following ones, correct? (\texttt{arrow.node})
2022-12-16 16:02:03 +01:00
\pause
\item \texttt{pre}
\pause
\item \texttt{reset}% (\texttt{reset})
2022-12-16 16:02:03 +01:00
\pause
\item Functions returning tuples thanks to Arnaud's linearization only have to deal with \texttt{(a0, a1, ..., an) = return\_tuple\_a0\_a1\_dots\_an(0)} (\texttt{function\_returning\_tuple.node})
2022-12-16 16:02:03 +01:00
\end{itemize}
\end{frame}
\section{Tests}
\begin{frame}{Tests}
\begin{block}{testing methods}
We thought of three testing methods:
\begin{itemize}
\item manual testing of our functionalities
\item run the sanity-checks-passes after any AST-altering pass
\item simulation of the nodes (aborted)
\end{itemize}
\end{block}
\end{frame}
\section{Possible improvements}
\begin{frame}{Improvements}
\begin{itemize}
\item Increase the expressivity of the accepted programs
\item Improve the complexity of the different passes
\begin{itemize}
\item Group neighbour passes of the same type (node-, expression or
equation-pass).
\end{itemize}
\item \dots{}
\end{itemize}
2022-12-15 11:40:29 +01:00
\end{frame}
\end{document}