slides/slides09.tex
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 29 Nov 2024 18:59:32 +0000
changeset 976 e9eac62928f5
parent 975 ae5c03560d4d
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
     1
% !TEX program = xelatex
744
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
     2
\documentclass[dvipsnames,14pt,t,xelatex,aspectratio=169,xcolor={table}]{beamer}
309
640e4a05cd9b 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: 207
diff changeset
     4
\usepackage{../langs}
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
     5
\usepackage{../data}
871
94b84d880c2b updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 864
diff changeset
     6
\usepackage{../graphicss}
379
fa2589ec0fae updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 312
diff changeset
     7
\usepackage{../grammar}
958
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
     8
%\usepackage{soul}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
     9
%\usepackage{mathpartir}
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
    10
\usetikzlibrary{shapes,arrows,shadows}
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    11
958
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    12
\usepackage[most]{tcolorbox}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    13
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    14
\newtcbox{\hl}[1][]{%
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    15
     size=fbox,
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    16
    tcbox raise base, nobeforeafter, 
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    17
    enhanced, colframe=gray,
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    18
    colback=gray!30, boxrule=1pt,
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    19
    fontupper=\ttfamily,
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    20
    #1}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    21
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    22
975
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
    23
\usepackage{tcolorbox}
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
    24
\newtcolorbox{mybox}{colback=red!5!white,colframe=red!75!black}
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
    25
\newtcolorbox{mybox2}[1]{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,title=#1}
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
    26
\newtcolorbox{mybox3}[1]{colback=Cyan!5!white,colframe=Cyan!75!black,fonttitle=\bfseries,title=#1}
958
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    27
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    28
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
    29
% beamer stuff
459
780486571e38 updated
Christian Urban <urbanc@in.tum.de>
parents: 384
diff changeset
    30
\renewcommand{\slidecaption}{CFL 09, King's College London}
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
    31
\newcommand{\bl}[1]{\textcolor{blue}{#1}}       
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
    32
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    33
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
\begin{document}
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
    35
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309
640e4a05cd9b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    37
\begin{frame}[t]
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
\frametitle{%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
  \begin{tabular}{@ {}c@ {}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
  \\[-3mm]
459
780486571e38 updated
Christian Urban <urbanc@in.tum.de>
parents: 384
diff changeset
    41
  \LARGE Compilers and \\[-2mm] 
901
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    42
  \LARGE Formal Languages\\[-3mm] 
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
  \end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
  \normalsize
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
  \begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
  \begin{tabular}{ll}
940
46eee459a999 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 901
diff changeset
    48
    Email:  & christian.urban at kcl.ac.uk\\
975
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
    49
Office Hour: & Fridays 12 -- 14\\  
901
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    50
  Location: & N7.07 (North Wing, Bush House)\\
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    51
  Slides \& Progs: & KEATS\\
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    52
  Pollev: & \texttt{\alert{https://pollev.com/cfltutoratki576}}\\  
538
17acdd516ccd updated
Christian Urban <urbanc@in.tum.de>
parents: 537
diff changeset
    53
  \end{tabular}
17acdd516ccd updated
Christian Urban <urbanc@in.tum.de>
parents: 537
diff changeset
    54
  \end{center}
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    55
744
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    56
  \begin{center}
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    57
    \begin{tikzpicture}
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    58
      \node[drop shadow,fill=white,inner sep=0pt] 
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    59
      {\footnotesize\rowcolors{1}{capri!10}{white}
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    60
        \begin{tabular}{|p{4.8cm}|p{4.8cm}|}\hline
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    61
          1 Introduction, Languages          & 6 While-Language \\
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    62
          2 Regular Expressions, Derivatives & 7 Compilation, JVM \\
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    63
          3 Automata, Regular Languages      & 8 Compiling Functional Languages \\
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    64
          4 Lexing, Tokenising               & \cellcolor{blue!50} 9 Optimisations \\
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    65
          5 Grammars, Parsing                & 10 LLVM \\ \hline
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    66
        \end{tabular}%
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    67
      };
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    68
    \end{tikzpicture}
99c5916d9a8f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 702
diff changeset
    69
  \end{center}
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
    70
\end{frame}
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
    71
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
    72
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
    73
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
    74
\begin{frame}[c,fragile]
702
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
    75
\frametitle{The Fun Language}
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
    76
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
    77
\footnotesize
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
    78
\begin{textblock}{13}(0.9,3)
864
Christian Urban <christian.urban@kcl.ac.uk>
parents: 853
diff changeset
    79
\begin{lstlisting}[numbers=none]
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
    80
def fib(n) = if n == 0 then 0 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
    81
             else if n == 1 then 1 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
    82
             else fib(n - 1) + fib(n - 2);
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
    83
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
    84
def fact(n) = if n == 0 then 1 else n * fact(n - 1);
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
    85
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
    86
def ack(m, n) = if m == 0 then n + 1
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
    87
                else if n == 0 then ack(m - 1, 1)
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
    88
                else ack(m - 1, ack(m, n - 1));
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
    89
                
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
    90
def gcd(a, b) = if b == 0 then a else gcd(b, a % b);                
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
    91
\end{lstlisting}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
    92
\end{textblock}
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
    93
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
    94
\end{frame}
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
    95
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
901
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
    96
853
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
    97
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
958
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    98
%\begin{frame}[c, fragile]
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
    99
%\frametitle{Stack Estimation}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   100
%\small
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   101
%\mbox{}\\[-15mm]%
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   102
%
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   103
%\bl{\begin{center}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   104
%\begin{tabular}{@{\hspace{-4mm}}l@{\hspace{2mm}}c@{\hspace{2mm}}l@{}}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   105
%$\textit{estimate}(n)$ & $\dn$ & $1$\\
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   106
%$\textit{estimate}(x)$ & $\dn$ & $1$\\
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   107
%$\textit{estimate}(a_1\;aop\;a_2)$ & $\dn$ &
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   108
%$\textit{estimate}(a_1) + \textit{estimate}(a_2)$\\
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   109
%$\textit{estimate}(\pcode{if}\;b\;\pcode{then}\;e_1\;\pcode{else}\;e_2)$ & $\dn$ & 
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   110
%$\textit{estimate}(b) +$\\ 
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   111
%& & $\quad max(\textit{estimate}(e_1), \textit{estimate}(e_2))$\\
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   112
%$\textit{estimate}(\pcode{write}(e))$ & $\dn$ & 
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   113
%$\textit{estimate}(e) + 1$\\
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   114
%$\textit{estimate}(e_1 ; e_2)$ & $\dn$ & 
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   115
%$max(\textit{estimate}(e_1), \textit{estimate}(e_2))$\\
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   116
%$\textit{estimate}(f(e_1, ..., e_n))$ & $\dn$ & 
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   117
%$\sum_{i = 1..n}\;estimate(e_i)$\medskip\\
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   118
%$\textit{estimate}(a_1\;bop\;a_2)$ & $\dn$ &
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   119
%$\textit{estimate}(a_1) + \textit{estimate}(a_2)$\\
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   120
%\end{tabular}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   121
%\end{center}}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   122
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   123
%\end{frame}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   124
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   125
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   126
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   127
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   128
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   129
\begin{frame}[c,fragile]
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   130
\frametitle{\mbox{}\hspace{5cm}Factorial}
901
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   131
958
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   132
\begin{textblock}{7}(0,1.6)\footnotesize
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   133
\begin{minipage}{6cm}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   134
\begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none]
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   135
.method public static fact(I)I
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   136
.limit locals 1
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   137
.limit stack 6
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   138
   iload 0
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   139
   ldc 0
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   140
   if_icmpne If_else_0
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   141
   ldc 1
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   142
   goto If_end_1
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   143
If_else_0:
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   144
   iload 0
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   145
   iload 0
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   146
   ldc 1
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   147
   isub
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   148
   invokestatic fact/fact/fact(I)I
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   149
   imul
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   150
If_end_1:
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   151
   ireturn
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   152
.end method
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   153
\end{lstlisting}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   154
\end{minipage}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   155
\end{textblock}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   156
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   157
\begin{textblock}{7}(6,7)
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   158
\begin{bubble}[7cm]\small
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   159
\begin{lstlisting}[language=Lisp,
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   160
                   basicstyle=\ttfamily, 
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   161
                   numbers=none,
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   162
                   xleftmargin=1mm,linebackgroundcolor=\color{cream}]
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   163
def fact(n) = 
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   164
  if n == 0 then 1 
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   165
  else n * fact(n - 1)
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   166
\end{lstlisting}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   167
\end{bubble}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   168
\end{textblock}
901
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   169
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   170
\end{frame}
958
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   171
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
901
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   172
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   173
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   174
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   175
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   176
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   177
853
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   178
\begin{frame}[c,fragile]
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   179
\frametitle{\mbox{}\hspace{5cm}Factorial}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   180
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   181
\begin{textblock}{7}(0,1.0)\footnotesize
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   182
\begin{minipage}{6cm}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   183
\begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none]
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   184
.method public static facT(II)I 
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   185
.limit locals 2
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   186
.limit stack 6
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   187
  iload 0
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   188
  ldc 0
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   189
  if_icmpne If_else_2
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   190
  iload 1
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   191
  goto If_end_3
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   192
If_else_2:
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   193
  iload 0
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   194
  ldc 1
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   195
  isub
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   196
  iload 0
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   197
  iload 1
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   198
  imul
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   199
  invokestatic fact/fact/facT(II)I
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   200
If_end_3:
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   201
  ireturn
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   202
.end method 
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   203
\end{lstlisting}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   204
\end{minipage}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   205
\end{textblock}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   206
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   207
\begin{textblock}{7}(6,7)
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   208
\begin{bubble}[7cm]\small
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   209
\begin{lstlisting}[language=Lisp,
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   210
                   basicstyle=\ttfamily, 
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   211
                   numbers=none,
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   212
                   xleftmargin=1mm,linebackgroundcolor=\color{cream}]
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   213
def facT(n, acc) = 
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   214
  if n == 0 then acc 
958
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   215
  else facT(n - 1, n * acc)
853
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   216
\end{lstlisting}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   217
\end{bubble}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   218
\end{textblock}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   219
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   220
\end{frame}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   221
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   222
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   223
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   224
\begin{frame}[fragile]
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   225
958
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   226
\begin{textblock}{7}(1,-0.38)\footnotesize
853
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   227
\begin{minipage}{6cm}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   228
\begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none, escapeinside={(*@}{@*)}]
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   229
.method public static facT(II)I 
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   230
.limit locals 2
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   231
.limit stack 6
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   232
(*@\hl{facT\_Start:} @*)
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   233
  iload 0
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   234
  ldc 0
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   235
  if_icmpne If_else_2
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   236
  iload 1
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   237
  goto If_end_3
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   238
If_else_2:
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   239
  iload 0
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   240
  ldc 1
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   241
  isub
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   242
  iload 0
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   243
  iload 1
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   244
  imul
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   245
  (*@\hl{istore 1} @*)
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   246
  (*@\hl{istore 0} @*)
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   247
  (*@\hl{goto facT\_Start} @*)
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   248
If_end_3:
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   249
  ireturn
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   250
.end method 
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   251
\end{lstlisting}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   252
\end{minipage}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   253
\end{textblock}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   254
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   255
\begin{textblock}{7}(6,7)
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   256
\begin{bubble}[7cm]\small
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   257
\begin{lstlisting}[language=Lisp,
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   258
                   basicstyle=\ttfamily, 
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   259
                   numbers=none,
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   260
                   xleftmargin=1mm,linebackgroundcolor=\color{cream}]
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   261
def facT(n, acc) = 
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   262
  if n == 0 then acc 
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   263
  else facT(n - 1, n * acc);
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   264
\end{lstlisting}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   265
\end{bubble}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   266
\end{textblock}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   267
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   268
\end{frame}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   269
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   270
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   271
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   272
\begin{frame}[t, fragile]
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   273
\frametitle{Tail Recursion}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   274
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   275
A call to \texttt{f(args)} is usually compiled as\medskip
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   276
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   277
{\small\begin{lstlisting}[basicstyle=\ttfamily, numbers=none]
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   278
  args onto stack
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   279
  invokestatic  .../f 
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   280
\end{lstlisting}}\pause
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   281
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   282
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   283
A call is in tail position provided:\medskip
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   284
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   285
{\small\begin{itemize}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   286
\item \texttt{if Bexp then \hl{Exp} else \hl{Exp}}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   287
\item \texttt{Exp ; \hl{Exp}}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   288
\item \texttt{Exp  op Exp}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   289
\end{itemize}}\medskip
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   290
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   291
then a call \texttt{f(args)} can be compiled as\medskip\small
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   292
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   293
\begin{lstlisting}[numbers=none]
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   294
  prepare environment
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   295
  jump to start of function
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   296
\end{lstlisting}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   297
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   298
\end{frame}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   299
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   300
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   301
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   302
\begin{frame}[c, fragile]
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   303
\frametitle{Tail Recursive Call}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   304
\footnotesize
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   305
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   306
\begin{textblock}{13}(-0.3,3)
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   307
\begin{lstlisting}[language=Scala, numbers=none]
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   308
def compile_expT(a: Exp, env: Mem, name: String): Instrs = 
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   309
  ...
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   310
  case Call(n, args) => if (name == n)
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   311
  {
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   312
    val stores =
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   313
      args.zipWithIndex.map { case (x, y) => i"istore $y" } 
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   314
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   315
    args.map(a => compile_expT(a, env, "")).mkString ++
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   316
    stores.reverse.mkString ++ 
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   317
    i"goto ${n}_Start" 
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   318
  } else {
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   319
    val is = "I" * args.length
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   320
    args.map(a => compile_expT(a, env, "")).mkString ++
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   321
    i"invokestatic XXX/XXX/${n}(${is})I"
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   322
  }
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   323
\end{lstlisting}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   324
\end{textblock}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   325
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   326
\end{frame}
568671822d52 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 822
diff changeset
   327
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   328
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   329
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
958
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   330
\begin{frame}[c]
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   331
\frametitle{???}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   332
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   333
\small
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   334
\begin{tabular}{cc}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   335
  \includegraphics[scale=0.2]{basic-code.jpg} &
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   336
  \includegraphics[scale=0.2]{machine-code.jpg}                                
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   337
\end{tabular}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   338
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   339
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   340
\end{frame}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   341
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   342
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   343
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   344
\begin{frame}[t]
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   345
\frametitle{Opcodes}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   346
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   347
\small
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   348
\begin{tabular}{cc}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   349
  \includegraphics[scale=0.3]{machine-code-large.png}      
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   350
\end{tabular}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   351
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   352
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   353
\end{frame}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   354
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   355
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   356
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   357
\begin{frame}<1-2>[t]
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   358
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   359
\end{frame}
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   360
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   361
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   362
fddf099a82f8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 940
diff changeset
   363
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   364
\begin{frame}[c,fragile]
901
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   365
\frametitle{Peephole Optimisations}
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   366
901
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   367
\begin{center}
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   368
\begin{tabular}{ll}
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   369
  \texttt{ldc}:  & \texttt{iconst\_0} \ldots \texttt{iconst\_5}\\
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   370
                 & \texttt{bipush} $n$ where $-128 < n <= 128$\bigskip\\  
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   371
  \texttt{iload}: &  \texttt{iload\_0} \ldots \texttt{iload\_3}\bigskip\\
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   372
  \texttt{istore}: &  \texttt{istore\_0} \ldots \texttt{istore\_3}\\
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   373
\end{tabular}
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   374
\end{center}  
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   375
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   376
\end{frame}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   377
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   378
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   379
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   380
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
901
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   381
%\begin{frame}[c,fragile]
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   382
%\frametitle{Factorial Funct.~on the JVM}
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   383
%
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   384
%\begin{textblock}{7}(1,1.8)\footnotesize
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   385
%\begin{minipage}{6cm}
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   386
%\begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none]
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   387
%.method public static facT(II)I 
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   388
%.limit locals 2
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   389
%.limit stack 6
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   390
%  iload 0
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   391
%  ldc 0
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   392
%  if_icmpne If_else_2
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   393
%  iload 1
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   394
%  goto If_end_3
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   395
%If_else_2:
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   396
%  iload 0
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   397
%  ldc 1
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   398
%  isub
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   399
%  iload 0
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   400
%  iload 1
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   401
%  imul
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   402
%  invokestatic fact/fact/facT(II)I
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   403
%If_end_3:
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   404
%  ireturn
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   405
%.end method 
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   406
%\end{lstlisting}
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   407
%\end{minipage}
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   408
%\end{textblock}
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   409
%
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   410
%\begin{textblock}{7}(6,7)
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   411
%\begin{bubble}[7cm]\small
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   412
%\begin{lstlisting}[language=Lisp,
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   413
%                   basicstyle=\ttfamily, 
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   414
%                   numbers=none,
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   415
%                   xleftmargin=1mm,linebackgroundcolor=\color{cream}]
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   416
%def facT(n, acc) = 
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   417
%  if n == 0 then acc 
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   418
%  else facT(n - 1, n * acc);
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   419
%\end{lstlisting}
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   420
%\end{bubble}
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   421
%\end{textblock}
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   422
%
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   423
%\end{frame}
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   424
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   425
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   426
33cff35bdc1a updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 871
diff changeset
   427
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   428
\begin{frame}[fragile,c]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   429
\frametitle{LLVM}
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   430
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   431
\begin{itemize}
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   432
  \item Chris Lattner, Vikram Adve (started in 2000)
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   433
  \item Apple hired Lattner in 2006
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   434
  \item modular architecture, LLVM-IR
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   435
  \item \texttt{lli} and \texttt{llc} 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   436
\end{itemize}
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   437
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   438
\end{frame}
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   439
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   440
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   441
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   442
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   443
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   444
\tikzstyle{sensor}=[draw, fill=blue!20, text width=3.8em, line width=1mm,
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   445
    text centered, minimum height=2em,drop shadow]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   446
\tikzstyle{ann} = [above, text width=4em, text centered]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   447
\tikzstyle{sc} = [sensor, text width=7em, fill=red!20, 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   448
    minimum height=6em, rounded corners, drop shadow,line width=1mm]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   449
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   450
\begin{frame}[fragile,c]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   451
\frametitle{LLVM: Overview}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   452
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   453
\begin{tikzpicture}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   454
    % Validation Layer is the same except that there are a set of nodes and links which are added
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   455
   
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   456
    \path (0,0) node (IR) [sc] {\textbf{LLVM-IR}\\ Optimisations};
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   457
    \path (IR.west)+(-2.2,1.7) node (sou1) [sensor] {C++};
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   458
    \path (IR.west)+(-2.2,0.5) node (sou2)[sensor] {C};
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   459
    \path (IR.west)+(-2.2,-1.0) node (dots)[ann] {$\vdots$}; 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   460
    \path (IR.west)+(-2.2,-1.8) node (sou3)[sensor] {Haskell};    
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   461
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   462
    \path [draw,->,line width=1mm] (sou1.east) -- node [above] {} (IR.160);
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   463
    \path [draw,->,line width=1mm] (sou2.east) -- node [above] {} (IR.180);
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   464
    \path [draw,->,line width=1mm] (sou3.east) -- node [above] {} (IR.200);
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   465
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   466
    \path (IR.east)+(2.2,2.0)  node (tar1)[sensor] {x86};
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   467
    \path (IR.east)+(2.2,0.8)  node (tar2)[sensor] {ARM};
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   468
    \path (IR.east)+(2.2,-0.4) node (tar3)[sensor] {MIPS}; 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   469
    \path (IR.east)+(2.2,-1.6) node (tar4)[sensor] {RISC}; 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   470
    \path (IR.east)+(2.2,-2.8) node (tar5)[sensor] {Power PC};
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   471
    \path (IR.east)+(2.2,-4.2) node (dots2)[ann] {$\vdots$};
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   472
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   473
    \path [draw,<-,line width=1mm] (tar1.west) -- node [above] {} (IR.10);
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   474
    \path [draw,<-,line width=1mm] (tar2.west) -- node [above] {} (IR.5);
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   475
    \path [draw,<-,line width=1mm] (tar3.west) -- node [above] {} (IR.0);
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   476
    \path [draw,<-,line width=1mm] (tar4.west) -- node [above] {} (IR.-5);
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   477
    \path [draw,<-,line width=1mm] (tar5.west) -- node [above] {} (IR.-10);
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   478
    
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   479
\end{tikzpicture}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   480
\end{frame}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   481
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   482
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   483
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   484
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   485
\begin{frame}[fragile,t]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   486
\frametitle{LLVM-IR}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   487
\small
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   488
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   489
\begin{textblock}{7.7}(8,11.4)
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   490
\begin{bubble}[5cm]\small
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   491
\begin{lstlisting}[language=Lisp,
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   492
                   numbers=none,
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   493
                   xleftmargin=1mm,linebackgroundcolor=\color{cream}]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   494
def fact(n) =
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   495
  if n == 0 then 1 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   496
  else n * fact(n - 1)
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   497
\end{lstlisting}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   498
\end{bubble}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   499
\end{textblock}
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   500
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   501
\begin{lstlisting}[language=LLVM,xleftmargin=-7mm]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   502
define i32 @fact (i32 %n) {
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   503
   %tmp_19 = icmp eq i32  %n, 0
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   504
   br i1 %tmp_19, label %if_br_23, label %else_br_24
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   505
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   506
if_br_23:
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   507
   ret i32 1
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   508
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   509
else_br_24:
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   510
   %tmp_21 = sub i32  %n, 1
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   511
   %tmp_22 = call i32 @fact (i32 %tmp_21)
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   512
   %tmp_20 = mul i32  %n, %tmp_22
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   513
   ret i32 %tmp_20
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   514
}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   515
\end{lstlisting}
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   516
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   517
\end{frame}
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   518
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   519
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   520
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   521
\begin{frame}[fragile,c]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   522
\frametitle{LLVM Types}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   523
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   524
\tt
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   525
\begin{center}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   526
\begin{tabular}{ll}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   527
boolean & i1 \\
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   528
byte    & i8 \\
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   529
short   & i16\\
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   530
char    & i16\\
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   531
integer & i32\\
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   532
long    & i64\\
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   533
float   & float\\
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   534
double  & double\\
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   535
*\_      & pointer to \\
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   536
**\_     & pointer to a pointer to\\
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   537
\mbox{}[\_]    & arrays of\\
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   538
\end{tabular}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   539
\end{center}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   540
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   541
\end{frame}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   542
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   543
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   544
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   545
\begin{frame}[fragile,c]
702
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   546
\frametitle{LLVM-IR Instructions}
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   547
\small
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   548
702
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   549
\begin{lstlisting}[language=LLVM,xleftmargin=0mm]
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   550
br i1 %var, label %if_br, label %else_br
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   551
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   552
icmp eq i32  %x, %y     ; for equal
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   553
icmp sle i32 %x, %y     ;   signed less or equal
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   554
icmp slt i32 %x, %y     ;   signed less than
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   555
icmp ult i32 %x, %y     ;   unsigned less than 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   556
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   557
%var = call i32 @foo(...args...)
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   558
\end{lstlisting}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   559
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   560
\end{frame}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   561
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   562
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   563
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   564
\begin{frame}[fragile,c]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   565
\frametitle{SSA Format}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   566
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   567
\bl{$(1 + a) + (3 + (b * 5))$}\bigskip\bigskip
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   568
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   569
\begin{lstlisting}[language=LLVM]
702
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   570
tmp0 = add 1 a   
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   571
tmp1 = mul b 5 
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   572
tmp2 = add 3 tmp1 
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   573
tmp3 = add tmp0 tmp2  
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   574
\end{lstlisting}\bigskip\bigskip
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   575
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   576
\hfill Static Single Assignment
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   577
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   578
\end{frame}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   579
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   580
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   581
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   582
\begin{frame}[fragile,c]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   583
\frametitle{Abstract Syntax Trees}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   584
\footnotesize
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   585
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   586
\begin{lstlisting}[language=Scala,numbers=none,xleftmargin=-3mm]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   587
// Fun language (expressions)
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   588
abstract class Exp 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   589
abstract class BExp 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   590
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   591
case class Call(name: String, args: List[Exp]) extends Exp
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   592
case class If(a: BExp, e1: Exp, e2: Exp) extends Exp
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   593
case class Write(e: Exp) extends Exp
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   594
case class Var(s: String) extends Exp
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   595
case class Num(i: Int) extends Exp
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   596
case class Aop(o: String, a1: Exp, a2: Exp) extends Exp
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   597
case class Sequence(e1: Exp, e2: Exp) extends Exp
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   598
case class Bop(o: String, a1: Exp, a2: Exp) extends BExp  
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   599
\end{lstlisting}
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   600
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   601
\end{frame}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   602
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   603
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   604
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   605
\begin{frame}[fragile,c]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   606
\frametitle{K-(Intermediate)Language}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   607
\footnotesize
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   608
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   609
\begin{lstlisting}[language=Scala,numbers=none,xleftmargin=-3mm]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   610
abstract class KExp
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   611
abstract class KVal
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   612
702
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   613
// K-Values
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   614
case class KVar(s: String) extends KVal
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   615
case class KNum(i: Int) extends KVal
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   616
case class Kop(o: String, v1: KVal, v2: KVal) extends KVal
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   617
case class KCall(o: String, vrs: List[KVal]) extends KVal
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   618
case class KWrite(v: KVal) extends KVal
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   619
702
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   620
// K-Expressions
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   621
case class KIf(x1: String, e1: KExp, e2: KExp) extends KExp
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   622
case class KLet(x: String, v: KVal, e: KExp) extends KExp
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   623
case class KReturn(v: KVal) extends KExp
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   624
\end{lstlisting}
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   625
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   626
\end{frame}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   627
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   628
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   629
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   630
\begin{frame}[fragile,c]
819
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   631
\frametitle{KLet}
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   632
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   633
\begin{lstlisting}[language=LLVM]
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   634
tmp0 = add 1 a   
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   635
tmp1 = mul b 5 
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   636
tmp2 = add 3 tmp1 
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   637
tmp3 = add tmp0 tmp2  
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   638
\end{lstlisting}
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   639
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   640
\begin{lstlisting}[language=LLVMIR]
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   641
  KLet tmp0 , add 1 a in  
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   642
   KLet tmp1 , mul b 5 in
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   643
    KLet tmp2 , add 3 tmp1 in 
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   644
     KLet tmp3 , add tmp0 tmp2 in
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   645
      ...
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   646
\end{lstlisting}
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   647
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   648
\begin{lstlisting}[language=Scala,numbers=none]
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   649
case class KLet(x: String, e1: KVal, e2: KExp)
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   650
\end{lstlisting}
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   651
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   652
\end{frame}
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   653
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   654
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   655
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   656
\begin{frame}[fragile,c]
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   657
\frametitle{KLet}
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   658
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   659
\begin{lstlisting}[language=LLVM]
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   660
tmp0 = add 1 a   
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   661
tmp1 = mul b 5 
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   662
tmp2 = add 3 tmp1 
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   663
tmp3 = add tmp0 tmp2  
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   664
\end{lstlisting}
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   665
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   666
\begin{lstlisting}[language=LLVMIR]
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   667
  let tmp0 = add 1 a in  
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   668
   let tmp1 = mul b 5 in
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   669
    let tmp2 = add 3 tmp1 in 
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   670
     let tmp3 = add tmp0 tmp2 in
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   671
      ...
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   672
\end{lstlisting}
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   673
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   674
\begin{lstlisting}[language=Scala,numbers=none]
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   675
case class KLet(x: String, e1: KVal, e2: KExp)
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   676
\end{lstlisting}
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   677
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   678
\end{frame}
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   679
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   680
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   681
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   682
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   683
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fd88a0656164 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 744
diff changeset
   684
\begin{frame}[fragile,c]
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   685
\frametitle{CPS-Translation}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   686
\small
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   687
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   688
\begin{lstlisting}[language=Scala,numbers=none]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   689
def CPS(e: Exp)(k: KVal => KExp) : KExp = 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   690
  e match { ... }
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   691
\end{lstlisting}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   692
\bigskip\bigskip
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   693
702
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   694
the continuation \texttt{k} can be thought of:\medskip
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   695
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   696
\small
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   697
\begin{lstlisting}[language=LLVMIR,numbers=none,xleftmargin=30mm,escapeinside={(*@}{@*)}]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   698
let tmp0 = add 1 a in   
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   699
let tmp1 = mul (*@$\Box$@*) 5 in 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   700
let tmp2 = add 3 tmp1 in 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   701
let tmp3 = add tmp0 tmp2 in
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   702
  KReturn tmp3 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   703
\end{lstlisting}
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   704
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   705
\end{frame}
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   706
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   707
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   708
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   709
\begin{frame}[fragile,c]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   710
\frametitle{CPS-Translation}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   711
\small
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   712
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   713
\begin{lstlisting}[language=Scala,numbers=none]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   714
def CPS(e: Exp)(k: KVal => KExp) : KExp = 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   715
  e match { 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   716
     case Var(s) => k(KVar(s)) 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   717
     case Num(i) => k(KNum(i))
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   718
     ...
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   719
  }
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   720
\end{lstlisting}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   721
\bigskip\bigskip
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   722
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   723
\small
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   724
\begin{lstlisting}[language=LLVMIR,numbers=none,xleftmargin=30mm,escapeinside={(*@}{@*)}]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   725
let tmp0 = add 1 a in   
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   726
let tmp1 = mul (*@$\Box$@*) 5 in 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   727
let tmp2 = add 3 tmp1 in 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   728
let tmp3 = add tmp0 tmp2 in
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   729
  KReturn tmp3 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   730
\end{lstlisting}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   731
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   732
\end{frame}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   733
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   734
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   735
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   736
\begin{frame}[fragile,c]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   737
\frametitle{CPS-Translation}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   738
\small
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   739
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   740
\begin{lstlisting}[language=Scala,numbers=none,xleftmargin=-5mm]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   741
def CPS(e: Exp)(k: KVal => KExp) : KExp = e match { 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   742
  case Aop(o, e1, e2) => {
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   743
    val z = Fresh("tmp")
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   744
    CPS(e1)(y1 => 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   745
      CPS(e2)(y2 => 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   746
               KLet(z, Kop(o, y1, y2), k(KVar(z)))))
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   747
  } ...
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   748
}
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   749
\end{lstlisting}
702
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   750
\mbox{}\\[-8mm]%
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   751
%
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   752
\begin{lstlisting}[language=LLVMIR,numbers=none,xleftmargin=30mm,escapeinside={(*@}{@*)}]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   753
...
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   754
let z = op (*@$\Box_{y_1}$@*) (*@$\Box_{y_2}$@*)
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   755
let tmp0 = add 1 a in   
702
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   756
let tmp1 = mul (*@$\Box\!\!\!\!\raisebox{0.6mm}{\alert{\texttt{z}}}$@*) 5 in 
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   757
let tmp2 = add 3 tmp1 in 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   758
let tmp3 = add tmp0 tmp2 in
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   759
  KReturn tmp3 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   760
\end{lstlisting}
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   761
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   762
\end{frame}
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   763
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   764
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   765
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   766
\begin{frame}[fragile,c]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   767
\frametitle{CPS-Translation}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   768
\small
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   769
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   770
\begin{lstlisting}[language=Scala,numbers=none]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   771
def CPS(e: Exp)(k: KVal => KExp) : KExp = 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   772
  e match { 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   773
    case Sequence(e1, e2) => 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   774
      CPS(e1)(_ => CPS(e2)(y2 => k(y2)))
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   775
     ...
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   776
  }
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   777
\end{lstlisting}
702
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   778
\bigskip
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   779
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   780
\small
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   781
\begin{lstlisting}[language=LLVMIR,numbers=none,xleftmargin=30mm,escapeinside={(*@}{@*)}]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   782
let tmp0 = add 1 a in   
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   783
let tmp1 = mul (*@$\Box$@*) 5 in 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   784
let tmp2 = add 3 tmp1 in 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   785
let tmp3 = add tmp0 tmp2 in
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   786
  KReturn tmp3 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   787
\end{lstlisting}
609
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   788
e33545bb2eba updated
Christian Urban <urbanc@in.tum.de>
parents: 538
diff changeset
   789
\end{frame}
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   790
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   791
610
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   792
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   793
\begin{frame}[fragile,c]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   794
\frametitle{CPS-Translation}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   795
\small
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   796
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   797
\begin{lstlisting}[language=Scala,numbers=none,xleftmargin=-3mm]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   798
def CPS(e: Exp)(k: KVal => KExp) : KExp = 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   799
  e match { 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   800
    ...
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   801
    case If(Bop(o, b1, b2), e1, e2) => {
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   802
      val z = Fresh("tmp")
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   803
      CPS(b1)(y1 => 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   804
        CPS(b2)(y2 => 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   805
          KLet(z, Kop(o, y1, y2), 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   806
                KIf(z, CPS(e1)(k), CPS(e2)(k)))))
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   807
     }
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   808
    ...
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   809
  }
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   810
\end{lstlisting}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   811
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   812
\end{frame}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   813
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   814
702
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   815
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   816
\begin{frame}[c,fragile]
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   817
\frametitle{The Basic Language, 1980+}
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   818
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   819
\begin{lstlisting}[language={[Visual]Basic},numbers=none]
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   820
 5 LET S = 0
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   821
10 INPUT V 
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   822
20 PRINT "Input number"
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   823
30 IF N = 0 THEN GOTO 99 
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   824
40 FOR I = 1 TO N 
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   825
45 LET S = S + V(I) 
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   826
50 NEXT I 
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   827
60 PRINT S/N 
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   828
70 GOTO 5 
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   829
99 END
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   830
\end{lstlisting}
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   831
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   832
\hfill ``Spaghetti Code''
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   833
\end{frame}
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   834
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   835
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   836
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   837
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   838
\begin{frame}[c,fragile]
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   839
\frametitle{Target Specific ASM}
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   840
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   841
\begin{lstlisting}[language={},numbers=none]
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   842
llc -march=x86-64 fact.ll 
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   843
llc -march=arm fact.ll
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   844
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   845
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   846
Intel:  xorl  %eax, %eax
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   847
ARM:    mov   pc, lr
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   848
\end{lstlisting}
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   849
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   850
\end{frame}
39e21a33ffb0 updated
Christian Urban <urbanc@in.tum.de>
parents: 701
diff changeset
   851
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   852
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   853
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   854
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   855
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
610
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   856
\begin{frame}[c]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   857
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   858
\large\bf
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   859
Using a compiler, \\
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   860
how can you mount the\\ 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   861
perfect attack against a system?
610
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   862
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
   863
\end{frame}
610
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   864
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   865
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   866
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   867
\mode<presentation>{
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   868
\begin{frame}[c]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   869
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   870
{\large\bf
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   871
What is a \alert{perfect} attack?}\bigskip
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   872
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   873
\begin{enumerate}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   874
\item you can potentially completely take over a target system
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   875
\item your attack is (nearly) undetectable
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   876
\item the victim has (almost) no chance to recover
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   877
\end{enumerate}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   878
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   879
\end{frame}}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   880
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   881
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   882
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   883
\mode<presentation>{
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   884
\begin{frame}[c]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   885
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   886
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   887
  \begin{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   888
  \begin{tikzpicture}[scale=1]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   889
  
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   890
  \onslide<1->{
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   891
  \node (A) at (0,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=17mm] {};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   892
  \node [below right] at (A.north west) {\footnotesize\begin{tabular}{@{}l@{}}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   893
  \only<1,2>{clean}\only<3->{\alert{hacked}}\\compiler\end{tabular}};}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   894
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   895
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   896
  \onslide<2->{
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   897
  \node (B) at (-2,2)  [draw=black, rectangle, very thick, minimum height=10mm, minimum width=12mm] {};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   898
  \node [below right] at (B.north west) {\footnotesize\begin{tabular}{@{}l@{}}login\\(src)\end{tabular}};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   899
  
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   900
  \node (C) at (2,2)  [draw=black, rectangle, very thick, minimum height=10mm, minimum width=12mm] {};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   901
  \node [below right] at (C.north west) {\footnotesize\begin{tabular}{@{}l@{}}login\\(bin)\end{tabular}};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   902
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   903
  \draw[->, line width=2mm] (B) -- (C);
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   904
  }
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   905
  
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   906
 \onslide<3->{\node [above left=-1.5mm] at (C.south east) {\footnotesize \alert{$\blacksquare$}};}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   907
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   908
  \end{tikzpicture}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   909
  \end{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   910
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   911
\end{frame}}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   912
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   913
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   914
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   915
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   916
\mode<presentation>{
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   917
\begin{frame}[c]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   918
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   919
  \begin{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   920
  \begin{tikzpicture}[scale=1]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   921
  
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   922
  \onslide<1->{
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   923
  \node (A) at (0,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   924
  \node [below right] at (A.north west) {\small V0.01};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   925
  \node [below right] (A1) at (A.south west) {\small Scala};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   926
  \node [below right] (A1) at (A1.south west) {\small\textcolor{gray}{host language}};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   927
  \node [above right] at (A.north west) {my compiler (src)};}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   928
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   929
  \onslide<2->{
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   930
  \node (B) at (1.8,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   931
  \node [below right] at (B.north west) {\small V0.02};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   932
  \node [below right] at (B.south west) {\small Scala};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   933
  \node at (3,0) {\ldots};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   934
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   935
  \node (C) at (5,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   936
  \node [below right] at (C.north west) {\small V1.00};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   937
  \node [below right] at (C.south west) {\small Scala};}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   938
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   939
  \onslide<3->{
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   940
  \node (D) at (6.8,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   941
  \node [below right] at (D.north west) {\small V1.00};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   942
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   943
  \node (E) at (6.8,2)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   944
  \node [below right] at (E.north west) {\small V1.01};}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   945
  
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   946
  \onslide<4->{
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   947
  \node (F) at (8.6,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   948
  \node [below right] at (F.north west) {\small V1.01};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   949
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   950
  \node (G) at (8.6,2)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   951
  \node [below right] at (G.north west) {\small V1.02};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   952
  \node at (9.8,0) {\ldots};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   953
  \node at (9.8,2) {\ldots};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   954
  \node at (8,-2) {\textcolor{gray}{\begin{tabular}{@{}l@{}}no host language\\needed\end{tabular}}};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   955
  }
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   956
  
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   957
  \end{tikzpicture}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   958
  \end{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   959
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   960
\end{frame}}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   961
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   962
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   963
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   964
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   965
  \mode<presentation>{
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   966
  \begin{frame}<1-3>
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   967
  \frametitle{\LARGE\begin{tabular}{c}Hacking Compilers 
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   968
  \end{tabular}}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   969
  
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   970
  %Why is it so paramount to have a small trusted code base (TCB)?
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   971
  \bigskip\bigskip
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   972
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   973
  \begin{columns}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   974
  \begin{column}{2.7cm}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   975
  \begin{minipage}{2.5cm}%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   976
  \begin{tabular}{c@ {}}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   977
  \includegraphics[scale=0.2]{../pics/ken-thompson.jpg}\\[-1.8mm]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   978
  \footnotesize Ken Thompson\\[-1.8mm]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   979
  \footnotesize Turing Award, 1983\\
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   980
  \end{tabular}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   981
  \end{minipage}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   982
  \end{column}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   983
  \begin{column}{9cm}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   984
  \begin{tabular}{l@ {\hspace{1mm}}p{8cm}}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   985
 
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   986
  & Ken Thompson showed how to hide a Trojan Horse in a 
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   987
  compiler \textcolor{red}{without} leaving any traces in the source code.\\[2mm]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   988
  
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   989
  & No amount of source level verification will protect 
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   990
  you from such Thompson-hacks.\\[2mm]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   991
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   992
  \end{tabular}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   993
  \end{column}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   994
  \end{columns}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   995
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   996
  \only<2>{
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   997
  \begin{textblock}{6}(4,2)
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   998
  \begin{tikzpicture}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
   999
  \draw (0,0) node[inner sep=3mm,fill=cream, ultra thick, draw=red, rounded corners=2mm] 
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1000
  {\normalsize
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1001
  \begin{minipage}{8cm}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1002
  \begin{quote}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1003
  \includegraphics[scale=0.05]{../pics/evil.png}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1004
  \begin{enumerate}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1005
  \item[1)] Assume you ship the compiler as binary and also with sources.
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1006
  \item[2)] Make the compiler aware when it compiles itself.
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1007
  \item[3)] Add the Trojan horse.
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1008
  \item[4)] Compile.
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1009
  \item[5)] Delete Trojan horse from the sources of the compiler.
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1010
  \item[6)] Go on holiday for the rest of your life. ;o)\\[-7mm]\mbox{}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1011
  \end{enumerate}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1012
  \end{quote}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1013
  \end{minipage}};
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1014
  \end{tikzpicture}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1015
  \end{textblock}}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1016
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1017
  \end{frame}}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1018
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1019
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1020
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1021
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1022
  \begin{frame}[c]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1023
  \frametitle{Dijkstra on Testing}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1024
  
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1025
  \begin{bubble}[10cm]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1026
  ``Program testing can be a very effective way to show the
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1027
  presence of bugs, but it is hopelessly inadequate for showing
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1028
  their absence.''
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1029
  \end{bubble}\bigskip
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1030
  
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1031
  \small
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1032
  What is good about compilers: the either seem to work,
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1033
  or go horribly wrong (most of the time).
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1034
  
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1035
  \end{frame}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1036
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1037
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1038
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1039
\begin{frame}[c]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1040
\frametitle{\Large Proving Programs to be Correct}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1041
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1042
\begin{bubble}[10cm]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1043
\small
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1044
{\bf Theorem:} There are infinitely many prime 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1045
numbers.\medskip\\
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1046
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1047
{\bf Proof} \ldots\\
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1048
\end{bubble}\bigskip
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1049
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1050
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1051
similarly\bigskip
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1052
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1053
\begin{bubble}[10cm]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1054
\small
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1055
{\bf Theorem:} The program is doing what 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1056
it is supposed to be doing.\medskip
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1057
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1058
{\bf Long, long proof} \ldots\\
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1059
\end{bubble}\bigskip\medskip
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1060
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1061
\small This can be a gigantic proof. The only hope is to have
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1062
help from the computer. `Program' is here to be understood to be
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1063
quite general (compiler, OS, \ldots).
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1064
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1065
\end{frame}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1066
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1067
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1068
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1069
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1070
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1071
\begin{frame}[c]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1072
\frametitle{Can This Be Done?}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1073
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1074
\begin{itemize}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1075
\item in 2008, verification of a small C-compiler
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1076
\begin{itemize}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1077
\item ``if my input program has a certain behaviour, then the compiled machine code has the same behaviour''
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1078
\item is as good as \texttt{gcc -O1}, but much, much less buggy 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1079
\end{itemize}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1080
\end{itemize}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1081
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1082
\begin{center}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1083
  \includegraphics[scale=0.12]{../pics/compcert.png}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1084
\end{center}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1085
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1086
\end{frame}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1087
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1088
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1089
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1090
\begin{frame}[t]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1091
\frametitle{Fuzzy Testing C-Compilers}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1092
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1093
\begin{itemize}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1094
\item tested GCC, LLVM and others by randomly generating 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1095
C-programs
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1096
\item found more than 300 bugs in GCC and also
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1097
many in LLVM (some of them highest-level critical)\bigskip
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1098
\item about CompCert:
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1099
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1100
\begin{bubble}[10.7cm]\small ``The striking thing about our CompCert
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1101
results is that the middle-end bugs we found in all other
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1102
compilers are absent. As of early 2011, the under-development
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1103
version of CompCert is the only compiler we have tested for
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1104
which Csmith cannot find wrong-code errors. This is not for
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1105
lack of trying: we have devoted about six CPU-years to the
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1106
task.'' 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1107
\end{bubble} 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1108
\end{itemize}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1109
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1110
\end{frame}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1111
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1112
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1113
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1114
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1115
\begin{frame}[c]
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1116
\frametitle{Next Week}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1117
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1118
\begin{itemize}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1119
\item Revision Lecture\medskip
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1120
\item How many  strings are in $\bl{L(a^*)}$?\pause\medskip
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1121
\item How many  strings are in $\bl{L((a + b)^*)}$?\\ Are there more than
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1122
  in $\bl{L(a^*)}$?
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1123
\end{itemize}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1124
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1125
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1126
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1127
\end{frame}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1128
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1129
822
6b06aeb192ea updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 819
diff changeset
  1130
\begin{frame}<1-20>[c]
6b06aeb192ea updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 819
diff changeset
  1131
\end{frame}
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1132
975
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1133
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1134
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1135
\begin{frame}[c]
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1136
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1137
\begin{mybox3}{Random Email}\it
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1138
  I would like to ask a question regarding CW4. When I run my file, I
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1139
  can see the output display in fib.j but I'm receiving the
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1140
  Java.lang.Verifyerror. What might be causing this error?
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1141
\end{mybox3}
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1142
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1143
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1144
\begin{textblock}{7}(0.5,14)
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1145
\begin{minipage}{14cm}\small
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1146
Error: Unable to initialize main class fib.fib
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1147
Caused by: java.lang.VerifyError: (class: fib/fib, method: main signature: ([Ljava/lang/String;)V) Illegal type in constant pool
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1148
\end{minipage}
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1149
\end{textblock}
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1150
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1151
\end{frame}
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1152
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1153
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1154
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1155
\begin{frame}[c]
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1156
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1157
\begin{textblock}{8}(1,4)
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1158
\begin{minipage}{14cm}
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1159
\bf\huge\textcolor{red}{Send some running code!!!!!}
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1160
\end{minipage}
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1161
\end{textblock}
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1162
  
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1163
\end{frame}
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1164
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1165
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1166
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1167
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1168
\begin{frame}[c]
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1169
\frametitle{And and Or}
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1170
\end{frame}
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1171
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1172
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1173
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1174
\begin{frame}[c]
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1175
\frametitle{Break}
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1176
\end{frame}
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1177
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1178
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1179
Christian Urban <christian.urban@kcl.ac.uk>
parents: 958
diff changeset
  1180
  
701
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1181
\end{document}
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1182
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1183
%%% Local Variables:  
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1184
%%% mode: latex
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1185
%%% TeX-master: t
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1186
%%% End: 
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1187
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1188
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1189
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1190
681c36b2af27 updated
Christian Urban <urbanc@in.tum.de>
parents: 612
diff changeset
  1191
610
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1192
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1193
  \begin{frame}[c]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1194
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1195
  \begin{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1196
  \includegraphics[scale=0.6]{../pics/bridge-limits.png}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1197
  \end{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1198
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1199
  \end{frame}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1200
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1201
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1202
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1203
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1204
\begin{frame}[c]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1205
\frametitle{Compilers \& Boeings 777}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1206
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1207
First flight in 1994. They want to achieve triple redundancy in hardware
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1208
faults.\bigskip
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1209
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1210
They compile 1 Ada program to\medskip
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1211
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1212
\begin{itemize}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1213
\item Intel 80486
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1214
\item Motorola 68040 (old Macintosh's)
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1215
\item AMD 29050 (RISC chips used often in laser printers)
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1216
\end{itemize}\medskip
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1217
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1218
using 3 independent compilers.\bigskip\pause
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1219
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1220
\small Airbus uses C and static analysers. Recently started using CompCert.
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1221
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1222
\end{frame}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1223
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1224
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1225
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1226
\begin{frame}[c]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1227
\frametitle{Goal}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1228
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1229
Remember the Bridges example?
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1230
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1231
\begin{itemize}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1232
\item Can we look at our programs and somehow ensure
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1233
they are bug free/correct?\pause\bigskip
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1234
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1235
\item Very hard: Anything interesting about programs is equivalent
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1236
to the Halting Problem, which is undecidable.\pause\bigskip
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1237
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1238
\item \alert{Solution:} We avoid this ``minor'' obstacle by
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1239
      being as close as possible of deciding the halting
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1240
      problem, without actually deciding the halting problem.
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1241
      \small$\quad\Rightarrow$ yes, no, don't know (static analysis)
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1242
\end{itemize}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1243
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1244
\end{frame}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1245
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1246
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1247
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1248
  \begin{frame}[c]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1249
  \frametitle{What is Static Analysis?}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1250
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1251
  \begin{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1252
  \includegraphics[scale=0.4]{../pics/state.png}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1253
  \end{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1254
  
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1255
  \begin{itemize}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1256
  \item depending on some initial input, a program 
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1257
  (behaviour) will ``develop'' over time.
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1258
  \end{itemize}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1259
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1260
  \end{frame}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1261
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1262
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1263
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1264
  \begin{frame}[c]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1265
  \frametitle{What is Static Analysis?}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1266
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1267
  \begin{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1268
  \includegraphics[scale=0.4]{../pics/state2.png}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1269
  \end{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1270
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1271
  \end{frame}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1272
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1273
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1274
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1275
  \begin{frame}[c]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1276
  \frametitle{What is Static Analysis?}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1277
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1278
  \begin{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1279
  \includegraphics[scale=0.4]{../pics/state3.jpg}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1280
  \end{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1281
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1282
  \end{frame}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1283
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1284
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1285
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1286
  \begin{frame}[c]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1287
  \frametitle{What is Static Analysis?}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1288
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1289
  \begin{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1290
  \includegraphics[scale=0.4]{../pics/state4.jpg}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1291
  \end{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1292
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1293
  \begin{itemize}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1294
  \item to be avoided
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1295
  \end{itemize}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1296
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1297
  \end{frame}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1298
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1299
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1300
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1301
  \begin{frame}[c]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1302
  \frametitle{What is Static Analysis?}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1303
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1304
  \begin{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1305
  \includegraphics[scale=0.4]{../pics/state5.png}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1306
  \end{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1307
  
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1308
  \begin{itemize}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1309
  \item this needs more work
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1310
  \end{itemize}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1311
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1312
  \end{frame}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1313
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1314
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1315
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1316
  \begin{frame}[c]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1317
  \frametitle{What is Static Analysis?}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1318
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1319
  \begin{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1320
  \includegraphics[scale=0.4]{../pics/state6.png}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1321
  \end{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1322
  
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1323
  \end{frame}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1324
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1325
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1326
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1327
  \begin{frame}[c,fragile]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1328
    \frametitle{\Large\begin{tabular}{c}Concrete Example:\\[-1mm]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1329
                  Are Vars Definitely Initialised?\end{tabular}}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1330
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1331
Assuming \texttt{x} is initialised, what about \texttt{y}?\bigskip
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1332
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1333
Prog.~1:\\
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1334
\begin{lstlisting}[numbers=none,
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1335
                   basicstyle=\ttfamily,
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1336
                   language=While,xleftmargin=3mm]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1337
if x < 1 then y := x else y := x + 1;
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1338
y := y + 1
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1339
\end{lstlisting}\medskip     
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1340
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1341
Prog.~2:\\
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1342
\begin{lstlisting}[numbers=none,
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1343
                   basicstyle=\ttfamily,
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1344
                   language=While,xleftmargin=3mm]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1345
if x < x then y := y + 1 else y := x;
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1346
y := y + 1
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1347
\end{lstlisting}            
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1348
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1349
  \end{frame}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1350
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1351
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1352
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1353
  \begin{frame}[c,fragile]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1354
    \frametitle{\Large\begin{tabular}{c}Concrete Example:\\[-1mm]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1355
                  Are Vars Definitely Initialised?\end{tabular}}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1356
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1357
              What should the rules be for deciding when a
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1358
              variable is initialised?\bigskip\pause
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1359
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1360
\begin{itemize}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1361
\item variable \texttt{x} is definitely initialized after
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1362
  \texttt{skip}\\
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1363
  iff \texttt{x} is definitely initialized before \texttt{skip}.
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1364
\end{itemize}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1365
  
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1366
\end{frame}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1367
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1368
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1369
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1370
  \begin{frame}[c,fragile]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1371
%    \frametitle{\Large\begin{tabular}{c}Concrete Example:\\[-1mm]
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1372
%                  Are Vars Definitely Initialised?\end{tabular}}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1373
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1374
$\bl{A}$ is the set of definitely defined variables:
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1375
              
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1376
\begin{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1377
\begin{tabular}{c}
612
7a12053567d4 updated
Christian Urban <urbanc@in.tum.de>
parents: 610
diff changeset
  1378
  \bl{\infer{\mbox{}}{A\triangleright\texttt{skip}\triangleright{}A}}\qquad
7a12053567d4 updated
Christian Urban <urbanc@in.tum.de>
parents: 610
diff changeset
  1379
  \bl{\infer{vars(a) \subseteq A}{A\triangleright
7a12053567d4 updated
Christian Urban <urbanc@in.tum.de>
parents: 610
diff changeset
  1380
  (\texttt{x\,:=\,a})\triangleright\{x\}\cup A}}
610
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1381
  \medskip\\\pause
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1382
612
7a12053567d4 updated
Christian Urban <urbanc@in.tum.de>
parents: 610
diff changeset
  1383
  \bl{\infer{A_1\triangleright{}s_1\triangleright{}A_2
7a12053567d4 updated
Christian Urban <urbanc@in.tum.de>
parents: 610
diff changeset
  1384
  \quad A_2\triangleright{}s_2\triangleright{}A_3}
7a12053567d4 updated
Christian Urban <urbanc@in.tum.de>
parents: 610
diff changeset
  1385
  {A_1\triangleright{}(s_1 ; s_2)\triangleright{}A_3}}
610
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1386
  \medskip\\\pause
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1387
  
612
7a12053567d4 updated
Christian Urban <urbanc@in.tum.de>
parents: 610
diff changeset
  1388
  \bl{\infer{vars(b)\subseteq A\quad A\triangleright{}s_1\triangleright{}A_1
7a12053567d4 updated
Christian Urban <urbanc@in.tum.de>
parents: 610
diff changeset
  1389
  \quad A\triangleright{}s_2\triangleright{}A_2}
7a12053567d4 updated
Christian Urban <urbanc@in.tum.de>
parents: 610
diff changeset
  1390
  {A\triangleright(\texttt{if}\;b\;\texttt{then}\;s_1\;\texttt{else}\;s_2)\triangleright{}A_1\cap A_2}}
610
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1391
  \medskip\\\pause
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1392
612
7a12053567d4 updated
Christian Urban <urbanc@in.tum.de>
parents: 610
diff changeset
  1393
  \bl{\infer{vars(b)\subseteq A\quad A\triangleright{}s\triangleright{}A'}
7a12053567d4 updated
Christian Urban <urbanc@in.tum.de>
parents: 610
diff changeset
  1394
  {A\triangleright(\texttt{while}\;b\;\texttt{do}\;s)\triangleright{}A}}\pause
610
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1395
\end{tabular}  
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1396
\end{center}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1397
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1398
\hfill we start with $\bl{A = \{\}}$
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1399
\end{frame}
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1400
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
7ec1bdb670ba updated
Christian Urban <urbanc@in.tum.de>
parents: 609
diff changeset
  1401