| author | Christian Urban <urbanc@in.tum.de> | 
| Mon, 27 Jan 2020 10:11:44 +0000 | |
| changeset 708 | 1b5dc2468ce3 | 
| parent 702 | 67ab7162a861 | 
| child 744 | a33ce6c8e2c3 | 
| 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]
 | |
| 702 | 43 | \frametitle{The Fun Language}
 | 
| 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]
 | |
| 702 | 67 | \frametitle{Factorial Funct.~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]
 | |
| 702 | 231 | \frametitle{LLVM-IR Instructions}
 | 
| 701 | 232 | \small | 
| 233 | ||
| 702 | 234 | \begin{lstlisting}[language=LLVM,xleftmargin=0mm]
 | 
| 701 | 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]
 | |
| 702 | 255 | tmp0 = add 1 a | 
| 256 | tmp1 = mul b 5 | |
| 257 | tmp2 = add 3 tmp1 | |
| 258 | tmp3 = add tmp0 tmp2 | |
| 259 | \end{lstlisting}\bigskip\bigskip
 | |
| 260 | ||
| 261 | \hfill Static Single Assignment | |
| 701 | 262 | |
| 263 | \end{frame}
 | |
| 264 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 609 | 265 | |
| 266 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 701 | 267 | \begin{frame}[fragile,c]
 | 
| 268 | \frametitle{Abstract Syntax Trees}
 | |
| 269 | \footnotesize | |
| 270 | ||
| 271 | \begin{lstlisting}[language=Scala,numbers=none,xleftmargin=-3mm]
 | |
| 272 | // Fun language (expressions) | |
| 273 | abstract class Exp | |
| 274 | abstract class BExp | |
| 275 | ||
| 276 | case class Call(name: String, args: List[Exp]) extends Exp | |
| 277 | case class If(a: BExp, e1: Exp, e2: Exp) extends Exp | |
| 278 | case class Write(e: Exp) extends Exp | |
| 279 | case class Var(s: String) extends Exp | |
| 280 | case class Num(i: Int) extends Exp | |
| 281 | case class Aop(o: String, a1: Exp, a2: Exp) extends Exp | |
| 282 | case class Sequence(e1: Exp, e2: Exp) extends Exp | |
| 283 | case class Bop(o: String, a1: Exp, a2: Exp) extends BExp | |
| 284 | \end{lstlisting}
 | |
| 609 | 285 | |
| 701 | 286 | \end{frame}
 | 
| 287 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 288 | ||
| 289 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 290 | \begin{frame}[fragile,c]
 | |
| 291 | \frametitle{K-(Intermediate)Language}
 | |
| 292 | \footnotesize | |
| 609 | 293 | |
| 701 | 294 | \begin{lstlisting}[language=Scala,numbers=none,xleftmargin=-3mm]
 | 
| 295 | abstract class KExp | |
| 296 | abstract class KVal | |
| 297 | ||
| 702 | 298 | // K-Values | 
| 701 | 299 | case class KVar(s: String) extends KVal | 
| 300 | case class KNum(i: Int) extends KVal | |
| 301 | case class Kop(o: String, v1: KVal, v2: KVal) extends KVal | |
| 302 | case class KCall(o: String, vrs: List[KVal]) extends KVal | |
| 303 | case class KWrite(v: KVal) extends KVal | |
| 304 | ||
| 702 | 305 | // K-Expressions | 
| 701 | 306 | case class KIf(x1: String, e1: KExp, e2: KExp) extends KExp | 
| 307 | case class KLet(x: String, v: KVal, e: KExp) extends KExp | |
| 308 | case class KReturn(v: KVal) extends KExp | |
| 609 | 309 | \end{lstlisting}
 | 
| 310 | ||
| 701 | 311 | \end{frame}
 | 
| 312 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 313 | ||
| 314 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 315 | \begin{frame}[fragile,c]
 | |
| 316 | \frametitle{CPS-Translation}
 | |
| 317 | \small | |
| 318 | ||
| 319 | \begin{lstlisting}[language=Scala,numbers=none]
 | |
| 320 | def CPS(e: Exp)(k: KVal => KExp) : KExp = | |
| 321 |   e match { ... }
 | |
| 322 | \end{lstlisting}
 | |
| 323 | \bigskip\bigskip | |
| 324 | ||
| 702 | 325 | the continuation \texttt{k} can be thought of:\medskip
 | 
| 326 | ||
| 701 | 327 | \small | 
| 328 | \begin{lstlisting}[language=LLVMIR,numbers=none,xleftmargin=30mm,escapeinside={(*@}{@*)}]
 | |
| 329 | let tmp0 = add 1 a in | |
| 330 | let tmp1 = mul (*@$\Box$@*) 5 in | |
| 331 | let tmp2 = add 3 tmp1 in | |
| 332 | let tmp3 = add tmp0 tmp2 in | |
| 333 | KReturn tmp3 | |
| 334 | \end{lstlisting}
 | |
| 609 | 335 | |
| 336 | \end{frame}
 | |
| 701 | 337 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 338 | ||
| 339 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 340 | \begin{frame}[fragile,c]
 | |
| 341 | \frametitle{CPS-Translation}
 | |
| 342 | \small | |
| 343 | ||
| 344 | \begin{lstlisting}[language=Scala,numbers=none]
 | |
| 345 | def CPS(e: Exp)(k: KVal => KExp) : KExp = | |
| 346 |   e match { 
 | |
| 347 | case Var(s) => k(KVar(s)) | |
| 348 | case Num(i) => k(KNum(i)) | |
| 349 | ... | |
| 350 | } | |
| 351 | \end{lstlisting}
 | |
| 352 | \bigskip\bigskip | |
| 353 | ||
| 354 | \small | |
| 355 | \begin{lstlisting}[language=LLVMIR,numbers=none,xleftmargin=30mm,escapeinside={(*@}{@*)}]
 | |
| 356 | let tmp0 = add 1 a in | |
| 357 | let tmp1 = mul (*@$\Box$@*) 5 in | |
| 358 | let tmp2 = add 3 tmp1 in | |
| 359 | let tmp3 = add tmp0 tmp2 in | |
| 360 | KReturn tmp3 | |
| 361 | \end{lstlisting}
 | |
| 362 | ||
| 363 | \end{frame}
 | |
| 364 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 609 | 365 | |
| 366 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 701 | 367 | \begin{frame}[fragile,c]
 | 
| 368 | \frametitle{CPS-Translation}
 | |
| 369 | \small | |
| 609 | 370 | |
| 701 | 371 | \begin{lstlisting}[language=Scala,numbers=none,xleftmargin=-5mm]
 | 
| 372 | def CPS(e: Exp)(k: KVal => KExp) : KExp = e match { 
 | |
| 373 |   case Aop(o, e1, e2) => {
 | |
| 374 |     val z = Fresh("tmp")
 | |
| 375 | CPS(e1)(y1 => | |
| 376 | CPS(e2)(y2 => | |
| 377 | KLet(z, Kop(o, y1, y2), k(KVar(z))))) | |
| 378 | } ... | |
| 379 | } | |
| 609 | 380 | \end{lstlisting}
 | 
| 702 | 381 | \mbox{}\\[-8mm]%
 | 
| 382 | % | |
| 701 | 383 | \begin{lstlisting}[language=LLVMIR,numbers=none,xleftmargin=30mm,escapeinside={(*@}{@*)}]
 | 
| 384 | ... | |
| 385 | let z = op (*@$\Box_{y_1}$@*) (*@$\Box_{y_2}$@*)
 | |
| 386 | let tmp0 = add 1 a in | |
| 702 | 387 | let tmp1 = mul (*@$\Box\!\!\!\!\raisebox{0.6mm}{\alert{\texttt{z}}}$@*) 5 in 
 | 
| 701 | 388 | let tmp2 = add 3 tmp1 in | 
| 389 | let tmp3 = add tmp0 tmp2 in | |
| 390 | KReturn tmp3 | |
| 391 | \end{lstlisting}
 | |
| 609 | 392 | |
| 393 | \end{frame}
 | |
| 701 | 394 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 609 | 395 | |
| 396 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 701 | 397 | \begin{frame}[fragile,c]
 | 
| 398 | \frametitle{CPS-Translation}
 | |
| 399 | \small | |
| 609 | 400 | |
| 701 | 401 | \begin{lstlisting}[language=Scala,numbers=none]
 | 
| 402 | def CPS(e: Exp)(k: KVal => KExp) : KExp = | |
| 403 |   e match { 
 | |
| 404 | case Sequence(e1, e2) => | |
| 405 | CPS(e1)(_ => CPS(e2)(y2 => k(y2))) | |
| 406 | ... | |
| 407 | } | |
| 408 | \end{lstlisting}
 | |
| 702 | 409 | \bigskip | 
| 701 | 410 | |
| 411 | \small | |
| 412 | \begin{lstlisting}[language=LLVMIR,numbers=none,xleftmargin=30mm,escapeinside={(*@}{@*)}]
 | |
| 413 | let tmp0 = add 1 a in | |
| 414 | let tmp1 = mul (*@$\Box$@*) 5 in | |
| 415 | let tmp2 = add 3 tmp1 in | |
| 416 | let tmp3 = add tmp0 tmp2 in | |
| 417 | KReturn tmp3 | |
| 418 | \end{lstlisting}
 | |
| 609 | 419 | |
| 420 | \end{frame}
 | |
| 701 | 421 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 310 
d384fe01d0e8
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
309diff
changeset | 422 | |
| 610 | 423 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 701 | 424 | \begin{frame}[fragile,c]
 | 
| 425 | \frametitle{CPS-Translation}
 | |
| 426 | \small | |
| 427 | ||
| 428 | \begin{lstlisting}[language=Scala,numbers=none,xleftmargin=-3mm]
 | |
| 429 | def CPS(e: Exp)(k: KVal => KExp) : KExp = | |
| 430 |   e match { 
 | |
| 431 | ... | |
| 432 |     case If(Bop(o, b1, b2), e1, e2) => {
 | |
| 433 |       val z = Fresh("tmp")
 | |
| 434 | CPS(b1)(y1 => | |
| 435 | CPS(b2)(y2 => | |
| 436 | KLet(z, Kop(o, y1, y2), | |
| 437 | KIf(z, CPS(e1)(k), CPS(e2)(k))))) | |
| 438 | } | |
| 439 | ... | |
| 440 | } | |
| 441 | \end{lstlisting}
 | |
| 442 | ||
| 443 | \end{frame}
 | |
| 444 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 445 | ||
| 702 | 446 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 447 | \begin{frame}[c,fragile]
 | |
| 448 | \frametitle{The Basic Language, 1980+}
 | |
| 449 | ||
| 450 | \begin{lstlisting}[language={[Visual]Basic},numbers=none]
 | |
| 451 | 5 LET S = 0 | |
| 452 | 10 INPUT V | |
| 453 | 20 PRINT "Input number" | |
| 454 | 30 IF N = 0 THEN GOTO 99 | |
| 455 | 40 FOR I = 1 TO N | |
| 456 | 45 LET S = S + V(I) | |
| 457 | 50 NEXT I | |
| 458 | 60 PRINT S/N | |
| 459 | 70 GOTO 5 | |
| 460 | 99 END | |
| 461 | \end{lstlisting}
 | |
| 462 | ||
| 463 | \hfill ``Spaghetti Code'' | |
| 464 | \end{frame}
 | |
| 465 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 466 | ||
| 467 | ||
| 468 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 469 | \begin{frame}[c,fragile]
 | |
| 470 | \frametitle{Target Specific ASM}
 | |
| 471 | ||
| 472 | \begin{lstlisting}[language={},numbers=none]
 | |
| 473 | llc -march=x86-64 fact.ll | |
| 474 | llc -march=arm fact.ll | |
| 475 | ||
| 476 | ||
| 477 | Intel: xorl %eax, %eax | |
| 478 | ARM: mov pc, lr | |
| 479 | \end{lstlisting}
 | |
| 480 | ||
| 481 | \end{frame}
 | |
| 482 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 701 | 483 | |
| 484 | ||
| 485 | ||
| 486 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 610 | 487 | \begin{frame}[c]
 | 
| 488 | ||
| 489 | \large\bf | |
| 701 | 490 | Using a compiler, \\ | 
| 491 | how can you mount the\\ | |
| 492 | perfect attack against a system? | |
| 610 | 493 | |
| 701 | 494 | \end{frame}
 | 
| 610 | 495 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 496 | ||
| 497 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 498 | \mode<presentation>{
 | |
| 499 | \begin{frame}[c]
 | |
| 500 | ||
| 501 | {\large\bf
 | |
| 502 | What is a \alert{perfect} attack?}\bigskip
 | |
| 503 | ||
| 504 | \begin{enumerate}
 | |
| 505 | \item you can potentially completely take over a target system | |
| 506 | \item your attack is (nearly) undetectable | |
| 507 | \item the victim has (almost) no chance to recover | |
| 508 | \end{enumerate}
 | |
| 509 | ||
| 510 | \end{frame}}
 | |
| 511 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 512 | ||
| 513 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 514 | \mode<presentation>{
 | |
| 515 | \begin{frame}[c]
 | |
| 516 | ||
| 517 | ||
| 518 |   \begin{center}
 | |
| 519 |   \begin{tikzpicture}[scale=1]
 | |
| 520 | ||
| 521 |   \onslide<1->{
 | |
| 522 |   \node (A) at (0,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=17mm] {};
 | |
| 523 |   \node [below right] at (A.north west) {\footnotesize\begin{tabular}{@{}l@{}}
 | |
| 524 |   \only<1,2>{clean}\only<3->{\alert{hacked}}\\compiler\end{tabular}};}
 | |
| 525 | ||
| 526 | ||
| 527 |   \onslide<2->{
 | |
| 528 |   \node (B) at (-2,2)  [draw=black, rectangle, very thick, minimum height=10mm, minimum width=12mm] {};
 | |
| 529 |   \node [below right] at (B.north west) {\footnotesize\begin{tabular}{@{}l@{}}login\\(src)\end{tabular}};
 | |
| 530 | ||
| 531 |   \node (C) at (2,2)  [draw=black, rectangle, very thick, minimum height=10mm, minimum width=12mm] {};
 | |
| 532 |   \node [below right] at (C.north west) {\footnotesize\begin{tabular}{@{}l@{}}login\\(bin)\end{tabular}};
 | |
| 533 | ||
| 534 | \draw[->, line width=2mm] (B) -- (C); | |
| 535 | } | |
| 536 | ||
| 537 |  \onslide<3->{\node [above left=-1.5mm] at (C.south east) {\footnotesize \alert{$\blacksquare$}};}
 | |
| 538 | ||
| 539 |   \end{tikzpicture}
 | |
| 540 |   \end{center}
 | |
| 541 | ||
| 542 | \end{frame}}
 | |
| 543 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 544 | ||
| 545 | ||
| 546 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 547 | \mode<presentation>{
 | |
| 548 | \begin{frame}[c]
 | |
| 549 | ||
| 550 |   \begin{center}
 | |
| 551 |   \begin{tikzpicture}[scale=1]
 | |
| 552 | ||
| 553 |   \onslide<1->{
 | |
| 554 |   \node (A) at (0,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
 | |
| 555 |   \node [below right] at (A.north west) {\small V0.01};
 | |
| 556 |   \node [below right] (A1) at (A.south west) {\small Scala};
 | |
| 557 |   \node [below right] (A1) at (A1.south west) {\small\textcolor{gray}{host language}};
 | |
| 558 |   \node [above right] at (A.north west) {my compiler (src)};}
 | |
| 559 | ||
| 560 |   \onslide<2->{
 | |
| 561 |   \node (B) at (1.8,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
 | |
| 562 |   \node [below right] at (B.north west) {\small V0.02};
 | |
| 563 |   \node [below right] at (B.south west) {\small Scala};
 | |
| 564 |   \node at (3,0) {\ldots};
 | |
| 565 | ||
| 566 |   \node (C) at (5,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
 | |
| 567 |   \node [below right] at (C.north west) {\small V1.00};
 | |
| 568 |   \node [below right] at (C.south west) {\small Scala};}
 | |
| 569 | ||
| 570 |   \onslide<3->{
 | |
| 571 |   \node (D) at (6.8,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
 | |
| 572 |   \node [below right] at (D.north west) {\small V1.00};
 | |
| 573 | ||
| 574 |   \node (E) at (6.8,2)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
 | |
| 575 |   \node [below right] at (E.north west) {\small V1.01};}
 | |
| 576 | ||
| 577 |   \onslide<4->{
 | |
| 578 |   \node (F) at (8.6,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
 | |
| 579 |   \node [below right] at (F.north west) {\small V1.01};
 | |
| 580 | ||
| 581 |   \node (G) at (8.6,2)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
 | |
| 582 |   \node [below right] at (G.north west) {\small V1.02};
 | |
| 583 |   \node at (9.8,0) {\ldots};
 | |
| 584 |   \node at (9.8,2) {\ldots};
 | |
| 585 |   \node at (8,-2) {\textcolor{gray}{\begin{tabular}{@{}l@{}}no host language\\needed\end{tabular}}};
 | |
| 586 | } | |
| 587 | ||
| 588 |   \end{tikzpicture}
 | |
| 589 |   \end{center}
 | |
| 590 | ||
| 591 | \end{frame}}
 | |
| 592 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 593 | ||
| 594 | ||
| 595 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 596 |   \mode<presentation>{
 | |
| 597 |   \begin{frame}<1-3>
 | |
| 598 |   \frametitle{\LARGE\begin{tabular}{c}Hacking Compilers 
 | |
| 599 |   \end{tabular}}
 | |
| 600 | ||
| 601 | %Why is it so paramount to have a small trusted code base (TCB)? | |
| 602 | \bigskip\bigskip | |
| 603 | ||
| 604 |   \begin{columns}
 | |
| 605 |   \begin{column}{2.7cm}
 | |
| 606 |   \begin{minipage}{2.5cm}%
 | |
| 607 |   \begin{tabular}{c@ {}}
 | |
| 608 |   \includegraphics[scale=0.2]{../pics/ken-thompson.jpg}\\[-1.8mm]
 | |
| 609 | \footnotesize Ken Thompson\\[-1.8mm] | |
| 610 | \footnotesize Turing Award, 1983\\ | |
| 611 |   \end{tabular}
 | |
| 612 |   \end{minipage}
 | |
| 613 |   \end{column}
 | |
| 614 |   \begin{column}{9cm}
 | |
| 615 |   \begin{tabular}{l@ {\hspace{1mm}}p{8cm}}
 | |
| 616 | ||
| 617 | & Ken Thompson showed how to hide a Trojan Horse in a | |
| 618 |   compiler \textcolor{red}{without} leaving any traces in the source code.\\[2mm]
 | |
| 619 | ||
| 620 | & No amount of source level verification will protect | |
| 621 | you from such Thompson-hacks.\\[2mm] | |
| 622 | ||
| 623 |   \end{tabular}
 | |
| 624 |   \end{column}
 | |
| 625 |   \end{columns}
 | |
| 626 | ||
| 627 |   \only<2>{
 | |
| 628 |   \begin{textblock}{6}(4,2)
 | |
| 629 |   \begin{tikzpicture}
 | |
| 630 | \draw (0,0) node[inner sep=3mm,fill=cream, ultra thick, draw=red, rounded corners=2mm] | |
| 631 |   {\normalsize
 | |
| 632 |   \begin{minipage}{8cm}
 | |
| 633 |   \begin{quote}
 | |
| 634 |   \includegraphics[scale=0.05]{../pics/evil.png}
 | |
| 635 |   \begin{enumerate}
 | |
| 636 | \item[1)] Assume you ship the compiler as binary and also with sources. | |
| 637 | \item[2)] Make the compiler aware when it compiles itself. | |
| 638 | \item[3)] Add the Trojan horse. | |
| 639 | \item[4)] Compile. | |
| 640 | \item[5)] Delete Trojan horse from the sources of the compiler. | |
| 641 |   \item[6)] Go on holiday for the rest of your life. ;o)\\[-7mm]\mbox{}
 | |
| 642 |   \end{enumerate}
 | |
| 643 |   \end{quote}
 | |
| 644 |   \end{minipage}};
 | |
| 645 |   \end{tikzpicture}
 | |
| 646 |   \end{textblock}}
 | |
| 647 | ||
| 648 |   \end{frame}}
 | |
| 649 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 650 | ||
| 701 | 651 | |
| 652 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 653 |   \begin{frame}[c]
 | |
| 654 |   \frametitle{Dijkstra on Testing}
 | |
| 655 | ||
| 656 |   \begin{bubble}[10cm]
 | |
| 657 | ``Program testing can be a very effective way to show the | |
| 658 | presence of bugs, but it is hopelessly inadequate for showing | |
| 659 | their absence.'' | |
| 660 |   \end{bubble}\bigskip
 | |
| 661 | ||
| 662 | \small | |
| 663 | What is good about compilers: the either seem to work, | |
| 664 | or go horribly wrong (most of the time). | |
| 665 | ||
| 666 |   \end{frame}
 | |
| 667 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 668 | ||
| 669 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 670 | \begin{frame}[c]
 | |
| 671 | \frametitle{\Large Proving Programs to be Correct}
 | |
| 672 | ||
| 673 | \begin{bubble}[10cm]
 | |
| 674 | \small | |
| 675 | {\bf Theorem:} There are infinitely many prime 
 | |
| 676 | numbers.\medskip\\ | |
| 677 | ||
| 678 | {\bf Proof} \ldots\\
 | |
| 679 | \end{bubble}\bigskip
 | |
| 680 | ||
| 681 | ||
| 682 | similarly\bigskip | |
| 683 | ||
| 684 | \begin{bubble}[10cm]
 | |
| 685 | \small | |
| 686 | {\bf Theorem:} The program is doing what 
 | |
| 687 | it is supposed to be doing.\medskip | |
| 688 | ||
| 689 | {\bf Long, long proof} \ldots\\
 | |
| 690 | \end{bubble}\bigskip\medskip
 | |
| 691 | ||
| 692 | \small This can be a gigantic proof. The only hope is to have | |
| 693 | help from the computer. `Program' is here to be understood to be | |
| 694 | quite general (compiler, OS, \ldots). | |
| 695 | ||
| 696 | \end{frame}
 | |
| 697 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 698 | ||
| 699 | ||
| 700 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 701 | ||
| 702 | \begin{frame}[c]
 | |
| 703 | \frametitle{Can This Be Done?}
 | |
| 704 | ||
| 705 | \begin{itemize}
 | |
| 706 | \item in 2008, verification of a small C-compiler | |
| 707 | \begin{itemize}
 | |
| 708 | \item ``if my input program has a certain behaviour, then the compiled machine code has the same behaviour'' | |
| 709 | \item is as good as \texttt{gcc -O1}, but much, much less buggy 
 | |
| 710 | \end{itemize}
 | |
| 711 | \end{itemize}
 | |
| 712 | ||
| 713 | \begin{center}
 | |
| 714 |   \includegraphics[scale=0.12]{../pics/compcert.png}
 | |
| 715 | \end{center}
 | |
| 716 | ||
| 717 | \end{frame}
 | |
| 718 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 719 | ||
| 720 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 721 | \begin{frame}[t]
 | |
| 722 | \frametitle{Fuzzy Testing C-Compilers}
 | |
| 723 | ||
| 724 | \begin{itemize}
 | |
| 725 | \item tested GCC, LLVM and others by randomly generating | |
| 726 | C-programs | |
| 727 | \item found more than 300 bugs in GCC and also | |
| 728 | many in LLVM (some of them highest-level critical)\bigskip | |
| 729 | \item about CompCert: | |
| 730 | ||
| 731 | \begin{bubble}[10.7cm]\small ``The striking thing about our CompCert
 | |
| 732 | results is that the middle-end bugs we found in all other | |
| 733 | compilers are absent. As of early 2011, the under-development | |
| 734 | version of CompCert is the only compiler we have tested for | |
| 735 | which Csmith cannot find wrong-code errors. This is not for | |
| 736 | lack of trying: we have devoted about six CPU-years to the | |
| 737 | task.'' | |
| 738 | \end{bubble} 
 | |
| 739 | \end{itemize}
 | |
| 740 | ||
| 741 | \end{frame}
 | |
| 742 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 743 | ||
| 744 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 745 | ||
| 746 | \begin{frame}[c]
 | |
| 747 | \frametitle{Next Week}
 | |
| 748 | ||
| 749 | \begin{itemize}
 | |
| 750 | \item Revision Lecture\medskip | |
| 751 | \item How many  strings are in $\bl{L(a^*)}$?\pause\medskip
 | |
| 752 | \item How many  strings are in $\bl{L((a + b)^*)}$?\\ Are there more than
 | |
| 753 |   in $\bl{L(a^*)}$?
 | |
| 754 | \end{itemize}
 | |
| 755 | ||
| 756 | ||
| 757 | ||
| 758 | \end{frame}
 | |
| 759 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 760 | ||
| 761 | ||
| 762 | ||
| 763 | \end{document}
 | |
| 764 | ||
| 765 | %%% Local Variables: | |
| 766 | %%% mode: latex | |
| 767 | %%% TeX-master: t | |
| 768 | %%% End: | |
| 769 | ||
| 770 | ||
| 771 | ||
| 772 | ||
| 773 | ||
| 610 | 774 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 
| 775 |   \begin{frame}[c]
 | |
| 776 | ||
| 777 |   \begin{center}
 | |
| 778 |   \includegraphics[scale=0.6]{../pics/bridge-limits.png}
 | |
| 779 |   \end{center}
 | |
| 780 | ||
| 781 |   \end{frame}
 | |
| 782 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 783 | ||
| 784 | ||
| 785 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 786 | \begin{frame}[c]
 | |
| 787 | \frametitle{Compilers \& Boeings 777}
 | |
| 788 | ||
| 789 | First flight in 1994. They want to achieve triple redundancy in hardware | |
| 790 | faults.\bigskip | |
| 791 | ||
| 792 | They compile 1 Ada program to\medskip | |
| 793 | ||
| 794 | \begin{itemize}
 | |
| 795 | \item Intel 80486 | |
| 796 | \item Motorola 68040 (old Macintosh's) | |
| 797 | \item AMD 29050 (RISC chips used often in laser printers) | |
| 798 | \end{itemize}\medskip
 | |
| 799 | ||
| 800 | using 3 independent compilers.\bigskip\pause | |
| 801 | ||
| 802 | \small Airbus uses C and static analysers. Recently started using CompCert. | |
| 803 | ||
| 804 | \end{frame}
 | |
| 805 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 806 | ||
| 807 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 808 | \begin{frame}[c]
 | |
| 809 | \frametitle{Goal}
 | |
| 810 | ||
| 811 | Remember the Bridges example? | |
| 812 | ||
| 813 | \begin{itemize}
 | |
| 814 | \item Can we look at our programs and somehow ensure | |
| 815 | they are bug free/correct?\pause\bigskip | |
| 816 | ||
| 817 | \item Very hard: Anything interesting about programs is equivalent | |
| 818 | to the Halting Problem, which is undecidable.\pause\bigskip | |
| 819 | ||
| 820 | \item \alert{Solution:} We avoid this ``minor'' obstacle by
 | |
| 821 | being as close as possible of deciding the halting | |
| 822 | problem, without actually deciding the halting problem. | |
| 823 | \small$\quad\Rightarrow$ yes, no, don't know (static analysis) | |
| 824 | \end{itemize}
 | |
| 825 | ||
| 826 | \end{frame}
 | |
| 827 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 828 | ||
| 829 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 830 |   \begin{frame}[c]
 | |
| 831 |   \frametitle{What is Static Analysis?}
 | |
| 832 | ||
| 833 |   \begin{center}
 | |
| 834 |   \includegraphics[scale=0.4]{../pics/state.png}
 | |
| 835 |   \end{center}
 | |
| 836 | ||
| 837 |   \begin{itemize}
 | |
| 838 | \item depending on some initial input, a program | |
| 839 | (behaviour) will ``develop'' over time. | |
| 840 |   \end{itemize}
 | |
| 841 | ||
| 842 |   \end{frame}
 | |
| 843 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 844 | ||
| 845 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 846 |   \begin{frame}[c]
 | |
| 847 |   \frametitle{What is Static Analysis?}
 | |
| 848 | ||
| 849 |   \begin{center}
 | |
| 850 |   \includegraphics[scale=0.4]{../pics/state2.png}
 | |
| 851 |   \end{center}
 | |
| 852 | ||
| 853 |   \end{frame}
 | |
| 854 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 855 | ||
| 856 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 857 |   \begin{frame}[c]
 | |
| 858 |   \frametitle{What is Static Analysis?}
 | |
| 859 | ||
| 860 |   \begin{center}
 | |
| 861 |   \includegraphics[scale=0.4]{../pics/state3.jpg}
 | |
| 862 |   \end{center}
 | |
| 863 | ||
| 864 |   \end{frame}
 | |
| 865 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 866 | ||
| 867 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 868 |   \begin{frame}[c]
 | |
| 869 |   \frametitle{What is Static Analysis?}
 | |
| 870 | ||
| 871 |   \begin{center}
 | |
| 872 |   \includegraphics[scale=0.4]{../pics/state4.jpg}
 | |
| 873 |   \end{center}
 | |
| 874 | ||
| 875 |   \begin{itemize}
 | |
| 876 | \item to be avoided | |
| 877 |   \end{itemize}
 | |
| 878 | ||
| 879 |   \end{frame}
 | |
| 880 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 881 | ||
| 882 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 883 |   \begin{frame}[c]
 | |
| 884 |   \frametitle{What is Static Analysis?}
 | |
| 885 | ||
| 886 |   \begin{center}
 | |
| 887 |   \includegraphics[scale=0.4]{../pics/state5.png}
 | |
| 888 |   \end{center}
 | |
| 889 | ||
| 890 |   \begin{itemize}
 | |
| 891 | \item this needs more work | |
| 892 |   \end{itemize}
 | |
| 893 | ||
| 894 |   \end{frame}
 | |
| 895 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 896 | ||
| 897 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 898 |   \begin{frame}[c]
 | |
| 899 |   \frametitle{What is Static Analysis?}
 | |
| 900 | ||
| 901 |   \begin{center}
 | |
| 902 |   \includegraphics[scale=0.4]{../pics/state6.png}
 | |
| 903 |   \end{center}
 | |
| 904 | ||
| 905 |   \end{frame}
 | |
| 906 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 907 | ||
| 908 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 909 |   \begin{frame}[c,fragile]
 | |
| 910 |     \frametitle{\Large\begin{tabular}{c}Concrete Example:\\[-1mm]
 | |
| 911 |                   Are Vars Definitely Initialised?\end{tabular}}
 | |
| 912 | ||
| 913 | Assuming \texttt{x} is initialised, what about \texttt{y}?\bigskip
 | |
| 914 | ||
| 915 | Prog.~1:\\ | |
| 916 | \begin{lstlisting}[numbers=none,
 | |
| 917 | basicstyle=\ttfamily, | |
| 918 | language=While,xleftmargin=3mm] | |
| 919 | if x < 1 then y := x else y := x + 1; | |
| 920 | y := y + 1 | |
| 921 | \end{lstlisting}\medskip     
 | |
| 922 | ||
| 923 | Prog.~2:\\ | |
| 924 | \begin{lstlisting}[numbers=none,
 | |
| 925 | basicstyle=\ttfamily, | |
| 926 | language=While,xleftmargin=3mm] | |
| 927 | if x < x then y := y + 1 else y := x; | |
| 928 | y := y + 1 | |
| 929 | \end{lstlisting}            
 | |
| 930 | ||
| 931 |   \end{frame}
 | |
| 932 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 933 | ||
| 934 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 935 |   \begin{frame}[c,fragile]
 | |
| 936 |     \frametitle{\Large\begin{tabular}{c}Concrete Example:\\[-1mm]
 | |
| 937 |                   Are Vars Definitely Initialised?\end{tabular}}
 | |
| 938 | ||
| 939 | What should the rules be for deciding when a | |
| 940 | variable is initialised?\bigskip\pause | |
| 941 | ||
| 942 | \begin{itemize}
 | |
| 943 | \item variable \texttt{x} is definitely initialized after
 | |
| 944 |   \texttt{skip}\\
 | |
| 945 |   iff \texttt{x} is definitely initialized before \texttt{skip}.
 | |
| 946 | \end{itemize}
 | |
| 947 | ||
| 948 | \end{frame}
 | |
| 949 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 950 | ||
| 951 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 952 |   \begin{frame}[c,fragile]
 | |
| 953 | %    \frametitle{\Large\begin{tabular}{c}Concrete Example:\\[-1mm]
 | |
| 954 | %                  Are Vars Definitely Initialised?\end{tabular}}
 | |
| 955 | ||
| 956 | $\bl{A}$ is the set of definitely defined variables:
 | |
| 957 | ||
| 958 | \begin{center}
 | |
| 959 | \begin{tabular}{c}
 | |
| 612 | 960 |   \bl{\infer{\mbox{}}{A\triangleright\texttt{skip}\triangleright{}A}}\qquad
 | 
| 961 |   \bl{\infer{vars(a) \subseteq A}{A\triangleright
 | |
| 962 |   (\texttt{x\,:=\,a})\triangleright\{x\}\cup A}}
 | |
| 610 | 963 | \medskip\\\pause | 
| 964 | ||
| 612 | 965 |   \bl{\infer{A_1\triangleright{}s_1\triangleright{}A_2
 | 
| 966 |   \quad A_2\triangleright{}s_2\triangleright{}A_3}
 | |
| 967 |   {A_1\triangleright{}(s_1 ; s_2)\triangleright{}A_3}}
 | |
| 610 | 968 | \medskip\\\pause | 
| 969 | ||
| 612 | 970 |   \bl{\infer{vars(b)\subseteq A\quad A\triangleright{}s_1\triangleright{}A_1
 | 
| 971 |   \quad A\triangleright{}s_2\triangleright{}A_2}
 | |
| 972 |   {A\triangleright(\texttt{if}\;b\;\texttt{then}\;s_1\;\texttt{else}\;s_2)\triangleright{}A_1\cap A_2}}
 | |
| 610 | 973 | \medskip\\\pause | 
| 974 | ||
| 612 | 975 |   \bl{\infer{vars(b)\subseteq A\quad A\triangleright{}s\triangleright{}A'}
 | 
| 976 |   {A\triangleright(\texttt{while}\;b\;\texttt{do}\;s)\triangleright{}A}}\pause
 | |
| 610 | 977 | \end{tabular}  
 | 
| 978 | \end{center}
 | |
| 979 | ||
| 980 | \hfill we start with $\bl{A = \{\}}$
 | |
| 981 | \end{frame}
 | |
| 982 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
| 983 |