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