| author | Christian Urban <urbanc@in.tum.de> | 
| Thu, 28 Nov 2019 08:18:57 +0000 | |
| changeset 701 | 81377a3eb717 | 
| parent 612 | 274477667793 | 
| child 702 | 67ab7162a861 | 
| permissions | -rw-r--r-- | 
| 701 | 1 | % !TEX program = xelatex | 
| 65 
ade6af51402c
tuned
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: diff
changeset | 2 | \documentclass[dvipsnames,14pt,t]{beamer}
 | 
| 309 
640e4a05cd9b
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
215diff
changeset | 3 | \usepackage{../slides}
 | 
| 215 
828303e8e4af
updated slides
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
207diff
changeset | 4 | \usepackage{../langs}
 | 
| 609 | 5 | \usepackage{../data}
 | 
| 309 
640e4a05cd9b
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
215diff
changeset | 6 | \usepackage{../graphics}
 | 
| 379 
fa2589ec0fae
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
312diff
changeset | 7 | \usepackage{../grammar}
 | 
| 310 
d384fe01d0e8
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
309diff
changeset | 8 | \usepackage{soul}
 | 
| 610 | 9 | \usepackage{mathpartir}
 | 
| 701 | 10 | \usetikzlibrary{shapes,arrows,shadows}
 | 
| 310 
d384fe01d0e8
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
309diff
changeset | 11 | |
| 609 | 12 | % beamer stuff | 
| 459 | 13 | \renewcommand{\slidecaption}{CFL 09, King's College London}
 | 
| 609 | 14 | \newcommand{\bl}[1]{\textcolor{blue}{#1}}       
 | 
| 15 | ||
| 310 
d384fe01d0e8
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
309diff
changeset | 16 | |
| 65 
ade6af51402c
tuned
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: diff
changeset | 17 | \begin{document}
 | 
| 609 | 18 | |
| 65 
ade6af51402c
tuned
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: diff
changeset | 19 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 309 
640e4a05cd9b
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
215diff
changeset | 20 | \begin{frame}[t]
 | 
| 65 
ade6af51402c
tuned
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: diff
changeset | 21 | \frametitle{%
 | 
| 
ade6af51402c
tuned
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: diff
changeset | 22 |   \begin{tabular}{@ {}c@ {}}
 | 
| 
ade6af51402c
tuned
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: diff
changeset | 23 | \\[-3mm] | 
| 459 | 24 | \LARGE Compilers and \\[-2mm] | 
| 538 | 25 | \LARGE Formal Languages (9)\\[3mm] | 
| 65 
ade6af51402c
tuned
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: diff
changeset | 26 |   \end{tabular}}
 | 
| 
ade6af51402c
tuned
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: diff
changeset | 27 | |
| 
ade6af51402c
tuned
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: diff
changeset | 28 | \normalsize | 
| 
ade6af51402c
tuned
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: diff
changeset | 29 |   \begin{center}
 | 
| 
ade6af51402c
tuned
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: diff
changeset | 30 |   \begin{tabular}{ll}
 | 
| 701 | 31 | Email: & christian.urban at kcl.ac.uk\\ | 
| 32 | Office Hours: & Thursdays 12 -- 14\\ | |
| 33 | Location: & N7.07 (North Wing, Bush House)\\ | |
| 34 | Slides \& Progs: & KEATS (also homework is there)\\ | |
| 538 | 35 |   \end{tabular}
 | 
| 36 |   \end{center}
 | |
| 310 
d384fe01d0e8
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
309diff
changeset | 37 | |
| 609 | 38 | \end{frame}
 | 
| 39 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 40 | ||
| 701 | 41 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 42 | \begin{frame}[c,fragile]
 | |
| 43 | \frametitle{Functional Programming}
 | |
| 609 | 44 | |
| 701 | 45 | \footnotesize | 
| 46 | \begin{textblock}{13}(0.9,3)
 | |
| 47 | \begin{lstlisting}[]numbers=none]
 | |
| 48 | def fib(n) = if n == 0 then 0 | |
| 49 | else if n == 1 then 1 | |
| 50 | else fib(n - 1) + fib(n - 2); | |
| 609 | 51 | |
| 701 | 52 | def fact(n) = if n == 0 then 1 else n * fact(n - 1); | 
| 609 | 53 | |
| 701 | 54 | def ack(m, n) = if m == 0 then n + 1 | 
| 55 | else if n == 0 then ack(m - 1, 1) | |
| 56 | else ack(m - 1, ack(m, n - 1)); | |
| 57 | ||
| 58 | def gcd(a, b) = if b == 0 then a else gcd(b, a % b); | |
| 59 | \end{lstlisting}
 | |
| 60 | \end{textblock}
 | |
| 609 | 61 | |
| 62 | \end{frame}
 | |
| 63 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 64 | ||
| 65 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 66 | \begin{frame}[c,fragile]
 | |
| 701 | 67 | \frametitle{Factorial on the JVM}
 | 
| 609 | 68 | |
| 701 | 69 | \begin{textblock}{7}(1,1.8)\footnotesize
 | 
| 70 | \begin{minipage}{6cm}
 | |
| 71 | \begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none]
 | |
| 72 | .method public static facT(II)I | |
| 73 | .limit locals 2 | |
| 74 | .limit stack 6 | |
| 75 | iload 0 | |
| 76 | ldc 0 | |
| 77 | if_icmpne If_else_2 | |
| 78 | iload 1 | |
| 79 | goto If_end_3 | |
| 80 | If_else_2: | |
| 81 | iload 0 | |
| 82 | ldc 1 | |
| 83 | isub | |
| 84 | iload 0 | |
| 85 | iload 1 | |
| 86 | imul | |
| 87 | invokestatic fact/fact/facT(II)I | |
| 88 | If_end_3: | |
| 89 | ireturn | |
| 90 | .end method | |
| 91 | \end{lstlisting}
 | |
| 92 | \end{minipage}
 | |
| 93 | \end{textblock}
 | |
| 94 | ||
| 95 | \begin{textblock}{7}(6,7)
 | |
| 96 | \begin{bubble}[7cm]\small
 | |
| 97 | \begin{lstlisting}[language=Lisp,
 | |
| 98 | basicstyle=\ttfamily, | |
| 99 | numbers=none, | |
| 100 |                    xleftmargin=1mm,linebackgroundcolor=\color{cream}]
 | |
| 101 | def facT(n, acc) = | |
| 102 | if n == 0 then acc | |
| 103 | else facT(n - 1, n * acc); | |
| 104 | \end{lstlisting}
 | |
| 105 | \end{bubble}
 | |
| 106 | \end{textblock}
 | |
| 107 | ||
| 108 | \end{frame}
 | |
| 109 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 110 | ||
| 111 | ||
| 112 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 113 | \begin{frame}[fragile,c]
 | |
| 114 | \frametitle{LLVM}
 | |
| 609 | 115 | |
| 116 | \begin{itemize}
 | |
| 701 | 117 | \item Chris Lattner, Vikram Adve (started in 2000) | 
| 118 | \item Apple hired Lattner in 2006 | |
| 119 | \item modular architecture, LLVM-IR | |
| 120 |   \item \texttt{lli} and \texttt{llc} 
 | |
| 121 | \end{itemize}
 | |
| 609 | 122 | |
| 123 | \end{frame}
 | |
| 701 | 124 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 125 | ||
| 126 | ||
| 127 | ||
| 128 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 129 | \tikzstyle{sensor}=[draw, fill=blue!20, text width=3.8em, line width=1mm,
 | |
| 130 | text centered, minimum height=2em,drop shadow] | |
| 131 | \tikzstyle{ann} = [above, text width=4em, text centered]
 | |
| 132 | \tikzstyle{sc} = [sensor, text width=7em, fill=red!20, 
 | |
| 133 | minimum height=6em, rounded corners, drop shadow,line width=1mm] | |
| 134 | ||
| 135 | \begin{frame}[fragile,c]
 | |
| 136 | \frametitle{LLVM: Overview}
 | |
| 137 | ||
| 138 | \begin{tikzpicture}
 | |
| 139 | % Validation Layer is the same except that there are a set of nodes and links which are added | |
| 140 | ||
| 141 |     \path (0,0) node (IR) [sc] {\textbf{LLVM-IR}\\ Optimisations};
 | |
| 142 |     \path (IR.west)+(-2.2,1.7) node (sou1) [sensor] {C++};
 | |
| 143 |     \path (IR.west)+(-2.2,0.5) node (sou2)[sensor] {C};
 | |
| 144 |     \path (IR.west)+(-2.2,-1.0) node (dots)[ann] {$\vdots$}; 
 | |
| 145 |     \path (IR.west)+(-2.2,-1.8) node (sou3)[sensor] {Haskell};    
 | |
| 146 | ||
| 147 |     \path [draw,->,line width=1mm] (sou1.east) -- node [above] {} (IR.160);
 | |
| 148 |     \path [draw,->,line width=1mm] (sou2.east) -- node [above] {} (IR.180);
 | |
| 149 |     \path [draw,->,line width=1mm] (sou3.east) -- node [above] {} (IR.200);
 | |
| 150 | ||
| 151 |     \path (IR.east)+(2.2,2.0)  node (tar1)[sensor] {x86};
 | |
| 152 |     \path (IR.east)+(2.2,0.8)  node (tar2)[sensor] {ARM};
 | |
| 153 |     \path (IR.east)+(2.2,-0.4) node (tar3)[sensor] {MIPS}; 
 | |
| 154 |     \path (IR.east)+(2.2,-1.6) node (tar4)[sensor] {RISC}; 
 | |
| 155 |     \path (IR.east)+(2.2,-2.8) node (tar5)[sensor] {Power PC};
 | |
| 156 |     \path (IR.east)+(2.2,-4.2) node (dots2)[ann] {$\vdots$};
 | |
| 157 | ||
| 158 |     \path [draw,<-,line width=1mm] (tar1.west) -- node [above] {} (IR.10);
 | |
| 159 |     \path [draw,<-,line width=1mm] (tar2.west) -- node [above] {} (IR.5);
 | |
| 160 |     \path [draw,<-,line width=1mm] (tar3.west) -- node [above] {} (IR.0);
 | |
| 161 |     \path [draw,<-,line width=1mm] (tar4.west) -- node [above] {} (IR.-5);
 | |
| 162 |     \path [draw,<-,line width=1mm] (tar5.west) -- node [above] {} (IR.-10);
 | |
| 163 | ||
| 164 | \end{tikzpicture}
 | |
| 165 | \end{frame}
 | |
| 166 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 167 | ||
| 609 | 168 | |
| 169 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 701 | 170 | \begin{frame}[fragile,t]
 | 
| 171 | \frametitle{LLVM-IR}
 | |
| 172 | \small | |
| 173 | ||
| 174 | \begin{textblock}{7.7}(8,11.4)
 | |
| 175 | \begin{bubble}[5cm]\small
 | |
| 176 | \begin{lstlisting}[language=Lisp,
 | |
| 177 | numbers=none, | |
| 178 |                    xleftmargin=1mm,linebackgroundcolor=\color{cream}]
 | |
| 179 | def fact(n) = | |
| 180 | if n == 0 then 1 | |
| 181 | else n * fact(n - 1) | |
| 182 | \end{lstlisting}
 | |
| 183 | \end{bubble}
 | |
| 184 | \end{textblock}
 | |
| 310 
d384fe01d0e8
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
309diff
changeset | 185 | |
| 701 | 186 | \begin{lstlisting}[language=LLVM,xleftmargin=-7mm]
 | 
| 187 | define i32 @fact (i32 %n) {
 | |
| 188 | %tmp_19 = icmp eq i32 %n, 0 | |
| 189 | br i1 %tmp_19, label %if_br_23, label %else_br_24 | |
| 190 | ||
| 191 | if_br_23: | |
| 192 | ret i32 1 | |
| 193 | ||
| 194 | else_br_24: | |
| 195 | %tmp_21 = sub i32 %n, 1 | |
| 196 | %tmp_22 = call i32 @fact (i32 %tmp_21) | |
| 197 | %tmp_20 = mul i32 %n, %tmp_22 | |
| 198 | ret i32 %tmp_20 | |
| 199 | } | |
| 200 | \end{lstlisting}
 | |
| 609 | 201 | |
| 202 | \end{frame}
 | |
| 701 | 203 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 204 | ||
| 205 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 206 | \begin{frame}[fragile,c]
 | |
| 207 | \frametitle{LLVM Types}
 | |
| 208 | ||
| 209 | \tt | |
| 210 | \begin{center}
 | |
| 211 | \begin{tabular}{ll}
 | |
| 212 | boolean & i1 \\ | |
| 213 | byte & i8 \\ | |
| 214 | short & i16\\ | |
| 215 | char & i16\\ | |
| 216 | integer & i32\\ | |
| 217 | long & i64\\ | |
| 218 | float & float\\ | |
| 219 | double & double\\ | |
| 220 | *\_ & pointer to \\ | |
| 221 | **\_ & pointer to a pointer to\\ | |
| 222 | \mbox{}[\_]    & arrays of\\
 | |
| 223 | \end{tabular}
 | |
| 224 | \end{center}
 | |
| 225 | ||
| 226 | \end{frame}
 | |
| 227 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 228 | ||
| 229 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 230 | \begin{frame}[fragile,c]
 | |
| 231 | \frametitle{LLVM Instructions}
 | |
| 232 | \small | |
| 233 | ||
| 234 | \begin{lstlisting}[language=LLVM]
 | |
| 235 | br i1 %var, label %if_br, label %else_br | |
| 236 | ||
| 237 | icmp eq i32 %x, %y ; for equal | |
| 238 | icmp sle i32 %x, %y ; signed less or equal | |
| 239 | icmp slt i32 %x, %y ; signed less than | |
| 240 | icmp ult i32 %x, %y ; unsigned less than | |
| 241 | ||
| 242 | %var = call i32 @foo(...args...) | |
| 243 | \end{lstlisting}
 | |
| 244 | ||
| 245 | \end{frame}
 | |
| 246 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 247 | ||
| 248 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 249 | \begin{frame}[fragile,c]
 | |
| 250 | \frametitle{SSA Format}
 | |
| 251 | ||
| 252 | \bl{$(1 + a) + (3 + (b * 5))$}\bigskip\bigskip
 | |
| 253 | ||
| 254 | \begin{lstlisting}[language=LLVM]
 | |
| 255 | let tmp0 = add 1 a in | |
| 256 | let tmp1 = mul b 5 in | |
| 257 | let tmp2 = add 3 tmp1 in | |
| 258 | let tmp3 = add tmp0 tmp2 in | |
| 259 | tmp3 | |
| 260 | \end{lstlisting}
 | |
| 261 | ||
| 262 | \end{frame}
 | |
| 263 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 609 | 264 | |
| 265 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 701 | 266 | \begin{frame}[fragile,c]
 | 
| 267 | \frametitle{Abstract Syntax Trees}
 | |
| 268 | \footnotesize | |
| 269 | ||
| 270 | \begin{lstlisting}[language=Scala,numbers=none,xleftmargin=-3mm]
 | |
| 271 | // Fun language (expressions) | |
| 272 | abstract class Exp | |
| 273 | abstract class BExp | |
| 274 | ||
| 275 | case class Call(name: String, args: List[Exp]) extends Exp | |
| 276 | case class If(a: BExp, e1: Exp, e2: Exp) extends Exp | |
| 277 | case class Write(e: Exp) extends Exp | |
| 278 | case class Var(s: String) extends Exp | |
| 279 | case class Num(i: Int) extends Exp | |
| 280 | case class Aop(o: String, a1: Exp, a2: Exp) extends Exp | |
| 281 | case class Sequence(e1: Exp, e2: Exp) extends Exp | |
| 282 | case class Bop(o: String, a1: Exp, a2: Exp) extends BExp | |
| 283 | \end{lstlisting}
 | |
| 609 | 284 | |
| 701 | 285 | \end{frame}
 | 
| 286 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 287 | ||
| 288 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 289 | \begin{frame}[fragile,c]
 | |
| 290 | \frametitle{K-(Intermediate)Language}
 | |
| 291 | \footnotesize | |
| 609 | 292 | |
| 701 | 293 | \begin{lstlisting}[language=Scala,numbers=none,xleftmargin=-3mm]
 | 
| 294 | abstract class KExp | |
| 295 | abstract class KVal | |
| 296 | ||
| 297 | case class KVar(s: String) extends KVal | |
| 298 | case class KNum(i: Int) extends KVal | |
| 299 | case class Kop(o: String, v1: KVal, v2: KVal) extends KVal | |
| 300 | case class KCall(o: String, vrs: List[KVal]) extends KVal | |
| 301 | case class KWrite(v: KVal) extends KVal | |
| 302 | ||
| 303 | case class KIf(x1: String, e1: KExp, e2: KExp) extends KExp | |
| 304 | case class KLet(x: String, v: KVal, e: KExp) extends KExp | |
| 305 | case class KReturn(v: KVal) extends KExp | |
| 609 | 306 | \end{lstlisting}
 | 
| 307 | ||
| 701 | 308 | \end{frame}
 | 
| 309 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 310 | ||
| 311 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 312 | \begin{frame}[fragile,c]
 | |
| 313 | \frametitle{CPS-Translation}
 | |
| 314 | \small | |
| 315 | ||
| 316 | \begin{lstlisting}[language=Scala,numbers=none]
 | |
| 317 | def CPS(e: Exp)(k: KVal => KExp) : KExp = | |
| 318 |   e match { ... }
 | |
| 319 | \end{lstlisting}
 | |
| 320 | \bigskip\bigskip | |
| 321 | ||
| 322 | \small | |
| 323 | \begin{lstlisting}[language=LLVMIR,numbers=none,xleftmargin=30mm,escapeinside={(*@}{@*)}]
 | |
| 324 | let tmp0 = add 1 a in | |
| 325 | let tmp1 = mul (*@$\Box$@*) 5 in | |
| 326 | let tmp2 = add 3 tmp1 in | |
| 327 | let tmp3 = add tmp0 tmp2 in | |
| 328 | KReturn tmp3 | |
| 329 | \end{lstlisting}
 | |
| 609 | 330 | |
| 331 | \end{frame}
 | |
| 701 | 332 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 333 | ||
| 334 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 335 | \begin{frame}[fragile,c]
 | |
| 336 | \frametitle{CPS-Translation}
 | |
| 337 | \small | |
| 338 | ||
| 339 | \begin{lstlisting}[language=Scala,numbers=none]
 | |
| 340 | def CPS(e: Exp)(k: KVal => KExp) : KExp = | |
| 341 |   e match { 
 | |
| 342 | case Var(s) => k(KVar(s)) | |
| 343 | case Num(i) => k(KNum(i)) | |
| 344 | ... | |
| 345 | } | |
| 346 | \end{lstlisting}
 | |
| 347 | \bigskip\bigskip | |
| 348 | ||
| 349 | \small | |
| 350 | \begin{lstlisting}[language=LLVMIR,numbers=none,xleftmargin=30mm,escapeinside={(*@}{@*)}]
 | |
| 351 | let tmp0 = add 1 a in | |
| 352 | let tmp1 = mul (*@$\Box$@*) 5 in | |
| 353 | let tmp2 = add 3 tmp1 in | |
| 354 | let tmp3 = add tmp0 tmp2 in | |
| 355 | KReturn tmp3 | |
| 356 | \end{lstlisting}
 | |
| 357 | ||
| 358 | \end{frame}
 | |
| 359 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 609 | 360 | |
| 361 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 701 | 362 | \begin{frame}[fragile,c]
 | 
| 363 | \frametitle{CPS-Translation}
 | |
| 364 | \small | |
| 609 | 365 | |
| 701 | 366 | \begin{lstlisting}[language=Scala,numbers=none,xleftmargin=-5mm]
 | 
| 367 | def CPS(e: Exp)(k: KVal => KExp) : KExp = e match { 
 | |
| 368 |   case Aop(o, e1, e2) => {
 | |
| 369 |     val z = Fresh("tmp")
 | |
| 370 | CPS(e1)(y1 => | |
| 371 | CPS(e2)(y2 => | |
| 372 | KLet(z, Kop(o, y1, y2), k(KVar(z))))) | |
| 373 | } ... | |
| 374 | } | |
| 609 | 375 | \end{lstlisting}
 | 
| 376 | ||
| 701 | 377 | \small | 
| 378 | \begin{lstlisting}[language=LLVMIR,numbers=none,xleftmargin=30mm,escapeinside={(*@}{@*)}]
 | |
| 379 | ... | |
| 380 | let z = op (*@$\Box_{y_1}$@*) (*@$\Box_{y_2}$@*)
 | |
| 381 | let tmp0 = add 1 a in | |
| 382 | let tmp1 = mul (*@$\Box\!\!\!\!\raisebox{0.6mm}{\texttt{z}}$@*) 5 in 
 | |
| 383 | let tmp2 = add 3 tmp1 in | |
| 384 | let tmp3 = add tmp0 tmp2 in | |
| 385 | KReturn tmp3 | |
| 386 | \end{lstlisting}
 | |
| 609 | 387 | |
| 388 | \end{frame}
 | |
| 701 | 389 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 609 | 390 | |
| 391 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 701 | 392 | \begin{frame}[fragile,c]
 | 
| 393 | \frametitle{CPS-Translation}
 | |
| 394 | \small | |
| 609 | 395 | |
| 701 | 396 | \begin{lstlisting}[language=Scala,numbers=none]
 | 
| 397 | def CPS(e: Exp)(k: KVal => KExp) : KExp = | |
| 398 |   e match { 
 | |
| 399 | case Sequence(e1, e2) => | |
| 400 | CPS(e1)(_ => CPS(e2)(y2 => k(y2))) | |
| 401 | ... | |
| 402 | } | |
| 403 | \end{lstlisting}
 | |
| 404 | \bigskip\bigskip | |
| 609 | 405 | |
| 701 | 406 | \small | 
| 407 | \begin{lstlisting}[language=LLVMIR,numbers=none,xleftmargin=30mm,escapeinside={(*@}{@*)}]
 | |
| 408 | let tmp0 = add 1 a in | |
| 409 | let tmp1 = mul (*@$\Box$@*) 5 in | |
| 410 | let tmp2 = add 3 tmp1 in | |
| 411 | let tmp3 = add tmp0 tmp2 in | |
| 412 | KReturn tmp3 | |
| 609 | 413 | \end{lstlisting}
 | 
| 414 | ||
| 701 | 415 | \end{frame}
 | 
| 416 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 417 | ||
| 418 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 419 | \begin{frame}[fragile,c]
 | |
| 420 | \frametitle{CPS-Translation}
 | |
| 421 | \small | |
| 422 | ||
| 423 | \begin{lstlisting}[language=Scala,numbers=none]
 | |
| 424 | def CPS(e: Exp)(k: KVal => KExp) : KExp = | |
| 425 |   e match { 
 | |
| 426 | ... | |
| 427 | case Sequence(e1, e2) => | |
| 428 | CPS(e1)(_ => CPS(e2)(y2 => k(y2))) | |
| 429 | ... | |
| 430 | } | |
| 431 | \end{lstlisting}
 | |
| 432 | \bigskip\bigskip | |
| 433 | ||
| 434 | \small | |
| 435 | \begin{lstlisting}[language=LLVMIR,numbers=none,xleftmargin=30mm,escapeinside={(*@}{@*)}]
 | |
| 436 | let tmp0 = add 1 a in | |
| 437 | let tmp1 = mul (*@$\Box$@*) 5 in | |
| 438 | let tmp2 = add 3 tmp1 in | |
| 439 | let tmp3 = add tmp0 tmp2 in | |
| 440 | KReturn tmp3 | |
| 441 | \end{lstlisting}
 | |
| 609 | 442 | |
| 443 | \end{frame}
 | |
| 701 | 444 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 310 
d384fe01d0e8
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
309diff
changeset | 445 | |
| 610 | 446 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 701 | 447 | \begin{frame}[fragile,c]
 | 
| 448 | \frametitle{CPS-Translation}
 | |
| 449 | \small | |
| 450 | ||
| 451 | \begin{lstlisting}[language=Scala,numbers=none,xleftmargin=-3mm]
 | |
| 452 | def CPS(e: Exp)(k: KVal => KExp) : KExp = | |
| 453 |   e match { 
 | |
| 454 | ... | |
| 455 |     case If(Bop(o, b1, b2), e1, e2) => {
 | |
| 456 |       val z = Fresh("tmp")
 | |
| 457 | CPS(b1)(y1 => | |
| 458 | CPS(b2)(y2 => | |
| 459 | KLet(z, Kop(o, y1, y2), | |
| 460 | KIf(z, CPS(e1)(k), CPS(e2)(k))))) | |
| 461 | } | |
| 462 | ... | |
| 463 | } | |
| 464 | \end{lstlisting}
 | |
| 465 | ||
| 466 | \end{frame}
 | |
| 467 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 468 | ||
| 469 | ||
| 470 | ||
| 471 | ||
| 472 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 610 | 473 | \begin{frame}[c]
 | 
| 474 | ||
| 475 | \large\bf | |
| 701 | 476 | Using a compiler, \\ | 
| 477 | how can you mount the\\ | |
| 478 | perfect attack against a system? | |
| 610 | 479 | |
| 701 | 480 | \end{frame}
 | 
| 610 | 481 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 482 | ||
| 483 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 484 | \mode<presentation>{
 | |
| 485 | \begin{frame}[c]
 | |
| 486 | ||
| 487 | {\large\bf
 | |
| 488 | What is a \alert{perfect} attack?}\bigskip
 | |
| 489 | ||
| 490 | \begin{enumerate}
 | |
| 491 | \item you can potentially completely take over a target system | |
| 492 | \item your attack is (nearly) undetectable | |
| 493 | \item the victim has (almost) no chance to recover | |
| 494 | \end{enumerate}
 | |
| 495 | ||
| 496 | \end{frame}}
 | |
| 497 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 498 | ||
| 499 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 500 | \mode<presentation>{
 | |
| 501 | \begin{frame}[c]
 | |
| 502 | ||
| 503 | ||
| 504 |   \begin{center}
 | |
| 505 |   \begin{tikzpicture}[scale=1]
 | |
| 506 | ||
| 507 |   \onslide<1->{
 | |
| 508 |   \node (A) at (0,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=17mm] {};
 | |
| 509 |   \node [below right] at (A.north west) {\footnotesize\begin{tabular}{@{}l@{}}
 | |
| 510 |   \only<1,2>{clean}\only<3->{\alert{hacked}}\\compiler\end{tabular}};}
 | |
| 511 | ||
| 512 | ||
| 513 |   \onslide<2->{
 | |
| 514 |   \node (B) at (-2,2)  [draw=black, rectangle, very thick, minimum height=10mm, minimum width=12mm] {};
 | |
| 515 |   \node [below right] at (B.north west) {\footnotesize\begin{tabular}{@{}l@{}}login\\(src)\end{tabular}};
 | |
| 516 | ||
| 517 |   \node (C) at (2,2)  [draw=black, rectangle, very thick, minimum height=10mm, minimum width=12mm] {};
 | |
| 518 |   \node [below right] at (C.north west) {\footnotesize\begin{tabular}{@{}l@{}}login\\(bin)\end{tabular}};
 | |
| 519 | ||
| 520 | \draw[->, line width=2mm] (B) -- (C); | |
| 521 | } | |
| 522 | ||
| 523 |  \onslide<3->{\node [above left=-1.5mm] at (C.south east) {\footnotesize \alert{$\blacksquare$}};}
 | |
| 524 | ||
| 525 |   \end{tikzpicture}
 | |
| 526 |   \end{center}
 | |
| 527 | ||
| 528 | \end{frame}}
 | |
| 529 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 530 | ||
| 531 | ||
| 532 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 533 | \mode<presentation>{
 | |
| 534 | \begin{frame}[c]
 | |
| 535 | ||
| 536 |   \begin{center}
 | |
| 537 |   \begin{tikzpicture}[scale=1]
 | |
| 538 | ||
| 539 |   \onslide<1->{
 | |
| 540 |   \node (A) at (0,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
 | |
| 541 |   \node [below right] at (A.north west) {\small V0.01};
 | |
| 542 |   \node [below right] (A1) at (A.south west) {\small Scala};
 | |
| 543 |   \node [below right] (A1) at (A1.south west) {\small\textcolor{gray}{host language}};
 | |
| 544 |   \node [above right] at (A.north west) {my compiler (src)};}
 | |
| 545 | ||
| 546 |   \onslide<2->{
 | |
| 547 |   \node (B) at (1.8,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
 | |
| 548 |   \node [below right] at (B.north west) {\small V0.02};
 | |
| 549 |   \node [below right] at (B.south west) {\small Scala};
 | |
| 550 |   \node at (3,0) {\ldots};
 | |
| 551 | ||
| 552 |   \node (C) at (5,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
 | |
| 553 |   \node [below right] at (C.north west) {\small V1.00};
 | |
| 554 |   \node [below right] at (C.south west) {\small Scala};}
 | |
| 555 | ||
| 556 |   \onslide<3->{
 | |
| 557 |   \node (D) at (6.8,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
 | |
| 558 |   \node [below right] at (D.north west) {\small V1.00};
 | |
| 559 | ||
| 560 |   \node (E) at (6.8,2)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
 | |
| 561 |   \node [below right] at (E.north west) {\small V1.01};}
 | |
| 562 | ||
| 563 |   \onslide<4->{
 | |
| 564 |   \node (F) at (8.6,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
 | |
| 565 |   \node [below right] at (F.north west) {\small V1.01};
 | |
| 566 | ||
| 567 |   \node (G) at (8.6,2)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
 | |
| 568 |   \node [below right] at (G.north west) {\small V1.02};
 | |
| 569 |   \node at (9.8,0) {\ldots};
 | |
| 570 |   \node at (9.8,2) {\ldots};
 | |
| 571 |   \node at (8,-2) {\textcolor{gray}{\begin{tabular}{@{}l@{}}no host language\\needed\end{tabular}}};
 | |
| 572 | } | |
| 573 | ||
| 574 |   \end{tikzpicture}
 | |
| 575 |   \end{center}
 | |
| 576 | ||
| 577 | \end{frame}}
 | |
| 578 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 579 | ||
| 580 | ||
| 581 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 582 |   \mode<presentation>{
 | |
| 583 |   \begin{frame}<1-3>
 | |
| 584 |   \frametitle{\LARGE\begin{tabular}{c}Hacking Compilers 
 | |
| 585 |   \end{tabular}}
 | |
| 586 | ||
| 587 | %Why is it so paramount to have a small trusted code base (TCB)? | |
| 588 | \bigskip\bigskip | |
| 589 | ||
| 590 |   \begin{columns}
 | |
| 591 |   \begin{column}{2.7cm}
 | |
| 592 |   \begin{minipage}{2.5cm}%
 | |
| 593 |   \begin{tabular}{c@ {}}
 | |
| 594 |   \includegraphics[scale=0.2]{../pics/ken-thompson.jpg}\\[-1.8mm]
 | |
| 595 | \footnotesize Ken Thompson\\[-1.8mm] | |
| 596 | \footnotesize Turing Award, 1983\\ | |
| 597 |   \end{tabular}
 | |
| 598 |   \end{minipage}
 | |
| 599 |   \end{column}
 | |
| 600 |   \begin{column}{9cm}
 | |
| 601 |   \begin{tabular}{l@ {\hspace{1mm}}p{8cm}}
 | |
| 602 | ||
| 603 | & Ken Thompson showed how to hide a Trojan Horse in a | |
| 604 |   compiler \textcolor{red}{without} leaving any traces in the source code.\\[2mm]
 | |
| 605 | ||
| 606 | & No amount of source level verification will protect | |
| 607 | you from such Thompson-hacks.\\[2mm] | |
| 608 | ||
| 609 |   \end{tabular}
 | |
| 610 |   \end{column}
 | |
| 611 |   \end{columns}
 | |
| 612 | ||
| 613 |   \only<2>{
 | |
| 614 |   \begin{textblock}{6}(4,2)
 | |
| 615 |   \begin{tikzpicture}
 | |
| 616 | \draw (0,0) node[inner sep=3mm,fill=cream, ultra thick, draw=red, rounded corners=2mm] | |
| 617 |   {\normalsize
 | |
| 618 |   \begin{minipage}{8cm}
 | |
| 619 |   \begin{quote}
 | |
| 620 |   \includegraphics[scale=0.05]{../pics/evil.png}
 | |
| 621 |   \begin{enumerate}
 | |
| 622 | \item[1)] Assume you ship the compiler as binary and also with sources. | |
| 623 | \item[2)] Make the compiler aware when it compiles itself. | |
| 624 | \item[3)] Add the Trojan horse. | |
| 625 | \item[4)] Compile. | |
| 626 | \item[5)] Delete Trojan horse from the sources of the compiler. | |
| 627 |   \item[6)] Go on holiday for the rest of your life. ;o)\\[-7mm]\mbox{}
 | |
| 628 |   \end{enumerate}
 | |
| 629 |   \end{quote}
 | |
| 630 |   \end{minipage}};
 | |
| 631 |   \end{tikzpicture}
 | |
| 632 |   \end{textblock}}
 | |
| 633 | ||
| 634 |   \end{frame}}
 | |
| 635 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 636 | ||
| 701 | 637 | |
| 638 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 639 |   \begin{frame}[c]
 | |
| 640 |   \frametitle{Dijkstra on Testing}
 | |
| 641 | ||
| 642 |   \begin{bubble}[10cm]
 | |
| 643 | ``Program testing can be a very effective way to show the | |
| 644 | presence of bugs, but it is hopelessly inadequate for showing | |
| 645 | their absence.'' | |
| 646 |   \end{bubble}\bigskip
 | |
| 647 | ||
| 648 | \small | |
| 649 | What is good about compilers: the either seem to work, | |
| 650 | or go horribly wrong (most of the time). | |
| 651 | ||
| 652 |   \end{frame}
 | |
| 653 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 654 | ||
| 655 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 656 | \begin{frame}[c]
 | |
| 657 | \frametitle{\Large Proving Programs to be Correct}
 | |
| 658 | ||
| 659 | \begin{bubble}[10cm]
 | |
| 660 | \small | |
| 661 | {\bf Theorem:} There are infinitely many prime 
 | |
| 662 | numbers.\medskip\\ | |
| 663 | ||
| 664 | {\bf Proof} \ldots\\
 | |
| 665 | \end{bubble}\bigskip
 | |
| 666 | ||
| 667 | ||
| 668 | similarly\bigskip | |
| 669 | ||
| 670 | \begin{bubble}[10cm]
 | |
| 671 | \small | |
| 672 | {\bf Theorem:} The program is doing what 
 | |
| 673 | it is supposed to be doing.\medskip | |
| 674 | ||
| 675 | {\bf Long, long proof} \ldots\\
 | |
| 676 | \end{bubble}\bigskip\medskip
 | |
| 677 | ||
| 678 | \small This can be a gigantic proof. The only hope is to have | |
| 679 | help from the computer. `Program' is here to be understood to be | |
| 680 | quite general (compiler, OS, \ldots). | |
| 681 | ||
| 682 | \end{frame}
 | |
| 683 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 684 | ||
| 685 | ||
| 686 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 687 | ||
| 688 | \begin{frame}[c]
 | |
| 689 | \frametitle{Can This Be Done?}
 | |
| 690 | ||
| 691 | \begin{itemize}
 | |
| 692 | \item in 2008, verification of a small C-compiler | |
| 693 | \begin{itemize}
 | |
| 694 | \item ``if my input program has a certain behaviour, then the compiled machine code has the same behaviour'' | |
| 695 | \item is as good as \texttt{gcc -O1}, but much, much less buggy 
 | |
| 696 | \end{itemize}
 | |
| 697 | \end{itemize}
 | |
| 698 | ||
| 699 | \begin{center}
 | |
| 700 |   \includegraphics[scale=0.12]{../pics/compcert.png}
 | |
| 701 | \end{center}
 | |
| 702 | ||
| 703 | \end{frame}
 | |
| 704 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 705 | ||
| 706 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 707 | \begin{frame}[t]
 | |
| 708 | \frametitle{Fuzzy Testing C-Compilers}
 | |
| 709 | ||
| 710 | \begin{itemize}
 | |
| 711 | \item tested GCC, LLVM and others by randomly generating | |
| 712 | C-programs | |
| 713 | \item found more than 300 bugs in GCC and also | |
| 714 | many in LLVM (some of them highest-level critical)\bigskip | |
| 715 | \item about CompCert: | |
| 716 | ||
| 717 | \begin{bubble}[10.7cm]\small ``The striking thing about our CompCert
 | |
| 718 | results is that the middle-end bugs we found in all other | |
| 719 | compilers are absent. As of early 2011, the under-development | |
| 720 | version of CompCert is the only compiler we have tested for | |
| 721 | which Csmith cannot find wrong-code errors. This is not for | |
| 722 | lack of trying: we have devoted about six CPU-years to the | |
| 723 | task.'' | |
| 724 | \end{bubble} 
 | |
| 725 | \end{itemize}
 | |
| 726 | ||
| 727 | \end{frame}
 | |
| 728 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 729 | ||
| 730 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 731 | ||
| 732 | \begin{frame}[c]
 | |
| 733 | \frametitle{Next Week}
 | |
| 734 | ||
| 735 | \begin{itemize}
 | |
| 736 | \item Revision Lecture\medskip | |
| 737 | \item How many  strings are in $\bl{L(a^*)}$?\pause\medskip
 | |
| 738 | \item How many  strings are in $\bl{L((a + b)^*)}$?\\ Are there more than
 | |
| 739 |   in $\bl{L(a^*)}$?
 | |
| 740 | \end{itemize}
 | |
| 741 | ||
| 742 | ||
| 743 | ||
| 744 | \end{frame}
 | |
| 745 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 746 | ||
| 747 | ||
| 748 | ||
| 749 | \end{document}
 | |
| 750 | ||
| 751 | %%% Local Variables: | |
| 752 | %%% mode: latex | |
| 753 | %%% TeX-master: t | |
| 754 | %%% End: | |
| 755 | ||
| 756 | ||
| 757 | ||
| 758 | ||
| 759 | ||
| 610 | 760 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 761 |   \begin{frame}[c]
 | |
| 762 | ||
| 763 |   \begin{center}
 | |
| 764 |   \includegraphics[scale=0.6]{../pics/bridge-limits.png}
 | |
| 765 |   \end{center}
 | |
| 766 | ||
| 767 |   \end{frame}
 | |
| 768 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 769 | ||
| 770 | ||
| 771 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 772 | \begin{frame}[c]
 | |
| 773 | \frametitle{Compilers \& Boeings 777}
 | |
| 774 | ||
| 775 | First flight in 1994. They want to achieve triple redundancy in hardware | |
| 776 | faults.\bigskip | |
| 777 | ||
| 778 | They compile 1 Ada program to\medskip | |
| 779 | ||
| 780 | \begin{itemize}
 | |
| 781 | \item Intel 80486 | |
| 782 | \item Motorola 68040 (old Macintosh's) | |
| 783 | \item AMD 29050 (RISC chips used often in laser printers) | |
| 784 | \end{itemize}\medskip
 | |
| 785 | ||
| 786 | using 3 independent compilers.\bigskip\pause | |
| 787 | ||
| 788 | \small Airbus uses C and static analysers. Recently started using CompCert. | |
| 789 | ||
| 790 | \end{frame}
 | |
| 791 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 792 | ||
| 793 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 794 | \begin{frame}[c]
 | |
| 795 | \frametitle{Goal}
 | |
| 796 | ||
| 797 | Remember the Bridges example? | |
| 798 | ||
| 799 | \begin{itemize}
 | |
| 800 | \item Can we look at our programs and somehow ensure | |
| 801 | they are bug free/correct?\pause\bigskip | |
| 802 | ||
| 803 | \item Very hard: Anything interesting about programs is equivalent | |
| 804 | to the Halting Problem, which is undecidable.\pause\bigskip | |
| 805 | ||
| 806 | \item \alert{Solution:} We avoid this ``minor'' obstacle by
 | |
| 807 | being as close as possible of deciding the halting | |
| 808 | problem, without actually deciding the halting problem. | |
| 809 | \small$\quad\Rightarrow$ yes, no, don't know (static analysis) | |
| 810 | \end{itemize}
 | |
| 811 | ||
| 812 | \end{frame}
 | |
| 813 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 814 | ||
| 815 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 816 |   \begin{frame}[c]
 | |
| 817 |   \frametitle{What is Static Analysis?}
 | |
| 818 | ||
| 819 |   \begin{center}
 | |
| 820 |   \includegraphics[scale=0.4]{../pics/state.png}
 | |
| 821 |   \end{center}
 | |
| 822 | ||
| 823 |   \begin{itemize}
 | |
| 824 | \item depending on some initial input, a program | |
| 825 | (behaviour) will ``develop'' over time. | |
| 826 |   \end{itemize}
 | |
| 827 | ||
| 828 |   \end{frame}
 | |
| 829 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 830 | ||
| 831 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 832 |   \begin{frame}[c]
 | |
| 833 |   \frametitle{What is Static Analysis?}
 | |
| 834 | ||
| 835 |   \begin{center}
 | |
| 836 |   \includegraphics[scale=0.4]{../pics/state2.png}
 | |
| 837 |   \end{center}
 | |
| 838 | ||
| 839 |   \end{frame}
 | |
| 840 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 841 | ||
| 842 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 843 |   \begin{frame}[c]
 | |
| 844 |   \frametitle{What is Static Analysis?}
 | |
| 845 | ||
| 846 |   \begin{center}
 | |
| 847 |   \includegraphics[scale=0.4]{../pics/state3.jpg}
 | |
| 848 |   \end{center}
 | |
| 849 | ||
| 850 |   \end{frame}
 | |
| 851 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 852 | ||
| 853 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 854 |   \begin{frame}[c]
 | |
| 855 |   \frametitle{What is Static Analysis?}
 | |
| 856 | ||
| 857 |   \begin{center}
 | |
| 858 |   \includegraphics[scale=0.4]{../pics/state4.jpg}
 | |
| 859 |   \end{center}
 | |
| 860 | ||
| 861 |   \begin{itemize}
 | |
| 862 | \item to be avoided | |
| 863 |   \end{itemize}
 | |
| 864 | ||
| 865 |   \end{frame}
 | |
| 866 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 867 | ||
| 868 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 869 |   \begin{frame}[c]
 | |
| 870 |   \frametitle{What is Static Analysis?}
 | |
| 871 | ||
| 872 |   \begin{center}
 | |
| 873 |   \includegraphics[scale=0.4]{../pics/state5.png}
 | |
| 874 |   \end{center}
 | |
| 875 | ||
| 876 |   \begin{itemize}
 | |
| 877 | \item this needs more work | |
| 878 |   \end{itemize}
 | |
| 879 | ||
| 880 |   \end{frame}
 | |
| 881 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 882 | ||
| 883 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 884 |   \begin{frame}[c]
 | |
| 885 |   \frametitle{What is Static Analysis?}
 | |
| 886 | ||
| 887 |   \begin{center}
 | |
| 888 |   \includegraphics[scale=0.4]{../pics/state6.png}
 | |
| 889 |   \end{center}
 | |
| 890 | ||
| 891 |   \end{frame}
 | |
| 892 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 893 | ||
| 894 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 895 |   \begin{frame}[c,fragile]
 | |
| 896 |     \frametitle{\Large\begin{tabular}{c}Concrete Example:\\[-1mm]
 | |
| 897 |                   Are Vars Definitely Initialised?\end{tabular}}
 | |
| 898 | ||
| 899 | Assuming \texttt{x} is initialised, what about \texttt{y}?\bigskip
 | |
| 900 | ||
| 901 | Prog.~1:\\ | |
| 902 | \begin{lstlisting}[numbers=none,
 | |
| 903 | basicstyle=\ttfamily, | |
| 904 | language=While,xleftmargin=3mm] | |
| 905 | if x < 1 then y := x else y := x + 1; | |
| 906 | y := y + 1 | |
| 907 | \end{lstlisting}\medskip     
 | |
| 908 | ||
| 909 | Prog.~2:\\ | |
| 910 | \begin{lstlisting}[numbers=none,
 | |
| 911 | basicstyle=\ttfamily, | |
| 912 | language=While,xleftmargin=3mm] | |
| 913 | if x < x then y := y + 1 else y := x; | |
| 914 | y := y + 1 | |
| 915 | \end{lstlisting}            
 | |
| 916 | ||
| 917 |   \end{frame}
 | |
| 918 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 919 | ||
| 920 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 921 |   \begin{frame}[c,fragile]
 | |
| 922 |     \frametitle{\Large\begin{tabular}{c}Concrete Example:\\[-1mm]
 | |
| 923 |                   Are Vars Definitely Initialised?\end{tabular}}
 | |
| 924 | ||
| 925 | What should the rules be for deciding when a | |
| 926 | variable is initialised?\bigskip\pause | |
| 927 | ||
| 928 | \begin{itemize}
 | |
| 929 | \item variable \texttt{x} is definitely initialized after
 | |
| 930 |   \texttt{skip}\\
 | |
| 931 |   iff \texttt{x} is definitely initialized before \texttt{skip}.
 | |
| 932 | \end{itemize}
 | |
| 933 | ||
| 934 | \end{frame}
 | |
| 935 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 936 | ||
| 937 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 938 |   \begin{frame}[c,fragile]
 | |
| 939 | %    \frametitle{\Large\begin{tabular}{c}Concrete Example:\\[-1mm]
 | |
| 940 | %                  Are Vars Definitely Initialised?\end{tabular}}
 | |
| 941 | ||
| 942 | $\bl{A}$ is the set of definitely defined variables:
 | |
| 943 | ||
| 944 | \begin{center}
 | |
| 945 | \begin{tabular}{c}
 | |
| 612 | 946 |   \bl{\infer{\mbox{}}{A\triangleright\texttt{skip}\triangleright{}A}}\qquad
 | 
| 947 |   \bl{\infer{vars(a) \subseteq A}{A\triangleright
 | |
| 948 |   (\texttt{x\,:=\,a})\triangleright\{x\}\cup A}}
 | |
| 610 | 949 | \medskip\\\pause | 
| 950 | ||
| 612 | 951 |   \bl{\infer{A_1\triangleright{}s_1\triangleright{}A_2
 | 
| 952 |   \quad A_2\triangleright{}s_2\triangleright{}A_3}
 | |
| 953 |   {A_1\triangleright{}(s_1 ; s_2)\triangleright{}A_3}}
 | |
| 610 | 954 | \medskip\\\pause | 
| 955 | ||
| 612 | 956 |   \bl{\infer{vars(b)\subseteq A\quad A\triangleright{}s_1\triangleright{}A_1
 | 
| 957 |   \quad A\triangleright{}s_2\triangleright{}A_2}
 | |
| 958 |   {A\triangleright(\texttt{if}\;b\;\texttt{then}\;s_1\;\texttt{else}\;s_2)\triangleright{}A_1\cap A_2}}
 | |
| 610 | 959 | \medskip\\\pause | 
| 960 | ||
| 612 | 961 |   \bl{\infer{vars(b)\subseteq A\quad A\triangleright{}s\triangleright{}A'}
 | 
| 962 |   {A\triangleright(\texttt{while}\;b\;\texttt{do}\;s)\triangleright{}A}}\pause
 | |
| 610 | 963 | \end{tabular}  
 | 
| 964 | \end{center}
 | |
| 965 | ||
| 966 | \hfill we start with $\bl{A = \{\}}$
 | |
| 967 | \end{frame}
 | |
| 968 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 969 |