slides/slides09.tex
changeset 207 f824e1331fc6
parent 206 85b961f1eee9
child 215 828303e8e4af
equal deleted inserted replaced
206:85b961f1eee9 207:f824e1331fc6
    19 \usetikzlibrary{positioning}
    19 \usetikzlibrary{positioning}
    20 \usetikzlibrary{calc}
    20 \usetikzlibrary{calc}
    21 \usetikzlibrary{plotmarks}
    21 \usetikzlibrary{plotmarks}
    22 \usepackage{graphicx} 
    22 \usepackage{graphicx} 
    23 \usepackage{pgfplots}
    23 \usepackage{pgfplots}
    24 
    24 \setmonofont{Consolas}
    25 
    25 
    26 \definecolor{javared}{rgb}{0.6,0,0} % for strings
    26 \definecolor{javared}{rgb}{0.6,0,0} % for strings
    27 \definecolor{javagreen}{rgb}{0.25,0.5,0.35} % comments
    27 \definecolor{javagreen}{rgb}{0.25,0.5,0.35} % comments
    28 \definecolor{javapurple}{rgb}{0.5,0,0.35} % keywords
    28 \definecolor{javapurple}{rgb}{0.5,0,0.35} % keywords
    29 \definecolor{javadocblue}{rgb}{0.25,0.35,0.75} % javadoc
    29 \definecolor{javadocblue}{rgb}{0.25,0.35,0.75} % javadoc
    93 	stepnumber=1,
    93 	stepnumber=1,
    94 	numbersep=10pt,
    94 	numbersep=10pt,
    95 	tabsize=2,
    95 	tabsize=2,
    96 	showspaces=false,
    96 	showspaces=false,
    97 	showstringspaces=false}
    97 	showstringspaces=false}
    98 
    98 	
    99 
    99 
   100 % beamer stuff 
   100 % beamer stuff 
   101 \renewcommand{\slidecaption}{AFL 09, King's College London, 27.~November 2013}
   101 \renewcommand{\slidecaption}{AFL 09, King's College London, 27.~November 2013}
   102 \newcommand{\bl}[1]{\textcolor{blue}{#1}}       
   102 \newcommand{\bl}[1]{\textcolor{blue}{#1}}       
   103 \newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions
   103 \newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions
   198 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   198 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   199 \mode<presentation>{
   199 \mode<presentation>{
   200 \begin{frame}[c]
   200 \begin{frame}[c]
   201 
   201 
   202 {\large\bf
   202 {\large\bf
   203 What is a perfect attack?}
   203 What is a \alert{perfect} attack?}\bigskip
   204 
   204 
   205 \begin{enumerate}
   205 \begin{enumerate}
   206 \item you can potentially completely take over a target system
   206 \item you can potentially completely take over a target system
   207 \item your attack is (nearly) undetectable
   207 \item your attack is (nearly) undetectable
       
   208 \item the victim has (almost) no chance to recover
   208 \end{enumerate}
   209 \end{enumerate}
   209 
   210 
   210 \end{frame}}
   211 \end{frame}}
   211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   212 
   213 
   218   \begin{center}
   219   \begin{center}
   219   \begin{tikzpicture}[scale=1]
   220   \begin{tikzpicture}[scale=1]
   220   
   221   
   221   \onslide<1->{
   222   \onslide<1->{
   222   \node (A) at (0,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=17mm] {};
   223   \node (A) at (0,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=17mm] {};
   223   \node [below right] at (A.north west) {\footnotesize\begin{tabular}{@{}l@{}}clean\\compiler\end{tabular}};}
   224   \node [below right] at (A.north west) {\footnotesize\begin{tabular}{@{}l@{}}
       
   225   \only<1,2>{clean}\only<3->{\alert{hacked}}\\compiler\end{tabular}};}
   224 
   226 
   225 
   227 
   226   \onslide<2->{
   228   \onslide<2->{
   227   \node (B) at (0,3)  [draw=black, rectangle, very thick, minimum height=8mm, minimum width=12mm] {};
   229   \node (B) at (-2,2)  [draw=black, rectangle, very thick, minimum height=10mm, minimum width=12mm] {};
   228   \node [below right] at (B.north west) {\footnotesize login};
   230   \node [below right] at (B.north west) {\footnotesize\begin{tabular}{@{}l@{}}login\\(src)\end{tabular}};
   229   \node [above right] at (B.south west) {\footnotesize \alert{infected}};
   231   
   230   \node [right] at (B.east) {\ldots};
   232   \node (C) at (2,2)  [draw=black, rectangle, very thick, minimum height=10mm, minimum width=12mm] {};
       
   233   \node [below right] at (C.north west) {\footnotesize\begin{tabular}{@{}l@{}}login\\(bin)\end{tabular}};
       
   234 
       
   235   \draw[->, line width=2mm] (B) -- (C);
   231   }
   236   }
   232  
   237   
   233 
   238  \onslide<3->{\node [above left=-1.5mm] at (C.south east) {\footnotesize \alert{$\blacksquare$}};}
   234 
   239 
   235   
       
   236   \end{tikzpicture}
   240   \end{tikzpicture}
   237   \end{center}
   241   \end{center}
   238 
   242 
   239 
   243 \end{frame}}
   240 
   244 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   241 \end{frame}}
   245 
   242 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   246 
   243 
   247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   244 
   248 \mode<presentation>{
   245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   249 \begin{frame}[c]
   246 \mode<presentation>{
       
   247 \begin{frame}[c]
       
   248 
       
   249 
   250 
   250   \begin{center}
   251   \begin{center}
   251   \begin{tikzpicture}[scale=1]
   252   \begin{tikzpicture}[scale=1]
   252   
   253   
   253   \onslide<1->{
   254   \onslide<1->{
   279   \node [below right] at (F.north west) {\small V1.01};
   280   \node [below right] at (F.north west) {\small V1.01};
   280 
   281 
   281   \node (G) at (8.6,2)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
   282   \node (G) at (8.6,2)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
   282   \node [below right] at (G.north west) {\small V1.02};
   283   \node [below right] at (G.north west) {\small V1.02};
   283   \node at (9.8,0) {\ldots};
   284   \node at (9.8,0) {\ldots};
   284   \node at (9.8,2) {\ldots};}
   285   \node at (9.8,2) {\ldots};
       
   286   \node at (8,-2) {\textcolor{gray}{\begin{tabular}{@{}l@{}}no host language\\needed\end{tabular}}};
       
   287   }
   285   
   288   
   286   \end{tikzpicture}
   289   \end{tikzpicture}
   287   \end{center}
   290   \end{center}
   288 
       
   289 
       
   290 
   291 
   291 \end{frame}}
   292 \end{frame}}
   292 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   293 
   294 
   294 
   295 
   353 
   354 
   354 
   355 
   355 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   356 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   356 \mode<presentation>{
   357 \mode<presentation>{
   357 \begin{frame}[c]
   358 \begin{frame}[c]
       
   359 \frametitle{Our Compiler}
       
   360 
       
   361   \begin{center}
       
   362   \begin{tikzpicture}[scale=1]
       
   363 
       
   364   \node (0) at (-2.3,0) {}; 
       
   365   
       
   366   \node (A) at (0,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=20mm] {};
       
   367   \node [below right] at (A.north west) {lexer};
       
   368 
       
   369   \node (B) at (3,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=20mm] {};
       
   370   \node [below right=1mm] at (B.north west) {\mbox{}\hspace{-1mm}parser};
       
   371 
       
   372   \node (C) at (6,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=20mm] {};
       
   373   \node [below right] at (C.north west) {\mbox{}\hspace{-1mm}code gen};
       
   374 
       
   375   \node (1) at (8.4,0) {}; 
       
   376 
       
   377   \draw [->,line width=4mm] (0) -- (A); 
       
   378   \draw [->,line width=4mm] (A) -- (B); 
       
   379   \draw [->,line width=4mm] (B) -- (C); 
       
   380   \draw [->,line width=4mm] (C) -- (1); 
       
   381   \end{tikzpicture}
       
   382   \end{center}
       
   383 
       
   384 lexer input: string\medskip\\
       
   385 lexer output: sequence of tokens\\ 
       
   386 \mbox{}\hfill(white space and comments filtered out)\medskip\\
       
   387 parser output: abstract syntax tree\medskip\\ 
       
   388 code gen output: assembler byte code / \\
       
   389 \mbox{}\hfill assembler machine code
       
   390 \end{frame}}
       
   391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   392 
       
   393 
       
   394 
       
   395 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   396 \mode<presentation>{
       
   397 \begin{frame}[c]
       
   398 \frametitle{\begin{tabular}{c}For-Loops\end{tabular}}
       
   399 
       
   400 
       
   401 \begin{center}\Large
       
   402 \texttt{for} \;\textit{Id} \texttt{:=} \textit{AExp}\; \texttt{upto} \;\textit{AExp}\; \texttt{do} \textit{Block}
       
   403 \end{center}\bigskip
       
   404 
       
   405 \begin{center}
       
   406 \begin{minipage}{8cm}
       
   407 \begin{tabular}{l}
       
   408 \texttt{for i := 2 upto 4 do \{}\\
       
   409 \hspace{5mm}\texttt{write i}\\	
       
   410 \texttt{\}}\
       
   411 \end{tabular}
       
   412 \end{minipage}
       
   413 \end{center}
       
   414 \end{frame}}
       
   415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   416 
       
   417 
       
   418 
       
   419 
       
   420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   421 \mode<presentation>{
       
   422 \begin{frame}[c]
   358 \frametitle{\begin{tabular}{c}While-Language\end{tabular}}
   423 \frametitle{\begin{tabular}{c}While-Language\end{tabular}}
   359 
   424 
   360 
   425 
   361 \begin{center}
   426 \begin{center}
   362 \bl{\begin{tabular}{@{}lcl@{}}
   427 \bl{\begin{tabular}{@{}lcl@{}}
   363 $Stmt$ & $\rightarrow$ &  $\text{skip}$\\
   428 $Stmt$ & $\rightarrow$ &  $\text{skip}$\\
   364               & $|$ & $Id := AExp$\\
   429               & $|$ & $Id := AExp$\\
   365               & $|$ & $\text{if}\; B\!Exp \;\text{then}\; Block \;\text{else}\; Block$\\
   430               & $|$ & $\text{if}\; B\!Exp \;\text{then}\; Block \;\text{else}\; Block$\\
   366               & $|$ & $\text{while}\; B\!Exp \;\text{do}\; Block$\\
   431               & $|$ & $\text{while}\; B\!Exp \;\text{do}\; Block$\\
   367                & $|$ & $\alert{\text{write}\; Id}$\medskip\\
   432                & $|$ & $\alert{\text{write}\; Id}$\\
       
   433                 & $|$ & $\alert{\text{read}\; Id}$\medskip\\
   368 $Stmts$ & $\rightarrow$ &  $Stmt \;\text{;}\; Stmts$\\
   434 $Stmts$ & $\rightarrow$ &  $Stmt \;\text{;}\; Stmts$\\
   369               & $|$ & $Stmt$\medskip\\
   435               & $|$ & $Stmt$\medskip\\
   370 $Block$ & $\rightarrow$ &  $\{ Stmts \}$\\
   436 $Block$ & $\rightarrow$ &  $\{ Stmts \}$\\
   371                 & $|$ & $Stmt$\medskip\\
   437                 & $|$ & $Stmt$\medskip\\
   372 $AExp$ & $\rightarrow$ & \ldots\\
   438 $AExp$ & $\rightarrow$ & \ldots\\
   376 
   442 
   377 
   443 
   378 \end{frame}}
   444 \end{frame}}
   379 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   445 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   380 
   446 
   381 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   447 
   382 \mode<presentation>{
       
   383 \begin{frame}[c]
       
   384 \frametitle{\begin{tabular}{c}Fibonacci Numbers\end{tabular}}
       
   385 
       
   386 \mbox{}\\[-18mm]\mbox{}
       
   387 
       
   388 {\lstset{language=While}\fontsize{10}{12}\selectfont
       
   389 \texttt{\lstinputlisting{../progs/fib.while}}}
       
   390 
       
   391 \end{frame}}
       
   392 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   393 
   448 
   394 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   449 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   395 \mode<presentation>{
   450 \mode<presentation>{
   396 \begin{frame}[c]
   451 \begin{frame}[c]
   397 \frametitle{\begin{tabular}{c}Interpreter\end{tabular}}
   452 \frametitle{\begin{tabular}{c}Interpreter\end{tabular}}
   435 \end{center}
   490 \end{center}
   436 
   491 
   437 \end{frame}}
   492 \end{frame}}
   438 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   493 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   439 
   494 
   440 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   495  
   441 \mode<presentation>{
       
   442 \begin{frame}[c]
       
   443 \frametitle{\begin{tabular}{c}Test Program\end{tabular}}
       
   444 
       
   445 \mbox{}\\[-18mm]\mbox{}
       
   446 
       
   447 {\lstset{language=While}\fontsize{10}{12}\selectfont
       
   448 \texttt{\lstinputlisting{../progs/loops.while}}}
       
   449 
       
   450 \end{frame}}
       
   451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   452 
       
   453 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   454 \mode<presentation>{
       
   455 \begin{frame}[t]
       
   456 \frametitle{\begin{tabular}{c}Interpreted Code\end{tabular}}
       
   457 
       
   458 \begin{center}
       
   459 \begin{tikzpicture}
       
   460 \begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small]
       
   461 \addplot+[smooth] file {interpreted.data};
       
   462 \end{axis}
       
   463 \end{tikzpicture}
       
   464 \end{center}
       
   465 
       
   466 \end{frame}}
       
   467 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
       
   468 
       
   469 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   470 \mode<presentation>{
       
   471 \begin{frame}[c]
       
   472 \frametitle{\begin{tabular}{c}Java Virtual Machine\end{tabular}}
       
   473 
       
   474 \begin{itemize}
       
   475 \item introduced in 1995
       
   476 \item is a stack-based VM (like Postscript, CLR of .Net)
       
   477 \item contains a JIT compiler
       
   478 \item many languages take advantage of JVM's infrastructure (JRE)
       
   479 \item is garbage collected $\Rightarrow$ no buffer overflows
       
   480 \item some languages compiled to the JVM: Scala, Clojure\ldots
       
   481 \end{itemize}
       
   482 
       
   483 \end{frame}}
       
   484 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   485 
       
   486 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   487 \mode<presentation>{
       
   488 \begin{frame}[t]
       
   489 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
       
   490 
       
   491 {\Large\bl{1 + 2}}
       
   492 
       
   493 \begin{center}
       
   494 \bl{\begin{tabular}{l}
       
   495 ldc 1\\
       
   496 ldc 2\\
       
   497 iadd\\
       
   498 \end{tabular}}
       
   499 \end{center}\end{frame}}
       
   500 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   501 
       
   502 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   503 \mode<presentation>{
       
   504 \begin{frame}[t]
       
   505 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
       
   506 
       
   507 {\Large\bl{1 + 2 + 3}}
       
   508 
       
   509 \begin{center}
       
   510 \bl{\begin{tabular}{l}
       
   511 ldc 1\\
       
   512 ldc 2\\
       
   513 iadd\\
       
   514 ldc 3\\
       
   515 iadd\\
       
   516 \end{tabular}}
       
   517 \end{center}
       
   518 
       
   519 \end{frame}}
       
   520 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   521 
       
   522 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   523 \mode<presentation>{
       
   524 \begin{frame}[t]
       
   525 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
       
   526 
       
   527 {\Large\bl{1 + (2 + 3)}}
       
   528 
       
   529 \begin{center}
       
   530 \bl{\begin{tabular}{l}
       
   531 ldc 1\\
       
   532 ldc 2\\
       
   533 ldc 3\\
       
   534 iadd\\
       
   535 iadd\\
       
   536 \end{tabular}}
       
   537 \end{center}\bigskip\pause
       
   538 \vfill
       
   539 
       
   540 \bl{dadd, fadd, ladd, \ldots}
       
   541 
       
   542 \end{frame}}
       
   543 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   544 
       
   545 
       
   546 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   547 \mode<presentation>{
       
   548 \begin{frame}[t]
       
   549 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
       
   550 
       
   551 \begin{center}
       
   552 \bl{\begin{tabular}{@{}lcl@{}}
       
   553 $\text{compile}(n)$ & $\dn$ & $\text{ldc}\;n$\\
       
   554 $\text{compile}(a_1 + a_2)$ & $\dn$\\ 
       
   555 \multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\;\text{compile}(a_2)\;@\; \text{iadd}$}\smallskip\\
       
   556 $\text{compile}(a_1 - a_2)$ & $\dn$\\ 
       
   557 \multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\; \text{compile}(a_2)\;@\; \text{isub}$}\smallskip\\
       
   558 $\text{compile}(a_1 * a_2)$ & $\dn$\\ 
       
   559 \multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\; \text{compile}(a_2)\;@\; \text{imul}$}\smallskip\\
       
   560 \end{tabular}}
       
   561 \end{center}\pause
       
   562 
       
   563 \end{frame}}
       
   564 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
       
   565 
       
   566 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   567 \mode<presentation>{
       
   568 \begin{frame}[t]
       
   569 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
       
   570 
       
   571 {\Large\bl{1 + 2 * 3 + (4 - 3)}}
       
   572 
       
   573 \begin{center}
       
   574 \bl{\begin{tabular}{l}
       
   575 ldc 1\\
       
   576 ldc 2\\
       
   577 ldc 3\\
       
   578 imul\\
       
   579 ldc 4\\
       
   580 ldc 3\\
       
   581 isub\\
       
   582 iadd\\
       
   583 iadd\\
       
   584 \end{tabular}}
       
   585 \end{center}
       
   586 
       
   587 \end{frame}}
       
   588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   589 
       
   590 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   591 \mode<presentation>{
       
   592 \begin{frame}[t]
       
   593 \frametitle{\begin{tabular}{c}Variables\end{tabular}}
       
   594 
       
   595 {\Large\bl{$x := 5 + y * 2$}}\bigskip\pause   
       
   596 
       
   597 \begin{itemize}
       
   598 \item lookup: \bl{$\text{iload}\; index$}
       
   599 \item store: \bl{$\text{istore}\; index$}
       
   600 \end{itemize}\bigskip\pause
       
   601 
       
   602 while compilating we have to maintain a map between our identifiers and the
       
   603 Java bytecode indices
       
   604 
       
   605 \begin{center}
       
   606 \bl{$\text{compile}(a, E)$}
       
   607 \end{center}
       
   608 
       
   609 \end{frame}}
       
   610 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   611 
       
   612 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   613 \mode<presentation>{
       
   614 \begin{frame}[t]
       
   615 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
       
   616 
       
   617 \begin{center}
       
   618 \bl{\begin{tabular}{@{}lcl@{}}
       
   619 $\text{compile}(n, E)$ & $\dn$ & $\text{ldc}\;n$\\
       
   620 $\text{compile}(a_1 + a_2, E)$ & $\dn$\\ 
       
   621 \multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\;\text{compile}(a_2. E)\;@\; \text{iadd}$}\smallskip\\
       
   622 $\text{compile}(a_1 - a_2, E)$ & $\dn$\\ 
       
   623 \multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{isub}$}\smallskip\\
       
   624 $\text{compile}(a_1 * a_2, E)$ & $\dn$\\ 
       
   625 \multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{imul}$}\bigskip\\
       
   626 $\text{compile}(x, E)$ & $\dn$ & $\text{iload}\;E(x)$\\
       
   627 \end{tabular}}
       
   628 \end{center}\pause
       
   629 
       
   630 \end{frame}}
       
   631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
       
   632 
       
   633 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   634 \mode<presentation>{
       
   635 \begin{frame}[t]
       
   636 \frametitle{\begin{tabular}{c}Compiling Statements\end{tabular}}
       
   637 
       
   638 We return a list of instructions and an environment for the variables
       
   639 
       
   640 \begin{center}
       
   641 \bl{\begin{tabular}{@{}l@{\hspace{1mm}}c@{\hspace{1mm}}l@{}}
       
   642 $\text{compile}(\text{skip}, E)$ & $\dn$ & $(N\!il, E)$\bigskip\\
       
   643 $\text{compile}(x := a, E)$ & $\dn$\\
       
   644 \multicolumn{3}{l}{$(\text{compile}(a, E) \;@\;\text{istore}\;index, E(x\mapsto index))$}\\
       
   645 \end{tabular}}
       
   646 \end{center}\medskip
       
   647 
       
   648 where \bl{$index$} is \bl{$E(x)$} if it is already defined, or if it is not then the largest index not yet seen
       
   649 
       
   650 \end{frame}}
       
   651 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
       
   652 
       
   653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   654 \mode<presentation>{
       
   655 \begin{frame}[t]
       
   656 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
       
   657 
       
   658 {\Large\bl{$x := x + 1$}}
       
   659 
       
   660 \begin{center}
       
   661 \bl{\begin{tabular}{l}
       
   662 iload $n_x$\\
       
   663 ldc 1\\
       
   664 iadd\\
       
   665 istore $n_x$\\
       
   666 \end{tabular}}
       
   667 \end{center}
       
   668 
       
   669 where \bl{$n_x$} is the index corresponding to the variable \bl{$x$}
       
   670 
       
   671 \end{frame}}
       
   672 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   673 
       
   674 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   675 \mode<presentation>{
       
   676 \begin{frame}[t]
       
   677 \frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}}
       
   678 
       
   679 {\Large\bl{$\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2$}}\bigskip\bigskip
       
   680 
       
   681 \onslide<2->{Case }\only<2>{{\bf True}:}\only<3>{{\bf False}:}
       
   682 
       
   683 \begin{center}
       
   684 \begin{tikzpicture}[node distance=2mm and 4mm,
       
   685  block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm},
       
   686  point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red},
       
   687  skip loop/.style={red, line width=1mm, to path={-- ++(0,-10mm) -| (\tikztotarget)}}]
       
   688 \node (A1) [point] {};
       
   689 \node (b) [block, right=of A1] {code of \bl{$b$}};
       
   690 \node (A2) [point, right=of b] {};
       
   691 \node (cs1) [block, right=of A2] {code of \bl{$cs_1$}};
       
   692 \node (A3) [point, right=of cs1] {};
       
   693 \node (cs2) [block, right=of A3] {code of \bl{$cs_2$}};
       
   694 \node (A4) [point, right=of cs2] {};
       
   695 
       
   696 \only<2>{
       
   697 \draw (A1) edge [->, red, line width=1mm] (b);
       
   698 \draw (b) edge [->, red, line width=1mm] (cs1);
       
   699 \draw (cs1) edge [->, red, line width=1mm] (A3);
       
   700 \draw (A3) edge [->,skip loop] (A4);
       
   701 \node [below=of cs2] {\raisebox{-5mm}{\small{}jump}};}
       
   702 \only<3>{
       
   703 \draw (A1) edge [->, red, line width=1mm] (b);
       
   704 \draw (b) edge [->, red, line width=1mm] (A2);
       
   705 \draw (A2) edge [skip loop] (A3);
       
   706 \draw (A3) edge [->, red, line width=1mm] (cs2);
       
   707 \draw (cs2) edge [->,red, line width=1mm] (A4);
       
   708 \node [below=of cs1] {\raisebox{-5mm}{\small{}conditional jump}};}
       
   709 \end{tikzpicture}
       
   710 \end{center}
       
   711 
       
   712 
       
   713 \end{frame}}
       
   714 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   715 
       
   716 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   717 \mode<presentation>{
       
   718 \begin{frame}[c]
       
   719 \frametitle{\begin{tabular}{c}Conditional Jumps\end{tabular}}
       
   720 
       
   721 \begin{minipage}{1.1\textwidth}
       
   722 \begin{itemize}
       
   723 \item \bl{if\_icmpeq $label$} if two ints are equal, then jump\medskip
       
   724 \item \bl{if\_icmpne $label$} if two ints aren't equal, then jump\medskip
       
   725 \item \bl{if\_icmpge $label$} if one int is greater or equal then another, then jump
       
   726 \item[]\ldots
       
   727 \end{itemize}
       
   728 \end{minipage}\pause
       
   729 
       
   730 
       
   731 \begin{center}
       
   732 \bl{\begin{tabular}{l}
       
   733 $L_1$:\\
       
   734 \hspace{5mm}if\_icmpeq\;$L_2$\\
       
   735 \hspace{5mm}iload 1\\
       
   736 \hspace{5mm}ldc 1\\
       
   737 \hspace{5mm}iadd\\
       
   738 \hspace{5mm}if\_icmpeq\;$L_1$\\
       
   739 $L_2$:
       
   740 \end{tabular}}
       
   741 \end{center}
       
   742 
       
   743 \begin{textblock}{3.5}(11,12)
       
   744 \only<3>{labels must be unique}
       
   745 \end{textblock}
       
   746 \end{frame}}
       
   747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   748 
       
   749 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   750 \mode<presentation>{
       
   751 \begin{frame}[t]
       
   752 \frametitle{\begin{tabular}{c}Compiling BExps\end{tabular}}
       
   753 
       
   754 {\Large\bl{$a_1 = a_2$}}
       
   755 
       
   756 \begin{center}
       
   757 \bl{\begin{tabular}{lcl}
       
   758 $\text{compile}(a_1 = a_2, E, lab)$ & $\dn$\\ 
       
   759 \multicolumn{3}{l}{$\quad\text{compile}(a_1, E) \;@\;\text{compile}(a_2, E)\;@\; \text{if\_icmpne}\;lab$}
       
   760 \end{tabular}}
       
   761 \end{center}
       
   762 
       
   763 \end{frame}}
       
   764 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   765 
       
   766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   767 \mode<presentation>{
       
   768 \begin{frame}[t]
       
   769 \frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}}
       
   770 
       
   771 {\Large\bl{if $b$ then $cs_1$ else $cs_2$}}
       
   772 
       
   773 \begin{center}
       
   774 \bl{\begin{tabular}{lcl}
       
   775 $\text{compile}(\text{if}\;b\;\text{then}\; cs_1\;\text{else}\; cs_2, E)$ & $\dn$\\ 
       
   776 \multicolumn{3}{l}{$\quad l_{ifelse}\;$ \textcolor{black}{(fresh label)}}\\
       
   777 \multicolumn{3}{l}{$\quad l_{ifend}\;$ \textcolor{black}{(fresh label)}}\\
       
   778 \multicolumn{3}{l}{$\quad (is_1, E') = \text{compile}(cs_1, E)$}\\
       
   779 \multicolumn{3}{l}{$\quad (is_2, E'') = \text{compile}(cs_2, E')$}\\
       
   780 \multicolumn{3}{l}{$\quad(\text{compile}(b, E, l_{ifelse})$}\\
       
   781 \multicolumn{3}{l}{$\quad\phantom{(}@\;is_1$}\\
       
   782 \multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{ifend}$}\\
       
   783 \multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifelse}:$}\\
       
   784 \multicolumn{3}{l}{$\quad\phantom{(}@\;is_2$}\\
       
   785 \multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifend}:, E'')$}\\
       
   786 \end{tabular}}
       
   787 \end{center}
       
   788 
       
   789 \end{frame}}
       
   790 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   791 
       
   792 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   793 \mode<presentation>{
       
   794 \begin{frame}[t]
       
   795 \frametitle{\begin{tabular}{c}Compiling Whiles\end{tabular}}
       
   796 
       
   797 {\Large\bl{$\text{while}\;b\;\text{do}\;cs$}}\bigskip\bigskip
       
   798 
       
   799 \onslide<2->{Case }\only<2>{{\bf True}:}\only<3>{{\bf False}:}
       
   800 
       
   801 \begin{center}
       
   802 \begin{tikzpicture}[node distance=2mm and 4mm,
       
   803  block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm},
       
   804  point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red},
       
   805  skip loop/.style={red, line width=1mm, to path={-- ++(0,-10mm) -| (\tikztotarget)}}]
       
   806 \node (A0) [point, left=of A1] {};
       
   807 \node (A1) [point] {};
       
   808 \node (b) [block, right=of A1] {code of \bl{$b$}};
       
   809 \node (A2) [point, right=of b] {};
       
   810 \node (cs1) [block, right=of A2] {code of \bl{$cs$}};
       
   811 \node (A3) [point, right=of cs1] {};
       
   812 \node (A4) [point, right=of A3] {};
       
   813 
       
   814 \only<2>{
       
   815 \draw (A0) edge [->, red, line width=1mm] (b);
       
   816 \draw (b) edge [->, red, line width=1mm] (cs1);
       
   817 \draw (cs1) edge [->, red, line width=1mm] (A3);
       
   818 \draw (A3) edge [->,skip loop] (A1);}
       
   819 \only<3>{
       
   820 \draw (A0) edge [->, red, line width=1mm] (b);
       
   821 \draw (b) edge [->, red, line width=1mm] (A2);
       
   822 \draw (A2) edge [skip loop] (A3);
       
   823 \draw (A3) edge [->, red, line width=1mm] (A4);}
       
   824 \end{tikzpicture}
       
   825 \end{center}
       
   826 
       
   827 
       
   828 \end{frame}}
       
   829 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   830 
       
   831 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   832 \mode<presentation>{
       
   833 \begin{frame}[t]
       
   834 \frametitle{\begin{tabular}{c}Compiling Whiles\end{tabular}}
       
   835 
       
   836 {\Large\bl{while $b$ do $cs$}}
       
   837 
       
   838 \begin{center}
       
   839 \bl{\begin{tabular}{lcl}
       
   840 $\text{compile}(\text{while}\; b\; \text{do} \;cs, E)$ & $\dn$\\ 
       
   841 \multicolumn{3}{l}{$\quad l_{wbegin}\;$ \textcolor{black}{(fresh label)}}\\
       
   842 \multicolumn{3}{l}{$\quad l_{wend}\;$ \textcolor{black}{(fresh label)}}\\
       
   843 \multicolumn{3}{l}{$\quad (is, E') = \text{compile}(cs_1, E)$}\\
       
   844 \multicolumn{3}{l}{$\quad(l_{wbegin}:$}\\
       
   845 \multicolumn{3}{l}{$\quad\phantom{(}@\;\text{compile}(b, E, l_{wend})$}\\
       
   846 \multicolumn{3}{l}{$\quad\phantom{(}@\;is$}\\
       
   847 \multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{wbegin}$}\\
       
   848 \multicolumn{3}{l}{$\quad\phantom{(}@\;l_{wend}:, E')$}\\
       
   849 \end{tabular}}
       
   850 \end{center}
       
   851 
       
   852 \end{frame}}
       
   853 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
       
   854 
       
   855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   496 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   856 \mode<presentation>{
   497 \mode<presentation>{
   857 \begin{frame}[t]
   498 \begin{frame}[t]
   858 \frametitle{\begin{tabular}{c}Compiling Writes\end{tabular}}
   499 \frametitle{\begin{tabular}{c}Compiling Writes\end{tabular}}
   859 
   500 
   907 \end{center}
   548 \end{center}
   908 
   549 
   909 \end{frame}}
   550 \end{frame}}
   910 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
   551 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
   911 
   552 
   912 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   913 \mode<presentation>{
       
   914 \begin{frame}[c]
       
   915 \frametitle{\begin{tabular}{c}Next Compiler Phases\end{tabular}}
       
   916 
       
   917 \begin{itemize}
       
   918 \item assembly $\Rightarrow$ byte code (class file)
       
   919 \item labels $\Rightarrow$ absolute or relative jumps\bigskip\bigskip
       
   920 \item \texttt{javap} is a disassembler for class files
       
   921 \end{itemize}
       
   922 
       
   923 \end{frame}}
       
   924 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
       
   925 
       
   926 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   927 \mode<presentation>{
       
   928 \begin{frame}[t]
       
   929 \frametitle{\begin{tabular}{c}Compiled Code\end{tabular}}
       
   930 
       
   931 \begin{center}
       
   932 \begin{tikzpicture}
       
   933 \begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small]
       
   934 \addplot+[smooth] file {compiled.data};
       
   935 \end{axis}
       
   936 \end{tikzpicture}
       
   937 \end{center}
       
   938 
       
   939 \end{frame}}
       
   940 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
       
   941 
       
   942 
       
   943 
       
   944 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   945 \mode<presentation>{
       
   946 \begin{frame}[t]
       
   947 \frametitle{\begin{tabular}{c}Compiled vs.~Interpreted Code\end{tabular}}
       
   948 
       
   949 \begin{center}
       
   950 \begin{tikzpicture}
       
   951 \begin{loglogaxis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small]
       
   952 \addplot+[smooth] file {interpreted.data};
       
   953 \addplot+[smooth] file {compiled.data};
       
   954 \end{loglogaxis}
       
   955 \end{tikzpicture}
       
   956 \end{center}
       
   957 
       
   958 \end{frame}}
       
   959 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   960 
       
   961 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   962 \mode<presentation>{
       
   963 \begin{frame}[t]
       
   964 \frametitle{\begin{tabular}{c}Compiled vs.~Interpreted Code\end{tabular}}
       
   965 
       
   966 \begin{center}
       
   967 \begin{tikzpicture}
       
   968 \begin{axis}[axis x line=bottom, axis y line=left, ylabel=secs,
       
   969     xlabel=n,
       
   970     enlargelimits=0.05,
       
   971     ybar interval=0.7, legend style=small]
       
   972 \addplot file {interpreted2.data};
       
   973 \addplot file {compiled2.data};
       
   974 %\legend{interpreted, compiled}
       
   975 \end{axis}
       
   976 \end{tikzpicture}
       
   977 \end{center}
       
   978 
       
   979 \end{frame}}
       
   980 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
       
   981 
       
   982 
       
   983 
       
   984 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   985 \mode<presentation>{
       
   986 \begin{frame}[t]
       
   987 \frametitle{\begin{tabular}{c}What Next\end{tabular}}
       
   988 
       
   989 \begin{itemize}
       
   990 \item register spilling
       
   991 \item dead code removal
       
   992 \item loop optimisations
       
   993 \item instruction selection
       
   994 \item type checking
       
   995 \item concurrency
       
   996 \item fuzzy testing
       
   997 \item verification\bigskip\\
       
   998 
       
   999 \item GCC, LLVM, tracing JITs
       
  1000 \end{itemize}
       
  1001 
       
  1002 \end{frame}}
       
  1003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
       
  1004 
       
  1005 
       
  1006 \end{document}
   553 \end{document}
  1007 
   554 
  1008 %%% Local Variables:  
   555 %%% Local Variables:  
  1009 %%% mode: latex
   556 %%% mode: latex
  1010 %%% TeX-master: t
   557 %%% TeX-master: t