| author | Christian Urban <christian.urban@kcl.ac.uk> | 
| Mon, 10 Oct 2022 12:42:06 +0100 | |
| changeset 884 | fa8cc61dfcf0 | 
| parent 871 | 358a72d7bf71 | 
| child 898 | 5075b69142d9 | 
| permissions | -rw-r--r-- | 
| 686 | 1  | 
% !TEX program = xelatex  | 
| 744 | 2  | 
\documentclass[dvipsnames,14pt,t,xelatex,aspectratio=169,xcolor={table}]{beamer}
 | 
| 
302
 
0fa7b4221745
updated
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
215 
diff
changeset
 | 
3  | 
\usepackage{../slides}
 | 
| 
215
 
828303e8e4af
updated slides
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
188 
diff
changeset
 | 
4  | 
\usepackage{../langs}
 | 
| 
 
828303e8e4af
updated slides
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
188 
diff
changeset
 | 
5  | 
\usepackage{../data}
 | 
| 871 | 6  | 
\usepackage{../graphicss}
 | 
| 608 | 7  | 
\usepackage{../grammar}
 | 
| 
188
 
12ef150273ce
added
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
187 
diff
changeset
 | 
8  | 
|
| 63 | 9  | 
% beamer stuff  | 
| 451 | 10  | 
\renewcommand{\slidecaption}{CFL 07, King's College London}
 | 
| 63 | 11  | 
\newcommand{\bl}[1]{\textcolor{blue}{#1}}       
 | 
12  | 
||
13  | 
\begin{document}
 | 
|
14  | 
||
15  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
| 
302
 
0fa7b4221745
updated
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
215 
diff
changeset
 | 
16  | 
\begin{frame}[t]
 | 
| 63 | 17  | 
\frametitle{%
 | 
18  | 
  \begin{tabular}{@ {}c@ {}}
 | 
|
19  | 
\\[-3mm]  | 
|
| 451 | 20  | 
\LARGE Compilers and \\[-2mm]  | 
| 744 | 21  | 
\LARGE Formal Languages\\[3mm]  | 
| 63 | 22  | 
  \end{tabular}}
 | 
23  | 
||
24  | 
\normalsize  | 
|
25  | 
  \begin{center}
 | 
|
26  | 
  \begin{tabular}{ll}
 | 
|
| 686 | 27  | 
Email: & christian.urban at kcl.ac.uk\\  | 
| 744 | 28  | 
%Office Hours: & Thursdays 12 -- 14\\  | 
29  | 
%Location: & N7.07 (North Wing, Bush House)\\  | 
|
| 686 | 30  | 
Slides \& Progs: & KEATS (also homework is there)\\  | 
| 63 | 31  | 
  \end{tabular}
 | 
32  | 
  \end{center}
 | 
|
33  | 
||
| 744 | 34  | 
  \begin{center}
 | 
35  | 
    \begin{tikzpicture}
 | 
|
36  | 
\node[drop shadow,fill=white,inner sep=0pt]  | 
|
37  | 
      {\footnotesize\rowcolors{1}{capri!10}{white}
 | 
|
38  | 
        \begin{tabular}{|p{4.8cm}|p{4.8cm}|}\hline
 | 
|
39  | 
1 Introduction, Languages & 6 While-Language \\  | 
|
| 852 | 40  | 
2 Regular Expressions, Derivatives & 7 Compilation, JVM \\  | 
41  | 
          3 Automata, Regular Languages      & \cellcolor{blue!50} 8 Compiling Functional Languages \\
 | 
|
42  | 
4 Lexing, Tokenising & 9 Optimisations \\  | 
|
43  | 
5 Grammars, Parsing & 10 LLVM \\ \hline  | 
|
44  | 
        \end{tabular}%
 | 
|
45  | 
};  | 
|
46  | 
    \end{tikzpicture}
 | 
|
47  | 
  \end{center}
 | 
|
48  | 
\end{frame}
 | 
|
49  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
50  | 
||
51  | 
||
52  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
53  | 
\begin{frame}[t]
 | 
|
54  | 
\frametitle{%
 | 
|
55  | 
  \begin{tabular}{@ {}c@ {}}
 | 
|
56  | 
\\[-3mm]  | 
|
57  | 
\LARGE Compilers and \\[-2mm]  | 
|
58  | 
\LARGE Formal Languages\\[3mm]  | 
|
59  | 
  \end{tabular}}
 | 
|
60  | 
||
61  | 
\normalsize  | 
|
62  | 
  \begin{center}
 | 
|
63  | 
  \begin{tabular}{ll}
 | 
|
64  | 
Email: & christian.urban at kcl.ac.uk\\  | 
|
65  | 
%Office Hours: & Thursdays 12 -- 14\\  | 
|
66  | 
%Location: & N7.07 (North Wing, Bush House)\\  | 
|
67  | 
Slides \& Progs: & KEATS (also homework is there)\\  | 
|
68  | 
  \end{tabular}
 | 
|
69  | 
  \end{center}
 | 
|
70  | 
||
71  | 
  \begin{center}
 | 
|
72  | 
    \begin{tikzpicture}
 | 
|
73  | 
\node[drop shadow,fill=white,inner sep=0pt]  | 
|
74  | 
      {\footnotesize\rowcolors{1}{capri!10}{white}
 | 
|
75  | 
        \begin{tabular}{|p{4.8cm}|p{4.8cm}|}\hline
 | 
|
76  | 
1 Introduction, Languages & 6 While-Language \\  | 
|
| 744 | 77  | 
          2 Regular Expressions, Derivatives & \cellcolor{blue!50} 7 Compilation, JVM \\
 | 
78  | 
3 Automata, Regular Languages & 8 Compiling Functional Languages \\  | 
|
79  | 
4 Lexing, Tokenising & 9 Optimisations \\  | 
|
80  | 
5 Grammars, Parsing & 10 LLVM \\ \hline  | 
|
81  | 
        \end{tabular}%
 | 
|
82  | 
};  | 
|
83  | 
    \end{tikzpicture}
 | 
|
84  | 
  \end{center}
 | 
|
85  | 
||
| 
302
 
0fa7b4221745
updated
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
215 
diff
changeset
 | 
86  | 
\end{frame}
 | 
| 
 
0fa7b4221745
updated
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
215 
diff
changeset
 | 
87  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
| 63 | 88  | 
|
| 608 | 89  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
| 807 | 90  | 
\begin{frame}[t]
 | 
| 608 | 91  | 
\frametitle{Bird's Eye View}
 | 
| 807 | 92  | 
\mbox{}\\[-16mm]\mbox{}
 | 
| 
387
 
8aa406adfde0
updated
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
374 
diff
changeset
 | 
93  | 
|
| 608 | 94  | 
\begin{center}
 | 
| 807 | 95  | 
  \begin{tikzpicture}[scale=1,
 | 
96  | 
                      node/.style={
 | 
|
97  | 
rectangle,rounded corners=3mm,  | 
|
98  | 
very thick,draw=black!50,  | 
|
99  | 
minimum height=18mm, minimum width=20mm,  | 
|
100  | 
top color=white,bottom color=black!20,drop shadow}]  | 
|
101  | 
  \node (0) at (-2.3,0) {}; 
 | 
|
102  | 
||
103  | 
  \node (A) at (0,0)  [node] {};
 | 
|
104  | 
  \node [below right] at (A.north west) {lexer};
 | 
|
105  | 
||
106  | 
  \node (B) at (3,0)  [node] {};
 | 
|
107  | 
\node [below right=1mm] at (B.north west)  | 
|
108  | 
    {\mbox{}\hspace{-1mm}parser};
 | 
|
| 608 | 109  | 
|
| 807 | 110  | 
  \node (C) at (6,0)  [node] {};
 | 
111  | 
\node [below right] at (C.north west)  | 
|
112  | 
    {\mbox{}\hspace{-1mm}code gen};
 | 
|
113  | 
||
114  | 
  \node (1) at (8.4,0) {}; 
 | 
|
115  | 
||
116  | 
\draw [->,line width=4mm] (0) -- (A);  | 
|
117  | 
\draw [->,line width=4mm] (A) -- (B);  | 
|
118  | 
\draw [->,line width=4mm] (B) -- (C);  | 
|
119  | 
\draw [->,line width=4mm] (C) -- (1);  | 
|
120  | 
  \end{tikzpicture}
 | 
|
| 808 | 121  | 
  \end{center}\pause
 | 
122  | 
||
123  | 
  \begin{center}
 | 
|
124  | 
\begin{tikzpicture}[scale=1,font=\bf,
 | 
|
125  | 
                      node/.style={
 | 
|
126  | 
rectangle,rounded corners=3mm,  | 
|
127  | 
ultra thick,draw=black!50,minimum height=18mm,  | 
|
128  | 
minimum width=20mm,  | 
|
129  | 
top color=white,bottom color=black!20}]  | 
|
130  | 
||
131  | 
  \node (0) at (-3,0) {};  
 | 
|
132  | 
  \node (A) at (0,0) [node,text width=1.6cm,text centered] {\small{}our compiler};
 | 
|
133  | 
  \node (B) at (3.5,0) [node,text width=1.6cm,text centered] {\small{}Jasmin / Krakatau};
 | 
|
134  | 
  \node (C) at (7.5,0) [node] {JVM};
 | 
|
135  | 
||
136  | 
  \draw [->,line width=2.5mm] (0) -- node [above,pos=0.35] {*.while} (A); 
 | 
|
137  | 
  \draw [->,line width=2.5mm] (A) -- node [above,pos=0.35] {*.j} (B); 
 | 
|
138  | 
  \draw [->,line width=2.5mm] (B) -- node [above,pos=0.35] {*.class} (C); 
 | 
|
139  | 
  \end{tikzpicture}
 | 
|
| 807 | 140  | 
  \end{center}
 | 
| 608 | 141  | 
\end{frame}
 | 
| 63 | 142  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
| 686 | 143  | 
|
| 808 | 144  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
145  | 
\begin{frame}[c]
 | 
|
146  | 
\frametitle{Test Program}
 | 
|
147  | 
||
148  | 
\mbox{}\\[-18mm]\mbox{}
 | 
|
149  | 
||
150  | 
{\lstset{language=While}\fontsize{10}{12}\selectfont
 | 
|
151  | 
\texttt{\lstinputlisting{../progs/while-tests/loops.while}}}
 | 
|
152  | 
||
153  | 
\end{frame}
 | 
|
154  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
| 686 | 155  | 
|
156  | 
||
157  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
158  | 
\begin{frame}[c]
 | 
|
| 608 | 159  | 
\begin{textblock}{10}(0.5,0.5)
 | 
160  | 
\LARGE  | 
|
161  | 
  \fontspec{Hoefler Text Black}
 | 
|
162  | 
  \textcolor{ProcessBlue}{JVM\\ Code}
 | 
|
163  | 
\\[12mm]  | 
|
164  | 
||
165  | 
\normalsize  | 
|
166  | 
Jasmin\\  | 
|
167  | 
Krakatau\\  | 
|
168  | 
ASM lib  | 
|
169  | 
\end{textblock}
 | 
|
170  | 
||
| 
387
 
8aa406adfde0
updated
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
374 
diff
changeset
 | 
171  | 
|
| 608 | 172  | 
\fontsize{8}{10}\selectfont
 | 
173  | 
%\footnotesize  | 
|
| 807 | 174  | 
\mbox{}\\[-13mm]\mbox{}
 | 
| 608 | 175  | 
|
176  | 
\begin{columns}
 | 
|
177  | 
\begin{column}{2cm} 
 | 
|
178  | 
\lstinputlisting[numbers=none]{../progs/appHa.j}
 | 
|
179  | 
\end{column}
 | 
|
180  | 
||
181  | 
\begin{column}{2cm} 
 | 
|
182  | 
\lstinputlisting[numbers=none]{../progs/appHb.j}
 | 
|
183  | 
\end{column}
 | 
|
184  | 
||
185  | 
\end{columns}
 | 
|
| 63 | 186  | 
|
| 608 | 187  | 
\end{frame}
 | 
188  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
189  | 
||
190  | 
||
| 808 | 191  | 
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
192  | 
% \begin{frame}[t]
 | 
|
| 608 | 193  | 
|
| 808 | 194  | 
% \begin{center}
 | 
195  | 
% \bl{\begin{tabular}{@{}lcl@{}}
 | 
|
196  | 
% \\[-12mm]  | 
|
197  | 
% \meta{Stmt} & $::=$ &  $\texttt{skip}$\\
 | 
|
198  | 
%               & $|$ & \textit{Id}\;\texttt{:=}\;\meta{AExp}\\
 | 
|
199  | 
%               & $|$ & \texttt{if}\; \meta{BExp} \;\texttt{then}\; \meta{Block} \;\texttt{else}\; \meta{Block}\\
 | 
|
200  | 
%               & $|$ & \texttt{while}\; \meta{BExp} \;\texttt{do}\; \meta{Block}\\
 | 
|
201  | 
%               & $|$ & \texttt{read}\;\textit{Id}\\
 | 
|
202  | 
%               & $|$ & \texttt{write}\;\textit{Id}\\
 | 
|
203  | 
%               & $|$ & \texttt{write}\;\textit{String}\medskip\\
 | 
|
204  | 
% \meta{Stmts} & $::=$ &  \meta{Stmt} \;\texttt{;}\; \meta{Stmts}\\
 | 
|
205  | 
%               & $|$ & \meta{Stmt}\medskip\\
 | 
|
206  | 
% \meta{Block} & $::=$ &  \texttt{\{}\,\meta{Stmts}\,\texttt{\}}\\
 | 
|
207  | 
%                 & $|$ & \meta{Stmt}\medskip\\
 | 
|
208  | 
% \meta{AExp} & $::=$ & \ldots\\
 | 
|
209  | 
% \meta{BExp} & $::=$ & \ldots\\
 | 
|
210  | 
% \end{tabular}}
 | 
|
211  | 
% \end{center}
 | 
|
212  | 
% \end{frame}
 | 
|
213  | 
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
| 
184
 
2e9134d25a2b
added slides
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
173 
diff
changeset
 | 
214  | 
|
| 608 | 215  | 
|
| 808 | 216  | 
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
217  | 
% \begin{frame}[c]
 | 
|
218  | 
% \frametitle{\begin{tabular}{c}Fibonacci Numbers\end{tabular}}
 | 
|
| 
387
 
8aa406adfde0
updated
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
374 
diff
changeset
 | 
219  | 
|
| 808 | 220  | 
% \mbox{}\\[-18mm]\mbox{}
 | 
221  | 
% ??  | 
|
222  | 
% %{\lstset{language=While}\fontsize{10}{12}\selectfont
 | 
|
223  | 
% %\texttt{\lstinputlisting{../progs/fib.while}}}
 | 
|
| 
387
 
8aa406adfde0
updated
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
374 
diff
changeset
 | 
224  | 
|
| 808 | 225  | 
% \end{frame}
 | 
226  | 
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
| 
387
 
8aa406adfde0
updated
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
374 
diff
changeset
 | 
227  | 
|
| 808 | 228  | 
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
229  | 
% \begin{frame}[c]
 | 
|
230  | 
% \frametitle{Interpreter}
 | 
|
| 
188
 
12ef150273ce
added
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
187 
diff
changeset
 | 
231  | 
|
| 808 | 232  | 
% \begin{center}
 | 
233  | 
% \bl{\begin{tabular}{@{}lcl@{}}
 | 
|
234  | 
% $\text{eval}(n, E)$ & $\dn$ & $n$\\
 | 
|
235  | 
% $\text{eval}(x, E)$ & $\dn$ & $E(x)$ \;\;\;\textcolor{black}{lookup \bl{$x$} in \bl{$E$}}\\
 | 
|
236  | 
% $\text{eval}(a_1 + a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) + \text{eval}(a_2, E)$\\
 | 
|
237  | 
% $\text{eval}(a_1 - a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) - \text{eval}(a_2, E)$\\
 | 
|
238  | 
% $\text{eval}(a_1 * a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) * \text{eval}(a_2, E)$\bigskip\\
 | 
|
239  | 
% $\text{eval}(a_1 = a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) = \text{eval}(a_2, E)$\\
 | 
|
240  | 
% $\text{eval}(a_1\,!\!= a_2, E)$ & $\dn$ & $\neg(\text{eval}(a_1, E) = \text{eval}(a_2, E))$\\
 | 
|
241  | 
% $\text{eval}(a_1 < a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) < \text{eval}(a_2, E)$\
 | 
|
242  | 
% \end{tabular}}
 | 
|
243  | 
% \end{center}
 | 
|
| 63 | 244  | 
|
| 808 | 245  | 
% \end{frame}
 | 
246  | 
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
| 608 | 247  | 
|
| 808 | 248  | 
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
249  | 
% \begin{frame}[c]
 | 
|
250  | 
% \frametitle{Interpreter (2)}
 | 
|
| 63 | 251  | 
|
| 808 | 252  | 
% \begin{center}
 | 
253  | 
% \bl{\begin{tabular}{@{}lcl@{}}
 | 
|
254  | 
% $\text{eval}(\text{skip}, E)$ & $\dn$ & $E$\\
 | 
|
255  | 
% $\text{eval}(x:=a, E)$ & $\dn$ & \bl{$E(x \mapsto \text{eval}(a, E))$}\\
 | 
|
256  | 
% \multicolumn{3}{@{}l@{}}{$\text{eval}(\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2 , E) \dn$}\\
 | 
|
257  | 
% \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)\;\text{then}\;
 | 
|
258  | 
% \text{eval}(cs_1,E)$}\\
 | 
|
259  | 
% \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\phantom{\text{if}\;\text{eval}(b,E)\;}\text{else}\;\text{eval}(cs_2,E)$}\\
 | 
|
260  | 
% \multicolumn{3}{@{}l@{}}{$\text{eval}(\text{while}\;b\;\text{do}\;cs, E) \dn$}\\
 | 
|
261  | 
% \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)$}\\
 | 
|
262  | 
% \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\;
 | 
|
263  | 
% \text{eval}(\text{while}\;b\;\text{do}\;cs, \text{eval}(cs,E))$}\\
 | 
|
264  | 
% \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\
 | 
|
265  | 
% $\text{eval}(\text{write}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\
 | 
|
266  | 
% \end{tabular}}
 | 
|
267  | 
% \end{center}
 | 
|
| 63 | 268  | 
|
| 808 | 269  | 
% \end{frame}
 | 
270  | 
% %%%%%%%%%%%%%%%  | 
|
271  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
| 
188
 
12ef150273ce
added
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
187 
diff
changeset
 | 
272  | 
|
| 808 | 273  | 
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
274  | 
% \begin{frame}[c]
 | 
|
275  | 
% \frametitle{Test Program}
 | 
|
| 
188
 
12ef150273ce
added
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
187 
diff
changeset
 | 
276  | 
|
| 808 | 277  | 
% \mbox{}\\[-18mm]\mbox{}
 | 
| 
188
 
12ef150273ce
added
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
187 
diff
changeset
 | 
278  | 
|
| 808 | 279  | 
% {\lstset{language=While}\fontsize{10}{12}\selectfont
 | 
280  | 
% \texttt{\lstinputlisting{../progs/while-tests/loops.while}}}
 | 
|
| 63 | 281  | 
|
| 808 | 282  | 
% \end{frame}
 | 
283  | 
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
| 63 | 284  | 
|
| 808 | 285  | 
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
286  | 
% \begin{frame}[c]
 | 
|
287  | 
% \fontsize{7}{9}\selectfont
 | 
|
| 608 | 288  | 
|
289  | 
||
| 808 | 290  | 
% \begin{columns}
 | 
291  | 
% \begin{column}{7cm} 
 | 
|
292  | 
% \lstinputlisting[numbers=none]{../progs/appHa.j}
 | 
|
293  | 
% \end{column}
 | 
|
| 608 | 294  | 
|
| 808 | 295  | 
% \begin{column}{7cm} 
 | 
296  | 
% \lstinputlisting[numbers=none]{../progs/appHb.j}
 | 
|
297  | 
% \end{column}
 | 
|
298  | 
% \end{columns}
 | 
|
| 608 | 299  | 
|
| 808 | 300  | 
% \end{frame}
 | 
301  | 
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
| 608 | 302  | 
|
| 686 | 303  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
304  | 
%\begin{frame}[t]
 | 
|
305  | 
%\frametitle{Interpreted Code}
 | 
|
306  | 
%  | 
|
307  | 
%\begin{center}
 | 
|
308  | 
%\begin{tikzpicture}
 | 
|
309  | 
%\begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small]
 | 
|
310  | 
%\addplot+[smooth] file {interpreted.data};
 | 
|
311  | 
%\end{axis}
 | 
|
312  | 
%\end{tikzpicture}
 | 
|
313  | 
%\end{center}
 | 
|
314  | 
%  | 
|
315  | 
%\end{frame}
 | 
|
316  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
317  | 
%  | 
|
318  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
319  | 
%\begin{frame}[c]
 | 
|
320  | 
%\frametitle{Java Virtual Machine}
 | 
|
321  | 
%  | 
|
322  | 
%\begin{itemize}
 | 
|
323  | 
%\item introduced in 1995  | 
|
324  | 
%\item is a stack-based VM (like Postscript, CLR of .Net)  | 
|
325  | 
%\item contains a JIT compiler  | 
|
326  | 
%\item many languages take advantage of JVM's infrastructure (JRE)  | 
|
327  | 
%\item is garbage collected $\Rightarrow$ no buffer overflows  | 
|
328  | 
%\item some languages compiled to the JVM: Scala, Clojure\ldots  | 
|
329  | 
%\end{itemize}
 | 
|
330  | 
%  | 
|
331  | 
%\end{frame}
 | 
|
| 608 | 332  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
333  | 
||
334  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
335  | 
\begin{frame}[t,fragile]
 | 
|
336  | 
\frametitle{Compiling AExps}
 | 
|
337  | 
||
| 686 | 338  | 
For example \textbf{\bl{1 + ((2 * 3) + (4 - 3))}}:\medskip
 | 
| 608 | 339  | 
|
340  | 
\begin{columns}[T]
 | 
|
341  | 
\begin{column}{.3\textwidth}
 | 
|
342  | 
\begin{center}
 | 
|
343  | 
\bl{\begin{tikzpicture}
 | 
|
344  | 
\tikzset{level distance=12mm,sibling distance=4mm}
 | 
|
345  | 
\tikzset{edge from parent/.style={draw,very thick}}
 | 
|
346  | 
\Tree [.$+$ [.$1$ ] [.$+$ [.$*$ $2$ $3$ ] [.$-$ $4$ $3$ ]]]  | 
|
347  | 
\end{tikzpicture}}
 | 
|
348  | 
\end{center}
 | 
|
349  | 
\end{column}
 | 
|
350  | 
\begin{column}{.3\textwidth}  
 | 
|
351  | 
\begin{lstlisting}[language=JVMIS,numbers=none]
 | 
|
352  | 
ldc 1  | 
|
353  | 
ldc 2  | 
|
354  | 
ldc 3  | 
|
355  | 
imul  | 
|
356  | 
ldc 4  | 
|
357  | 
ldc 3  | 
|
358  | 
isub  | 
|
359  | 
iadd  | 
|
360  | 
iadd  | 
|
361  | 
\end{lstlisting}
 | 
|
362  | 
\end{column}
 | 
|
363  | 
\end{columns}\bigskip
 | 
|
364  | 
||
365  | 
\small  | 
|
366  | 
Traverse tree in post-order \bl{$\Rightarrow$} code for 
 | 
|
367  | 
stack-machine  | 
|
368  | 
||
369  | 
\end{frame}
 | 
|
370  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
371  | 
||
372  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
373  | 
\begin{frame}[t,fragile]
 | 
|
374  | 
\frametitle{Compiling AExps}
 | 
|
375  | 
||
| 686 | 376  | 
\liningnums{\textbf{\Large\bl{(1 + 2) + 3}}}
 | 
| 608 | 377  | 
|
378  | 
\begin{lstlisting}[language=JVMIS,numbers=none,xleftmargin=6cm]  
 | 
|
379  | 
ldc 1  | 
|
380  | 
ldc 2  | 
|
381  | 
iadd  | 
|
382  | 
ldc 3  | 
|
383  | 
iadd  | 
|
384  | 
\end{lstlisting}
 | 
|
385  | 
||
386  | 
||
387  | 
\end{frame}
 | 
|
388  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
389  | 
||
390  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
391  | 
\begin{frame}[t,fragile]
 | 
|
392  | 
\frametitle{Compiling AExps}
 | 
|
393  | 
||
394  | 
\liningnums{\textbf{\Large\bl{1 + (2 + 3)}}}
 | 
|
395  | 
||
396  | 
\begin{lstlisting}[language=JVMIS,numbers=none,xleftmargin=6cm]  
 | 
|
397  | 
ldc 1  | 
|
398  | 
ldc 2  | 
|
399  | 
ldc 3  | 
|
400  | 
iadd  | 
|
401  | 
iadd  | 
|
402  | 
\end{lstlisting}
 | 
|
403  | 
\bigskip\pause  | 
|
404  | 
\vfill  | 
|
405  | 
||
406  | 
\textcolor{codepurple}{\textbf{\texttt{dadd}}},
 | 
|
407  | 
\textcolor{codepurple}{\textbf{\texttt{fadd}}},
 | 
|
408  | 
\textcolor{codepurple}{\textbf{\texttt{ladd}}}, \ldots
 | 
|
409  | 
||
410  | 
\end{frame}
 | 
|
411  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
412  | 
||
413  | 
||
414  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
415  | 
\begin{frame}[t]
 | 
|
416  | 
\frametitle{Compiling AExps}
 | 
|
417  | 
||
418  | 
\begin{center}
 | 
|
419  | 
\bl{\begin{tabular}{@{}lcl@{}}
 | 
|
420  | 
$\text{compile}(n)$ & $\dn$ & $\text{ldc}\;n$\\
 | 
|
421  | 
$\text{compile}(a_1 + a_2)$ & $\dn$\\ 
 | 
|
422  | 
\multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\;\text{compile}(a_2)\;@\; \text{iadd}$}\smallskip\\
 | 
|
423  | 
$\text{compile}(a_1 - a_2)$ & $\dn$\\ 
 | 
|
424  | 
\multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\; \text{compile}(a_2)\;@\; \text{isub}$}\smallskip\\
 | 
|
425  | 
$\text{compile}(a_1 * a_2)$ & $\dn$\\ 
 | 
|
426  | 
\multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\; \text{compile}(a_2)\;@\; \text{imul}$}\smallskip\\
 | 
|
427  | 
\end{tabular}}
 | 
|
428  | 
\end{center}
 | 
|
429  | 
||
430  | 
\end{frame}
 | 
|
431  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
432  | 
||
433  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
434  | 
\begin{frame}[t,fragile]
 | 
|
435  | 
\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
 | 
|
436  | 
||
437  | 
\liningnums{\textbf{\Large\bl{1 $+$ 2 $*$ 3 $+$ (4 $-$ 3)}}}
 | 
|
438  | 
||
439  | 
\begin{lstlisting}[language=JVMIS,numbers=none,xleftmargin=6cm]         
 | 
|
440  | 
ldc 1  | 
|
441  | 
ldc 2  | 
|
442  | 
ldc 3  | 
|
443  | 
imul  | 
|
444  | 
ldc 4  | 
|
445  | 
ldc 3  | 
|
446  | 
isub  | 
|
447  | 
iadd  | 
|
448  | 
iadd  | 
|
449  | 
\end{lstlisting}
 | 
|
450  | 
||
451  | 
\end{frame}
 | 
|
452  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
453  | 
||
454  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
455  | 
\begin{frame}[c]
 | 
|
456  | 
\frametitle{Variables}
 | 
|
457  | 
\liningnums{\textbf{\Large\bl{x $:=$ 5 $+$ y $*$ 2}}}\bigskip\pause   
 | 
|
458  | 
||
459  | 
\begin{itemize}
 | 
|
460  | 
\item lookup: \bl{$\textcolor{codepurple}{\textbf{\texttt{iload}}}\; index$}
 | 
|
461  | 
\item store: \bl{$\textcolor{codepurple}{\textbf{\texttt{istore}}}\; index$}
 | 
|
462  | 
\end{itemize}\bigskip\pause
 | 
|
463  | 
||
464  | 
while compilating we have to maintain a map between our identifiers and the  | 
|
465  | 
Java bytecode indices  | 
|
466  | 
||
467  | 
\begin{center}
 | 
|
468  | 
\bl{$\text{compile}(a, E)$}
 | 
|
469  | 
\end{center}
 | 
|
470  | 
||
471  | 
\end{frame}
 | 
|
472  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
473  | 
||
474  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
475  | 
\begin{frame}[t]
 | 
|
476  | 
\frametitle{Compiling AExps}
 | 
|
477  | 
||
478  | 
\begin{center}
 | 
|
479  | 
\bl{\begin{tabular}{@{}lcl@{}}
 | 
|
480  | 
$\text{compile}(n, E)$ & $\dn$ & $\text{ldc}\;n$\\
 | 
|
481  | 
$\text{compile}(a_1 + a_2, E)$ & $\dn$\\ 
 | 
|
482  | 
\multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\;\text{compile}(a_2, E)\;@\; \text{iadd}$}\smallskip\\
 | 
|
483  | 
$\text{compile}(a_1 - a_2, E)$ & $\dn$\\ 
 | 
|
484  | 
\multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{isub}$}\smallskip\\
 | 
|
485  | 
$\text{compile}(a_1 * a_2, E)$ & $\dn$\\ 
 | 
|
486  | 
\multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{imul}$}\bigskip\\
 | 
|
487  | 
$\text{compile}(x, E)$ & $\dn$ & $\text{iload}\;E(x)$\\
 | 
|
488  | 
\end{tabular}}
 | 
|
489  | 
\end{center}
 | 
|
490  | 
||
491  | 
\end{frame}
 | 
|
492  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
493  | 
||
494  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
495  | 
\begin{frame}[c, fragile]
 | 
|
496  | 
\frametitle{Mathematical Functions}
 | 
|
497  | 
||
498  | 
Compilation of some mathematical functions:  | 
|
499  | 
||
500  | 
\begin{center}
 | 
|
501  | 
\begin{tabular}{lcl}
 | 
|
502  | 
\texttt{Aop("+", a1, a2)} & $\Rightarrow$ & \texttt{...iadd}\\
 | 
|
503  | 
\texttt{Aop("-", a1, a2)} & $\Rightarrow$ & \texttt{...isub}\\
 | 
|
504  | 
\texttt{Aop("*", a1, a2)} & $\Rightarrow$ & \texttt{...imul}\\
 | 
|
505  | 
\texttt{Aop("/", a1, a2)} & $\Rightarrow$ & \texttt{...idiv}\\
 | 
|
506  | 
\texttt{Aop("\%", a1, a2)} & $\Rightarrow$ & \texttt{...irem}\\
 | 
|
507  | 
\end{tabular}
 | 
|
508  | 
\end{center}
 | 
|
509  | 
||
510  | 
\end{frame}
 | 
|
511  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
512  | 
||
513  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
514  | 
\begin{frame}[c]
 | 
|
515  | 
\frametitle{Compiling Statements}
 | 
|
516  | 
||
517  | 
We return a list of instructions and an environment for the  | 
|
518  | 
variables  | 
|
519  | 
||
520  | 
\begin{center}
 | 
|
521  | 
\bl{\begin{tabular}{@{}l@{\hspace{1mm}}c@{\hspace{1mm}}l@{}}
 | 
|
522  | 
$\text{compile}(\text{skip}, E)$ & $\dn$ & $(\textit{Nil}, E)$\bigskip\\
 | 
|
523  | 
$\text{compile}(x := a, E)$ & $\dn$\\
 | 
|
524  | 
\multicolumn{3}{l}{$(\text{compile}(a, E) \;@\;\text{istore}\;index, E(x\mapsto index))$}\\
 | 
|
525  | 
\end{tabular}}
 | 
|
526  | 
\end{center}\medskip
 | 
|
527  | 
||
528  | 
where \bl{$index$} is \bl{$E(x)$} if it is already defined, 
 | 
|
529  | 
or if it is not, then the largest index not yet seen  | 
|
530  | 
||
531  | 
\end{frame}
 | 
|
532  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
533  | 
||
534  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
535  | 
\begin{frame}[c,fragile]
 | 
|
536  | 
\frametitle{Compiling Assignments}
 | 
|
537  | 
||
538  | 
\liningnums{\textbf{\Large\bl{x $:=$ x $+$ 1}}}
 | 
|
539  | 
||
540  | 
\begin{lstlisting}[language=JVMIS,numbers=none,xleftmargin=6cm]        
 | 
|
541  | 
iload /*@\bl{$n_x$}@*/
 | 
|
542  | 
ldc 1  | 
|
543  | 
iadd  | 
|
544  | 
istore /*@\bl{$n_x$}@*/
 | 
|
545  | 
\end{lstlisting}\medskip
 | 
|
546  | 
||
547  | 
where \bl{$n_x$} is the index corresponding to the variable~\bl{$x$}
 | 
|
548  | 
||
549  | 
\end{frame}
 | 
|
550  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
551  | 
||
552  | 
||
553  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
554  | 
\begin{frame}[t]
 | 
|
555  | 
\frametitle{Compiling Ifs}
 | 
|
556  | 
||
557  | 
{\Large\bl{$\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2$}}\bigskip\bigskip
 | 
|
558  | 
||
559  | 
\onslide<2->{Case }\only<2>{{\bf True}:}\only<3>{{\bf False}:}
 | 
|
560  | 
||
561  | 
\begin{center}
 | 
|
562  | 
\begin{tikzpicture}[node distance=2mm and 4mm,
 | 
|
563  | 
 block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm},
 | 
|
564  | 
 point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red},
 | 
|
565  | 
 skip loop/.style={red, line width=1mm, to path={-- ++(0,-10mm) -| (\tikztotarget)}}]
 | 
|
566  | 
\node (A1) [point] {};
 | 
|
567  | 
\node (b) [block, right=of A1] {code of \bl{$b$}};
 | 
|
568  | 
\node (A2) [point, right=of b] {};
 | 
|
569  | 
\node (cs1) [block, right=of A2] {code of \bl{$cs_1$}};
 | 
|
570  | 
\node (A3) [point, right=of cs1] {};
 | 
|
571  | 
\node (cs2) [block, right=of A3] {code of \bl{$cs_2$}};
 | 
|
572  | 
\node (A4) [point, right=of cs2] {};
 | 
|
573  | 
||
574  | 
\only<2>{
 | 
|
575  | 
\draw (A1) edge [->, red, line width=1mm] (b);  | 
|
576  | 
\draw (b) edge [->, red, line width=1mm] (cs1);  | 
|
577  | 
\draw (cs1) edge [->, red, line width=1mm] (A3);  | 
|
578  | 
\draw (A3) edge [->,skip loop] (A4);  | 
|
579  | 
\node [below=of cs2] {\raisebox{-5mm}{\small{}jump}};}
 | 
|
580  | 
\only<3>{
 | 
|
581  | 
\draw (A1) edge [->, red, line width=1mm] (b);  | 
|
582  | 
\draw (b) edge [->, red, line width=1mm] (A2);  | 
|
583  | 
\draw (A2) edge [skip loop] (A3);  | 
|
584  | 
\draw (A3) edge [->, red, line width=1mm] (cs2);  | 
|
585  | 
\draw (cs2) edge [->,red, line width=1mm] (A4);  | 
|
586  | 
\node [below=of cs1] {\raisebox{-5mm}{\small{}conditional jump}};}
 | 
|
587  | 
\end{tikzpicture}
 | 
|
588  | 
\end{center}
 | 
|
589  | 
||
590  | 
\end{frame}
 | 
|
591  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
592  | 
||
593  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
594  | 
\begin{frame}[t,fragile]
 | 
|
595  | 
\frametitle{Conditional Jumps}
 | 
|
596  | 
||
597  | 
\begin{minipage}{1.1\textwidth}
 | 
|
598  | 
\begin{itemize}
 | 
|
599  | 
\item \textcolor{codepurple}{\textbf{\texttt{if\_icmpeq}}} \bl{$label$}
 | 
|
600  | 
if two ints are equal, then jump\medskip  | 
|
601  | 
\item \textcolor{codepurple}{\textbf{\texttt{if\_icmpne}}} \bl{$label$}
 | 
|
602  | 
if two ints aren't equal, then jump\medskip  | 
|
603  | 
\item \textcolor{codepurple}{\textbf{\texttt{if\_icmpge}}} \bl{$label$}
 | 
|
604  | 
if one int is greater or equal then another, then jump  | 
|
605  | 
\item[]\ldots  | 
|
606  | 
\end{itemize}
 | 
|
607  | 
\end{minipage}\pause
 | 
|
608  | 
||
609  | 
\begin{lstlisting}[language=JVMIS,numbers=none,xleftmargin=2cm]
 | 
|
610  | 
/*@\bl{$L_1$:}@*/
 | 
|
611  | 
  if_icmpeq /*@\bl{$L_2$}@*/
 | 
|
612  | 
iload 1  | 
|
613  | 
ldc 1  | 
|
614  | 
iadd  | 
|
615  | 
  if_icmpeq /*@\bl{$L_1$}@*/
 | 
|
616  | 
/*@\bl{$L_2$:}@*/
 | 
|
617  | 
\end{lstlisting}
 | 
|
618  | 
||
619  | 
||
620  | 
\begin{textblock}{3.5}(11,12)
 | 
|
621  | 
\only<3>{labels must be unique}
 | 
|
622  | 
\end{textblock}
 | 
|
623  | 
\end{frame}
 | 
|
624  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
625  | 
||
626  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
627  | 
\begin{frame}[c,fragile]
 | 
|
628  | 
\frametitle{Compiling Ifs}
 | 
|
629  | 
||
630  | 
For example  | 
|
631  | 
||
632  | 
\begin{lstlisting}[mathescape,numbers=none,language=While]
 | 
|
| 810 | 633  | 
if 1 == 1 then x := 2 else y := 3  | 
| 608 | 634  | 
\end{lstlisting}
 | 
635  | 
||
636  | 
||
637  | 
\begin{center}
 | 
|
638  | 
\begin{lstlisting}[mathescape,language=JVMIS,numbers=none]
 | 
|
639  | 
ldc 1  | 
|
640  | 
ldc 1  | 
|
641  | 
   if_icmpne L_ifelse $\quad\tikz[remember picture] \node (C) {\mbox{}};$
 | 
|
642  | 
ldc 2  | 
|
643  | 
istore 0  | 
|
644  | 
   goto L_ifend $\quad\tikz[remember picture] \node (A) {\mbox{}};$
 | 
|
645  | 
L_ifelse: $\quad\tikz[remember picture] \node[] (D) {\mbox{}};$
 | 
|
646  | 
ldc 3  | 
|
647  | 
istore 1  | 
|
648  | 
L_ifend: $\quad\tikz[remember picture] \node[] (B) {\mbox{}};$
 | 
|
649  | 
\end{lstlisting}
 | 
|
650  | 
\end{center}
 | 
|
651  | 
||
652  | 
\begin{tikzpicture}[remember picture,overlay]
 | 
|
653  | 
  \draw[->,very thick] (A) edge [->,to path={-- ++(10mm,0mm) 
 | 
|
654  | 
-- ++(0mm,-17.3mm) |- (\tikztotarget)},line width=1mm] (B.east);  | 
|
655  | 
  \draw[->,very thick] (C) edge [->,to path={-- ++(10mm,0mm) 
 | 
|
656  | 
-- ++(0mm,-17.3mm) |- (\tikztotarget)},line width=1mm] (D.east);  | 
|
657  | 
\end{tikzpicture}
 | 
|
658  | 
||
659  | 
\end{frame}
 | 
|
660  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
661  | 
||
662  | 
||
663  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
664  | 
\begin{frame}[t]
 | 
|
665  | 
\frametitle{Compiling BExps}
 | 
|
666  | 
||
| 810 | 667  | 
{\Large\bl{$a_1 == a_2$}}
 | 
| 608 | 668  | 
|
669  | 
\begin{center}
 | 
|
670  | 
\bl{\begin{tabular}{lcl}
 | 
|
| 810 | 671  | 
$\text{compile}(a_1 == a_2, E, lab)$ & $\dn$\\ 
 | 
| 608 | 672  | 
\multicolumn{3}{l}{$\quad\text{compile}(a_1, E) \;@\;\text{compile}(a_2, E)\;@\; \text{if\_icmpne}\;lab$}
 | 
673  | 
\end{tabular}}
 | 
|
674  | 
\end{center}
 | 
|
675  | 
||
676  | 
\end{frame}
 | 
|
677  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
678  | 
||
679  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
680  | 
\begin{frame}[c, fragile]
 | 
|
681  | 
\frametitle{Boolean Expressions}
 | 
|
682  | 
||
683  | 
Compilation of boolean expressions:  | 
|
684  | 
||
685  | 
\begin{center}
 | 
|
686  | 
\begin{tikzpicture}[node distance=2mm and 4mm,
 | 
|
687  | 
 block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm},
 | 
|
688  | 
 point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red},
 | 
|
689  | 
 skip loop/.style={red, line width=1mm, to path={-- ++(0,-10mm) -| (\tikztotarget)}}]
 | 
|
690  | 
\node (A1) [point] {};
 | 
|
691  | 
\node (b) [block, right=of A1] {code of \bl{$b$}};
 | 
|
692  | 
\node (A2) [point, right=of b] {};
 | 
|
693  | 
\node (cs1) [block, right=of A2] {code of \bl{$cs_1$}};
 | 
|
694  | 
\node (A3) [point, right=of cs1] {};
 | 
|
695  | 
\node (cs2) [block, right=of A3] {code of \bl{$cs_2$}};
 | 
|
696  | 
\node (A4) [point, right=of cs2] {};
 | 
|
697  | 
||
698  | 
\only<1>{
 | 
|
699  | 
\draw (A1) edge [->, red, line width=1mm] (b);  | 
|
700  | 
\draw (b) edge [->, red, line width=1mm] (A2);  | 
|
701  | 
\draw (A2) edge [skip loop] (A3);  | 
|
702  | 
\draw (A3) edge [->, red, line width=1mm] (cs2);  | 
|
703  | 
\draw (cs2) edge [->,red, line width=1mm] (A4);  | 
|
704  | 
\node [below=of cs1] {\raisebox{-5mm}{\small{}conditional jump}};}
 | 
|
705  | 
\end{tikzpicture}
 | 
|
706  | 
\end{center}
 | 
|
707  | 
||
708  | 
\begin{center}
 | 
|
709  | 
\begin{tabular}{lcl}
 | 
|
710  | 
\texttt{Bop("==", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpne...}\\
 | 
|
711  | 
\texttt{Bop("!=", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpeq...}\\
 | 
|
712  | 
\texttt{Bop("<", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpge...}\\
 | 
|
713  | 
\texttt{Bop("<=", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpgt...}\\
 | 
|
714  | 
\end{tabular}
 | 
|
715  | 
\end{center}
 | 
|
716  | 
||
717  | 
\end{frame}
 | 
|
718  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
719  | 
||
720  | 
||
721  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
722  | 
\begin{frame}[t]
 | 
|
723  | 
\frametitle{Compiling Ifs}
 | 
|
724  | 
||
725  | 
{\Large\bl{if $b$ then $cs_1$ else $cs_2$}}
 | 
|
726  | 
||
727  | 
\begin{center}
 | 
|
728  | 
\bl{\begin{tabular}{lcl}
 | 
|
729  | 
$\text{compile}(\text{if}\;b\;\text{then}\; cs_1\;\text{else}\; cs_2, E)$ & $\dn$\\ 
 | 
|
730  | 
\multicolumn{3}{l}{$\quad l_{ifelse}\;$ \textcolor{black}{(fresh label)}}\\
 | 
|
731  | 
\multicolumn{3}{l}{$\quad l_{ifend}\;$ \textcolor{black}{(fresh label)}}\\
 | 
|
732  | 
\multicolumn{3}{l}{$\quad (is_1, E') = \text{compile}(cs_1, E)$}\\
 | 
|
733  | 
\multicolumn{3}{l}{$\quad (is_2, E'') = \text{compile}(cs_2, E')$}\\
 | 
|
734  | 
\multicolumn{3}{l}{$\quad(\text{compile}(b, E, l_{ifelse})$}\\
 | 
|
735  | 
\multicolumn{3}{l}{$\quad\phantom{(}@\;is_1$}\\
 | 
|
736  | 
\multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{ifend}$}\\
 | 
|
737  | 
\multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifelse}:$}\\
 | 
|
738  | 
\multicolumn{3}{l}{$\quad\phantom{(}@\;is_2$}\\
 | 
|
739  | 
\multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifend}:, E'')$}\\
 | 
|
740  | 
\end{tabular}}
 | 
|
741  | 
\end{center}
 | 
|
742  | 
||
743  | 
\end{frame}
 | 
|
744  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
745  | 
||
746  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
747  | 
\begin{frame}[t]
 | 
|
748  | 
\frametitle{Compiling Whiles}
 | 
|
749  | 
||
750  | 
{\Large\bl{$\text{while}\;b\;\text{do}\;cs$}}\bigskip\bigskip
 | 
|
751  | 
||
752  | 
\onslide<2->{Case }\only<2>{{\bf True}:}\only<3>{{\bf False}:}
 | 
|
753  | 
||
754  | 
\begin{center}
 | 
|
755  | 
\begin{tikzpicture}[node distance=2mm and 4mm,
 | 
|
756  | 
 block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm},
 | 
|
757  | 
 point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red},
 | 
|
758  | 
 skip loop/.style={red, line width=1mm, to path={-- ++(0,-10mm) -| (\tikztotarget)}}]
 | 
|
759  | 
\node (A0) [point, left=of A1] {};
 | 
|
760  | 
\node (A1) [point] {};
 | 
|
761  | 
\node (b) [block, right=of A1] {code of \bl{$b$}};
 | 
|
762  | 
\node (A2) [point, right=of b] {};
 | 
|
763  | 
\node (cs1) [block, right=of A2] {code of \bl{$cs$}};
 | 
|
764  | 
\node (A3) [point, right=of cs1] {};
 | 
|
765  | 
\node (A4) [point, right=of A3] {};
 | 
|
766  | 
||
767  | 
\only<2>{
 | 
|
768  | 
\draw (A0) edge [->, red, line width=1mm] (b);  | 
|
769  | 
\draw (b) edge [->, red, line width=1mm] (cs1);  | 
|
770  | 
\draw (cs1) edge [->, red, line width=1mm] (A3);  | 
|
771  | 
\draw (A3) edge [->,skip loop] (A1);}  | 
|
772  | 
\only<3>{
 | 
|
773  | 
\draw (A0) edge [->, red, line width=1mm] (b);  | 
|
774  | 
\draw (b) edge [->, red, line width=1mm] (A2);  | 
|
775  | 
\draw (A2) edge [skip loop] (A3);  | 
|
776  | 
\draw (A3) edge [->, red, line width=1mm] (A4);}  | 
|
777  | 
\end{tikzpicture}
 | 
|
778  | 
\end{center}
 | 
|
779  | 
||
780  | 
\end{frame}
 | 
|
781  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
782  | 
||
783  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
784  | 
\begin{frame}[t]
 | 
|
785  | 
\frametitle{Compiling Whiles}
 | 
|
786  | 
||
787  | 
{\Large\bl{while $b$ do $cs$}}
 | 
|
788  | 
||
789  | 
\begin{center}
 | 
|
790  | 
\bl{\begin{tabular}{lcl}
 | 
|
791  | 
$\text{compile}(\text{while}\; b\; \text{do} \;cs, E)$ & $\dn$\\ 
 | 
|
792  | 
\multicolumn{3}{l}{$\quad l_{wbegin}\;$ \textcolor{black}{(fresh label)}}\\
 | 
|
793  | 
\multicolumn{3}{l}{$\quad l_{wend}\;$ \textcolor{black}{(fresh label)}}\\
 | 
|
794  | 
\multicolumn{3}{l}{$\quad (is, E') = \text{compile}(cs_1, E)$}\\
 | 
|
795  | 
\multicolumn{3}{l}{$\quad(l_{wbegin}:$}\\
 | 
|
796  | 
\multicolumn{3}{l}{$\quad\phantom{(}@\;\text{compile}(b, E, l_{wend})$}\\
 | 
|
797  | 
\multicolumn{3}{l}{$\quad\phantom{(}@\;is$}\\
 | 
|
798  | 
\multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{wbegin}$}\\
 | 
|
799  | 
\multicolumn{3}{l}{$\quad\phantom{(}@\;l_{wend}:, E')$}\\
 | 
|
800  | 
\end{tabular}}
 | 
|
801  | 
\end{center}
 | 
|
802  | 
||
803  | 
\end{frame}
 | 
|
804  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
805  | 
||
806  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
807  | 
\begin{frame}[c,fragile]
 | 
|
808  | 
\frametitle{Compiling Whiles}
 | 
|
809  | 
||
810  | 
For example  | 
|
811  | 
||
812  | 
\begin{lstlisting}[mathescape,numbers=none,language=While]
 | 
|
813  | 
while x <= 10 do x := x + 1  | 
|
814  | 
\end{lstlisting}
 | 
|
815  | 
||
816  | 
||
817  | 
\begin{center}
 | 
|
818  | 
\begin{lstlisting}[mathescape,language=JVMIS,numbers=none]
 | 
|
819  | 
L_wbegin: $\quad\tikz[remember picture] \node[] (LB) {\mbox{}};$
 | 
|
820  | 
iload 0  | 
|
821  | 
ldc 10  | 
|
822  | 
   if_icmpgt L_wend $\quad\tikz[remember picture] \node (LC) {\mbox{}};$
 | 
|
823  | 
iload 0  | 
|
824  | 
ldc 1  | 
|
825  | 
iadd  | 
|
826  | 
istore 0  | 
|
827  | 
   goto L_wbegin $\quad\tikz[remember picture] \node (LA) {\mbox{}};$
 | 
|
828  | 
L_wend: $\quad\tikz[remember picture] \node[] (LD) {\mbox{}};$
 | 
|
829  | 
\end{lstlisting}
 | 
|
830  | 
\end{center}
 | 
|
831  | 
||
832  | 
\begin{tikzpicture}[remember picture,overlay]
 | 
|
833  | 
  \draw[->,very thick] (LA) edge [->,to path={-- ++(12mm,0mm) 
 | 
|
834  | 
-- ++(0mm,17.3mm) |- (\tikztotarget)},line width=1mm] (LB.east);  | 
|
835  | 
  \draw[->,very thick] (LC) edge [->,to path={-- ++(12mm,0mm) 
 | 
|
836  | 
-- ++(0mm,-17.3mm) |- (\tikztotarget)},line width=1mm] (LD.east);  | 
|
837  | 
\end{tikzpicture}
 | 
|
838  | 
||
839  | 
\end{frame}
 | 
|
840  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
841  | 
||
842  | 
||
843  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
844  | 
\begin{frame}[c,fragile]
 | 
|
845  | 
\frametitle{Compiling Writes}
 | 
|
846  | 
||
847  | 
\small  | 
|
848  | 
\begin{lstlisting}[language=JVMIS,mathescape,
 | 
|
849  | 
numbers=none,xleftmargin=-6mm]  | 
|
850  | 
.method public static write(I)V  | 
|
851  | 
.limit locals 1  | 
|
852  | 
.limit stack 2  | 
|
| 811 | 853  | 
getstatic java/lang/System/out Ljava/io/PrintStream;  | 
| 608 | 854  | 
iload 0  | 
855  | 
invokevirtual java/io/PrintStream/println(I)V  | 
|
856  | 
return  | 
|
857  | 
.end method  | 
|
858  | 
||
859  | 
||
860  | 
||
861  | 
iload $E(x)$  | 
|
862  | 
invokestatic XXX/XXX/write(I)V  | 
|
863  | 
\end{lstlisting}
 | 
|
864  | 
||
865  | 
\end{frame}
 | 
|
866  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
867  | 
||
868  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
869  | 
\begin{frame}[c,fragile]
 | 
|
870  | 
\frametitle{Compiling Main}
 | 
|
871  | 
||
872  | 
\footnotesize  | 
|
873  | 
\begin{lstlisting}[language=JVMIS,mathescape,
 | 
|
874  | 
numbers=none,xleftmargin=-6mm]  | 
|
875  | 
.class public XXX.XXX  | 
|
876  | 
.super java/lang/Object  | 
|
877  | 
||
| 811 | 878  | 
...  | 
| 608 | 879  | 
|
880  | 
.method public static main([Ljava/lang/String;)V  | 
|
881  | 
.limit locals 200  | 
|
882  | 
.limit stack 200  | 
|
883  | 
||
884  | 
      $\textit{\ldots{}here comes the compiled code\ldots}$
 | 
|
885  | 
||
886  | 
return  | 
|
887  | 
.end method  | 
|
888  | 
\end{lstlisting}
 | 
|
889  | 
||
| 811 | 890  | 
%.method public <init>()V  | 
891  | 
% aload_0  | 
|
892  | 
% invokenonvirtual java/lang/Object/<init>()V  | 
|
893  | 
% return  | 
|
894  | 
%.end method  | 
|
895  | 
||
896  | 
||
| 608 | 897  | 
\end{frame}
 | 
898  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
899  | 
||
900  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
901  | 
\begin{frame}[c]
 | 
|
| 686 | 902  | 
\frametitle{Next Compiler Phases}
 | 
| 608 | 903  | 
|
904  | 
\begin{itemize}
 | 
|
905  | 
\item assembly $\Rightarrow$ byte code (class file)  | 
|
906  | 
\item labels $\Rightarrow$ absolute or relative jumps\bigskip\bigskip  | 
|
907  | 
\item \texttt{javap} is a disassembler for class files
 | 
|
| 686 | 908  | 
\item jasmin and krakatau are assemblers for jvm code  | 
| 
369
 
43c0ed473720
updated
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
302 
diff
changeset
 | 
909  | 
\end{itemize}
 | 
| 
 
43c0ed473720
updated
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
302 
diff
changeset
 | 
910  | 
|
| 686 | 911  | 
\end{frame}
 | 
| 608 | 912  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
913  | 
||
914  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
915  | 
\begin{frame}[t]
 | 
|
| 686 | 916  | 
\frametitle{Recall: Interpreted Code}
 | 
917  | 
||
918  | 
\begin{center}
 | 
|
919  | 
\begin{tikzpicture}
 | 
|
920  | 
\begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small]
 | 
|
921  | 
\addplot+[smooth] file {interpreted.data};
 | 
|
922  | 
\end{axis}
 | 
|
923  | 
\end{tikzpicture}
 | 
|
924  | 
\end{center}
 | 
|
925  | 
||
926  | 
Loop program  | 
|
927  | 
\end{frame}
 | 
|
928  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
929  | 
||
930  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
931  | 
\begin{frame}[t]
 | 
|
932  | 
\frametitle{Compiled Code}
 | 
|
| 608 | 933  | 
|
934  | 
\begin{center}
 | 
|
935  | 
\begin{tikzpicture}
 | 
|
936  | 
\begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small]
 | 
|
937  | 
\addplot+[smooth] file {compiled.data};
 | 
|
938  | 
\end{axis}
 | 
|
939  | 
\end{tikzpicture}
 | 
|
940  | 
\end{center}
 | 
|
941  | 
||
| 686 | 942  | 
\end{frame}
 | 
| 608 | 943  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
944  | 
||
945  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
946  | 
\begin{frame}[t]
 | 
|
| 686 | 947  | 
\frametitle{Compiler vs.~Interpreter}
 | 
| 608 | 948  | 
|
949  | 
\begin{center}
 | 
|
950  | 
\begin{tikzpicture}
 | 
|
951  | 
\begin{axis}[axis x line=bottom, axis y line=left, ylabel=secs,
 | 
|
952  | 
xlabel=n,  | 
|
953  | 
enlargelimits=0.05,  | 
|
954  | 
ybar interval=0.7, legend style=small]  | 
|
955  | 
\addplot file {interpreted2.data};
 | 
|
956  | 
\addplot file {compiled2.data};
 | 
|
957  | 
%\legend{interpreted, compiled}
 | 
|
958  | 
\end{axis}
 | 
|
959  | 
\end{tikzpicture}
 | 
|
960  | 
\end{center}
 | 
|
961  | 
||
| 686 | 962  | 
\end{frame}
 | 
| 608 | 963  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
964  | 
||
965  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
| 686 | 966  | 
\begin{frame}[c]
 | 
967  | 
  \frametitle{A ``Compiler'' for BF*** to C}
 | 
|
968  | 
||
969  | 
  \begin{center}
 | 
|
970  | 
  \begin{tabular}{lcl}
 | 
|
971  | 
  \bl{\texttt{>}} & $\Rightarrow$ & \texttt{ptr++}\\
 | 
|
972  | 
  \bl{\texttt{<}} & $\Rightarrow$ & \texttt{ptr--}\\
 | 
|
973  | 
  \bl{\texttt{+}} & $\Rightarrow$ & \texttt{(*ptr)++}\\
 | 
|
974  | 
  \bl{\texttt{-}} & $\Rightarrow$ & \texttt{(*ptr)--}\\
 | 
|
975  | 
  \bl{\texttt{.}} & $\Rightarrow$ & \texttt{putchar(*ptr)}\\
 | 
|
976  | 
  \bl{\texttt{,}} & $\Rightarrow$ & \texttt{*ptr = getchar()}\\
 | 
|
977  | 
  \bl{\texttt{[}} & $\Rightarrow$ & \texttt{while(*ptr)\{}\\
 | 
|
978  | 
  \bl{\texttt{]}} & $\Rightarrow$ & \texttt{\}}\medskip\\
 | 
|
979  | 
& $\Rightarrow$ & ignore everything else\\  | 
|
980  | 
  \end{tabular}  
 | 
|
981  | 
  \end{center}\bigskip  
 | 
|
982  | 
||
983  | 
  \texttt{char field[30000]\\ char *ptr = \&field[15000]}
 | 
|
984  | 
||
985  | 
\end{frame}
 | 
|
986  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
987  | 
||
988  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
989  | 
\begin{frame}[c,fragile]
 | 
|
990  | 
\frametitle{BF***}
 | 
|
991  | 
||
992  | 
we need some big array, say \texttt{arr} and 7 (8) instructions:\medskip
 | 
|
993  | 
||
994  | 
\begin{itemize}
 | 
|
995  | 
\item \texttt{>} move \texttt{ptr++}
 | 
|
996  | 
\item \texttt{<} move \texttt{ptr-{}-}
 | 
|
997  | 
\item \texttt{+} add \texttt{arr[ptr]++}
 | 
|
998  | 
\item \texttt{-} subtract \texttt{arr[ptr]-{}-}
 | 
|
999  | 
\item \texttt{.} print out \texttt{arr[ptr]} as ASCII
 | 
|
1000  | 
\item \texttt{[} if \texttt{arr[ptr] == 0} jump just after the corresponding \texttt{]}; otherwise \texttt{ptr++}
 | 
|
1001  | 
\item \texttt{]} if \texttt{arr[ptr] != 0} jump just after the corresponding \texttt{[}; otherwise \texttt{ptr++}
 | 
|
1002  | 
||
1003  | 
\end{itemize}  
 | 
|
1004  | 
||
1005  | 
\end{frame}
 | 
|
1006  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
1007  | 
||
1008  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
1009  | 
\begin{frame}[c,fragile]
 | 
|
1010  | 
\frametitle{Arrays in While}
 | 
|
1011  | 
||
1012  | 
\begin{itemize}
 | 
|
1013  | 
\item \texttt{new arr[15000]}\medskip 
 | 
|
1014  | 
\item \texttt{x := 3 + arr[3 + y]}\medskip 
 | 
|
1015  | 
\item \texttt{arr[42 * n] := ...}
 | 
|
1016  | 
\end{itemize}  
 | 
|
1017  | 
||
1018  | 
\end{frame}
 | 
|
1019  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
1020  | 
||
1021  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
1022  | 
\begin{frame}[c,fragile]
 | 
|
1023  | 
\frametitle{New Arrays}
 | 
|
1024  | 
||
1025  | 
\begin{lstlisting}[mathescape,numbers=none,language=While]
 | 
|
1026  | 
new arr[number]  | 
|
1027  | 
\end{lstlisting}\bigskip\bigskip
 | 
|
1028  | 
||
1029  | 
\begin{lstlisting}[mathescape,numbers=none,language=JVMIS]
 | 
|
1030  | 
ldc number  | 
|
1031  | 
newarray int  | 
|
1032  | 
astore loc_var  | 
|
1033  | 
\end{lstlisting}
 | 
|
1034  | 
||
1035  | 
||
1036  | 
\end{frame}
 | 
|
1037  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
1038  | 
||
1039  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
1040  | 
\begin{frame}[c,fragile]
 | 
|
1041  | 
\frametitle{Array Update}
 | 
|
1042  | 
||
1043  | 
\begin{lstlisting}[mathescape,numbers=none,language=While]
 | 
|
1044  | 
arr[...] :=  | 
|
1045  | 
\end{lstlisting}\bigskip\bigskip
 | 
|
1046  | 
||
1047  | 
\begin{lstlisting}[mathescape,numbers=none,language=JVMIS]
 | 
|
1048  | 
aload loc_var  | 
|
1049  | 
index_aexp  | 
|
1050  | 
value_aexp  | 
|
1051  | 
iastore  | 
|
1052  | 
\end{lstlisting}
 | 
|
1053  | 
||
1054  | 
||
1055  | 
\end{frame}
 | 
|
1056  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
1057  | 
||
1058  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
1059  | 
\begin{frame}[c,fragile]
 | 
|
1060  | 
\frametitle{Array Lookup in AExp}
 | 
|
1061  | 
||
1062  | 
\begin{lstlisting}[mathescape,numbers=none,language=While]
 | 
|
1063  | 
...arr[...]...  | 
|
1064  | 
\end{lstlisting}\bigskip\bigskip
 | 
|
1065  | 
||
1066  | 
\begin{lstlisting}[mathescape,numbers=none,language=JVMIS]
 | 
|
1067  | 
aload loc_var  | 
|
1068  | 
index_aexp  | 
|
1069  | 
iaload  | 
|
1070  | 
\end{lstlisting}
 | 
|
1071  | 
||
1072  | 
||
1073  | 
\end{frame}
 | 
|
1074  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
1075  | 
||
1076  | 
||
| 852 | 1077  | 
|
1078  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
1079  | 
\begin{frame}[t, fragile]
 | 
|
1080  | 
\frametitle{Function Definitions}
 | 
|
1081  | 
||
1082  | 
\footnotesize  | 
|
1083  | 
\begin{lstlisting}[language=JVMIS, 
 | 
|
1084  | 
xleftmargin=2mm,  | 
|
1085  | 
numbers=none]  | 
|
1086  | 
.method public static write(I)V  | 
|
1087  | 
.limit locals 1  | 
|
1088  | 
.limit stack 2  | 
|
1089  | 
getstatic java/lang/System/out Ljava/io/PrintStream;  | 
|
1090  | 
iload 0  | 
|
1091  | 
invokevirtual java/io/PrintStream/println(I)V  | 
|
1092  | 
return  | 
|
1093  | 
.end method  | 
|
1094  | 
\end{lstlisting}\bigskip
 | 
|
1095  | 
||
1096  | 
\small We will need methods for definitions like\footnotesize\medskip  | 
|
1097  | 
||
1098  | 
\begin{lstlisting}[language=JVMIS, 
 | 
|
1099  | 
xleftmargin=2mm,  | 
|
1100  | 
numbers=none]  | 
|
1101  | 
def fname (x1, ... , xn) = ...  | 
|
1102  | 
||
1103  | 
.method public static fname (I...I)I  | 
|
1104  | 
.limit locals ??  | 
|
1105  | 
.limit stack ??  | 
|
1106  | 
??  | 
|
1107  | 
.end method  | 
|
1108  | 
\end{lstlisting}
 | 
|
1109  | 
||
1110  | 
\end{frame}
 | 
|
1111  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
1112  | 
||
1113  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
1114  | 
\begin{frame}[c, fragile]
 | 
|
1115  | 
\frametitle{Stack Estimation}
 | 
|
1116  | 
\small  | 
|
1117  | 
\mbox{}\\[-15mm]
 | 
|
1118  | 
||
1119  | 
\bl{\begin{center}
 | 
|
1120  | 
\begin{tabular}{@{\hspace{-4mm}}l@{\hspace{2mm}}c@{\hspace{2mm}}l@{}}
 | 
|
1121  | 
$\textit{estimate}(n)$ & $\dn$ & $1$\\
 | 
|
1122  | 
$\textit{estimate}(x)$ & $\dn$ & $1$\\
 | 
|
1123  | 
$\textit{estimate}(a_1\;aop\;a_2)$ & $\dn$ &
 | 
|
1124  | 
$\textit{estimate}(a_1) + \textit{estimate}(a_2)$\\
 | 
|
1125  | 
$\textit{estimate}(\pcode{if}\;b\;\pcode{then}\;e_1\;\pcode{else}\;e_2)$ & $\dn$ & 
 | 
|
1126  | 
$\textit{estimate}(b) +$\\ 
 | 
|
1127  | 
& & $\quad max(\textit{estimate}(e_1), \textit{estimate}(e_2))$\\
 | 
|
1128  | 
$\textit{estimate}(\pcode{write}(e))$ & $\dn$ & 
 | 
|
1129  | 
$\textit{estimate}(e) + 1$\\
 | 
|
1130  | 
$\textit{estimate}(e_1 ; e_2)$ & $\dn$ & 
 | 
|
1131  | 
$max(\textit{estimate}(e_1), \textit{estimate}(e_2))$\\
 | 
|
1132  | 
$\textit{estimate}(f(e_1, ..., e_n))$ & $\dn$ & 
 | 
|
1133  | 
$\sum_{i = 1..n}\;estimate(e_i)$\medskip\\
 | 
|
1134  | 
$\textit{estimate}(a_1\;bop\;a_2)$ & $\dn$ &
 | 
|
1135  | 
$\textit{estimate}(a_1) + \textit{estimate}(a_2)$\\
 | 
|
1136  | 
\end{tabular}
 | 
|
1137  | 
\end{center}}
 | 
|
1138  | 
||
1139  | 
\end{frame}
 | 
|
1140  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
1141  | 
||
1142  | 
||
| 686 | 1143  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
| 608 | 1144  | 
\mode<presentation>{
 | 
1145  | 
\begin{frame}[c]
 | 
|
1146  | 
\frametitle{Backend}
 | 
|
1147  | 
||
1148  | 
\begin{center}
 | 
|
1149  | 
\begin{tikzpicture}
 | 
|
1150  | 
\node (rexp)  {\bl{\bf Lexer}};
 | 
|
1151  | 
\node (nfa) [right=of rexp] {\bl{\bf Parser}};
 | 
|
1152  | 
\node (dfa) [right=of nfa] {\bl{\begin{tabular}{c}\bf Optimizations\end{tabular}}};
 | 
|
1153  | 
\path[->, red, line width=2mm] (rexp) edge node [above=4mm, black] {\begin{tabular}{c@{\hspace{9mm}}}token\\[-1mm]
 | 
|
1154  | 
sequence\end{tabular}} (nfa);
 | 
|
1155  | 
\node (final) [below=of dfa] {\bl{\begin{tabular}{c}\bf Machine Code/\\\bf Byte Code\end{tabular}}};
 | 
|
1156  | 
\path[->, red, line width=2mm] (nfa) edge node [above=4mm, black] {\begin{tabular}{c}parse\\[-1mm] tree
 | 
|
1157  | 
\end{tabular}}(dfa);
 | 
|
1158  | 
\path[->, red, line width=2mm] (dfa) edge (final);  | 
|
1159  | 
\end{tikzpicture}\\
 | 
|
1160  | 
\end{center}
 | 
|
1161  | 
||
1162  | 
\end{frame}}
 | 
|
| 
369
 
43c0ed473720
updated
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
302 
diff
changeset
 | 
1163  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
| 
 
43c0ed473720
updated
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
302 
diff
changeset
 | 
1164  | 
|
| 608 | 1165  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
1166  | 
\mode<presentation>{
 | 
|
1167  | 
\begin{frame}[t]
 | 
|
1168  | 
\frametitle{\begin{tabular}{c}What is Next\end{tabular}}
 | 
|
1169  | 
||
1170  | 
\begin{itemize}
 | 
|
1171  | 
\item register spilling  | 
|
1172  | 
\item dead code removal  | 
|
1173  | 
\item loop optimisations  | 
|
1174  | 
\item instruction selection  | 
|
1175  | 
\item type checking  | 
|
1176  | 
\item concurrency  | 
|
1177  | 
\item fuzzy testing  | 
|
1178  | 
\item verification\bigskip\\  | 
|
1179  | 
||
1180  | 
\item GCC, LLVM, tracing JITs  | 
|
1181  | 
\end{itemize}
 | 
|
1182  | 
||
1183  | 
\end{frame}}
 | 
|
1184  | 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  | 
|
1185  | 
||
| 
184
 
2e9134d25a2b
added slides
 
Christian Urban <christian dot urban at kcl dot ac dot uk> 
parents: 
173 
diff
changeset
 | 
1186  | 
|
| 812 | 1187  | 
|
1188  | 
\begin{frame}<1-10>
 | 
|
1189  | 
\end{frame}  
 | 
|
1190  | 
||
| 63 | 1191  | 
\end{document}
 | 
1192  | 
||
1193  | 
%%% Local Variables:  | 
|
1194  | 
%%% mode: latex  | 
|
1195  | 
%%% TeX-master: t  | 
|
1196  | 
%%% End:  | 
|
1197  |