slides/slides09.tex
changeset 333 cf02511469d6
parent 332 8eab185fb187
child 334 6f08b13c0242
equal deleted inserted replaced
332:8eab185fb187 333:cf02511469d6
     1 \documentclass[dvipsnames,14pt,t]{beamer}
     1 \documentclass[dvipsnames,14pt,t]{beamer}
     2 \usepackage{../slides}
     2 \usepackage{../slides}
     3 \usepackage{../langs}
     3 \usepackage{../langs}
     4 \usepackage{../graphics}
     4 \usepackage{../graphics}
     5 \usepackage{../grammar}
     5 \usepackage{../grammar}
       
     6 \usepackage{soul}
       
     7 
       
     8 \makeatletter
       
     9 \newenvironment<>{btHighlight}[1][]
       
    10 {\begin{onlyenv}#2\begingroup\tikzset{bt@Highlight@par/.style={#1}}\begin{lrbox}{\@tempboxa}}
       
    11 {\end{lrbox}\bt@HL@box[bt@Highlight@par]{\@tempboxa}\endgroup\end{onlyenv}}
       
    12 
       
    13 \newcommand<>\btHL[1][]{%
       
    14   \only#2{\begin{btHighlight}[#1]\bgroup\aftergroup\bt@HL@endenv}%
       
    15 }
       
    16 \def\bt@HL@endenv{%
       
    17   \end{btHighlight}%   
       
    18   \egroup
       
    19 }
       
    20 \newcommand{\bt@HL@box}[2][]{%
       
    21   \tikz[#1]{%
       
    22     \pgfpathrectangle{\pgfpoint{1pt}{0pt}}{\pgfpoint{\wd #2}{\ht #2}}%
       
    23     \pgfusepath{use as bounding box}%
       
    24     \node[anchor=base west, fill=orange!30,outer sep=0pt,inner xsep=1pt, inner ysep=0pt, rounded corners=3pt, minimum height=\ht\strutbox+1pt,#1]{\raisebox{1pt}{\strut}\strut\usebox{#2}};
       
    25   }%
       
    26 }
       
    27 \makeatother
       
    28 
     6 
    29 
     7 % beamer stuff 
    30 % beamer stuff 
     8 \renewcommand{\slidecaption}{APP 09, King's College London}
    31 \renewcommand{\slidecaption}{APP 09, King's College London}
     9 \newcommand{\bl}[1]{\textcolor{blue}{#1}}
    32 \newcommand{\bl}[1]{\textcolor{blue}{#1}}
    10 
    33 
   108 similarly\bigskip
   131 similarly\bigskip
   109 
   132 
   110 \begin{bubble}[10cm]
   133 \begin{bubble}[10cm]
   111 \small
   134 \small
   112 {\bf Theorem:} The program is doing what 
   135 {\bf Theorem:} The program is doing what 
   113 it is supposed to be doing.\medskip
   136 it is sup+ed to be doing.\medskip
   114 
   137 
   115 {\bf Long, long proof} \ldots\\
   138 {\bf Long, long proof} \ldots\\
   116 \end{bubble}\bigskip\medskip
   139 \end{bubble}\bigskip\medskip
   117 
   140 
   118 \small This can be a gigantic proof. The only hope is to have
   141 \small This can be a gigantic proof. The only hope is to have
   689   \item working purely in the \emph{dynamic world} does not work -\!-\!- infinite state space\bigskip
   712   \item working purely in the \emph{dynamic world} does not work -\!-\!- infinite state space\bigskip
   690 
   713 
   691   \item working purely on \emph{static} policies also does not\\ work -\!-\!- because of over approximation
   714   \item working purely on \emph{static} policies also does not\\ work -\!-\!- because of over approximation
   692   \smallskip
   715   \smallskip
   693   \begin{itemize}
   716   \begin{itemize}
   694   \item suppose a tainted file has type \emph{bin} and
   717   \item sup+e a tainted file has type \emph{bin} and
   695   \item there is a role \bl{$r$} which can both read and write \emph{bin}-files\pause
   718   \item there is a role \bl{$r$} which can both read and write \emph{bin}-files\pause
   696   \item then we would conclude that this tainted file can spread\medskip\pause
   719   \item then we would conclude that this tainted file can spread\medskip\pause
   697   \item but if there is no process with role \bl{$r$} and it will never been
   720   \item but if there is no process with role \bl{$r$} and it will never been
   698   created, then the file actually does not spread
   721   created, then the file actually does not spread
   699   \end{itemize}\bigskip\pause
   722   \end{itemize}\bigskip\pause
   740 
   763 
   741 \item Very hard: Anything interesting about programs is equivalent
   764 \item Very hard: Anything interesting about programs is equivalent
   742 to halting problem, which is undecidable.\pause\bigskip
   765 to halting problem, which is undecidable.\pause\bigskip
   743 
   766 
   744 \item \alert{Solution:} We avoid this ``minor'' obstacle by
   767 \item \alert{Solution:} We avoid this ``minor'' obstacle by
   745       being as close as possible of deciding the halting
   768       being as close as +sible of deciding the halting
   746       problem, without actually deciding the halting problem.
   769       problem, without actually deciding the halting problem.
   747       $\quad\Rightarrow$ static analysis
   770       $\quad\Rightarrow$ static analysis
   748 \end{itemize}
   771 \end{itemize}
   749 
   772 
   750 \end{frame}
   773 \end{frame}
   871 \begin{textblock}{0}(7.8,2.5)
   894 \begin{textblock}{0}(7.8,2.5)
   872 \small
   895 \small
   873 \begin{bubble}[5.6cm]
   896 \begin{bubble}[5.6cm]
   874 \begin{lstlisting}[numbers=none,
   897 \begin{lstlisting}[numbers=none,
   875                    basicstyle=\ttfamily,
   898                    basicstyle=\ttfamily,
   876                    language={},xleftmargin=3]
   899                    language={},xleftmargin=3mm]
   877       a := 1
   900       a := 1
   878       n := 5 
   901       n := 5 
   879 top:  jump? n = 0 done 
   902 top:  jump? n = 0 done 
   880       a := a * n 
   903       a := a * n 
   881       n := n + -1 
   904       n := n + -1 
   899          | \meta{Exp} = \meta{Exp} 
   922          | \meta{Exp} = \meta{Exp} 
   900          | \meta{num}
   923          | \meta{num}
   901          | \meta{var}\\
   924          | \meta{var}\\
   902 : \meta{Stmt} ::= \meta{label} :
   925 : \meta{Stmt} ::= \meta{label} :
   903          | \meta{var} := \meta{Exp}
   926          | \meta{var} := \meta{Exp}
   904          | jump? \meta{Exp} \meta{label}
   927          | jmp? \meta{Exp} \meta{label}
   905          | goto \meta{label}\\
   928          | goto \meta{label}\\
   906 : \meta{Prog} ::= \meta{Stmt} \ldots\\
   929 : \meta{Prog} ::= \meta{Stmt} \ldots\\
   907 \end{plstx}}
   930 \end{plstx}}
   908 
   931 
   909 \begin{textblock}{0}(7.8,3.5)
   932 \begin{textblock}{0}(7.8,3.5)
   910 \small
   933 \small
   911 \begin{bubble}[5.6cm]
   934 \begin{bubble}[5.6cm]
   912 \begin{lstlisting}[numbers=none,
   935 \begin{lstlisting}[numbers=none,
   913                    basicstyle=\ttfamily,
   936                    basicstyle=\ttfamily,
   914                    language={},xleftmargin=3]
   937                    language={},xleftmargin=3mm]
   915       n := 6
   938       n := 6
   916       m1 := 0
   939       m1 := 0
   917       m2 := 1
   940       m2 := 1
   918 top:  jump? n = 0 done
   941 top:  jmp? n = 0 done
   919       tmp := m2
   942       tmp := m2
   920       m2 := m1 + m2
   943       m2 := m1 + m2
   921       m1 := tmp
   944       m1 := tmp
   922       n := n + -1
   945       n := n + -1
   923       goto top
   946       goto top
   927 \end{textblock}
   950 \end{textblock}
   928 
   951 
   929 \end{frame}
   952 \end{frame}
   930 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   953 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   931 
   954 
       
   955 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   956 \begin{frame}[fragile]
       
   957 \frametitle{Eval}
       
   958 \mbox{}\\[-18mm]\mbox{}
       
   959 
       
   960 \small
       
   961 \begin{center}
       
   962 \bl{\begin{tabular}{lcl}
       
   963 $[n]_{env}$ & $\dn$ & $n$\\
       
   964 $[x]_{env}$ & $\dn$ & $env(x)$\\
       
   965 $[e_1 + e_2]_{env}$ & $\dn$ & $[e_1]_{env} + [e_2]_{env}$\\
       
   966 $[e_1 * e_2]_{env}$ & $\dn$ & $[e_1]_{env} * [e_2]_{env}$\\
       
   967 $[e_1 = e_2]_{env}$ & $\dn$ & 
       
   968 $\begin{cases}
       
   969 1 & \text{if}\quad[e_1]_{env} = [e_2]_{env}\\
       
   970 0 & \text{otherwise}
       
   971 \end{cases}$\\
       
   972 \end{tabular}}
       
   973 \end{center}
       
   974 
       
   975 \footnotesize
       
   976 \begin{lstlisting}[language=Scala,numbers=none,xleftmargin=-5mm]
       
   977 def eval_exp(e: Exp, env: Env) : Int = e match {
       
   978   case Num(n) & n
       
   979   case Var(x) & env(x)
       
   980   case Plus(e1, e2) & eval_exp(e1, env) + eval_exp(e2, env)
       
   981   case Times(e1, e2) & eval_exp(e1, env) * eval_exp(e2, env)
       
   982   case Equ(e1, e2) & 
       
   983     if (eval_exp(e1, env) == eval_exp(e2, env)) 1 else 0
       
   984 }
       
   985 \end{lstlisting}
       
   986 
       
   987 \end{frame}
       
   988 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   989 
       
   990 
       
   991 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   992 \begin{frame}[fragile]
       
   993 \small
       
   994 A program
       
   995 \begin{bubble}[6cm]\footnotesize
       
   996 \begin{lstlisting}[numbers=none,
       
   997                    language={},
       
   998                    basicstyle=\ttfamily,
       
   999                    xleftmargin=1mm]
       
  1000       a := 1
       
  1001       n := 5 
       
  1002 top:  jmp? n = 0 done 
       
  1003       a := a * n 
       
  1004       n := n + -1 
       
  1005       goto top 
       
  1006 done:
       
  1007 \end{lstlisting}
       
  1008 \end{bubble}
       
  1009 
       
  1010 Some snippets
       
  1011 
       
  1012 \footnotesize
       
  1013 \begin{columns}
       
  1014 \begin{column}[t]{5cm}
       
  1015 \begin{bubble}[4.5cm]
       
  1016 \begin{lstlisting}[numbers=none,
       
  1017                    basicstyle=\ttfamily,
       
  1018                    language={},xleftmargin=1mm]
       
  1019 ""    a := 1
       
  1020       n := 5 
       
  1021 top:  jmp? n = 0 done 
       
  1022       a := a * n 
       
  1023       n := n + -1 
       
  1024       goto top 
       
  1025 done:
       
  1026 \end{lstlisting}
       
  1027 \end{bubble}
       
  1028 \end{column}
       
  1029 \begin{column}[t]{5cm}
       
  1030 \begin{bubble}[4.5cm]
       
  1031 \begin{lstlisting}[numbers=none,
       
  1032                    basicstyle=\ttfamily,
       
  1033                    language={},xleftmargin=1mm]
       
  1034 top:  jmp? n = 0 done 
       
  1035       a := a * n 
       
  1036       n := n + -1 
       
  1037       goto top 
       
  1038 done:
       
  1039 \end{lstlisting}
       
  1040 \end{bubble}
       
  1041 \end{column}
       
  1042 \begin{column}[t]{2cm}
       
  1043 \begin{bubble}[1.1cm]
       
  1044 \begin{lstlisting}[numbers=none,
       
  1045                    basicstyle=\ttfamily,
       
  1046                    language={},xleftmargin=1mm]
       
  1047 done:
       
  1048 \end{lstlisting}
       
  1049 \end{bubble}
       
  1050 \end{column}
       
  1051 \end{columns}
       
  1052 
       
  1053 \end{frame}
       
  1054 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
  1055 
       
  1056 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
  1057 \begin{frame}[fragile]
       
  1058 \frametitle{Eval for Stmts}
       
  1059 \mbox{}\\[-12mm]\mbox{}
       
  1060 
       
  1061 Let \bl{$sn$} be the snippets of a program
       
  1062 
       
  1063 \small
       
  1064 \begin{center}
       
  1065 \bl{\begin{tabular}{lcl}
       
  1066 $[\texttt{nil}]_{env}$ & $\dn$ & $env$\medskip\\
       
  1067 $[\texttt{Label}(l:)::rest]_{env}$ & $\dn$ & $[rest]_{env}$\medskip\\
       
  1068 $[x \,\texttt{:=}\, e::rest]_{env}$ & $\dn$ & 
       
  1069 $[rest]_{(env[x:= [e]_{env}])}$\medskip\\
       
  1070 $[\texttt{jmp?}\;e\;l::rest]_{env}$ & $\dn$ & 
       
  1071 $\begin{cases}
       
  1072 [sn(l)]_{env} & \text{if}\quad[e]_{env} = 1\\
       
  1073 [rest]_{env}  & \text{otherwise}
       
  1074 \end{cases}$\medskip\\
       
  1075 $[\texttt{goto}\;l::rest]_{env}$ & $\dn$ & $[sn(l)]_{env}$\\
       
  1076 \end{tabular}}
       
  1077 \end{center}\bigskip
       
  1078 
       
  1079 Start with \bl{$[sn(\mbox{\code{""}})]_{\varnothing}$}
       
  1080 
       
  1081 \end{frame}
       
  1082 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
  1083 
       
  1084 
       
  1085 
       
  1086 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
  1087 \begin{frame}[fragile]
       
  1088 \frametitle{Eval in Code}
       
  1089 
       
  1090 \footnotesize
       
  1091 \begin{lstlisting}[language=Scala,numbers=none,xleftmargin=-5mm]
       
  1092 def eval(sn: Snips) : Env = {
       
  1093   def eval_stmts(sts: Stmts, env: Env) : Env = sts match {
       
  1094     case Nil & env
       
  1095     case Label(l)::rest & eval_stmts(rest, env)
       
  1096     case Assign(x, e)::rest & 
       
  1097       eval_stmts(rest, env + (x -> eval_exp(e, env)))
       
  1098     case Jump(b, l)::rest & 
       
  1099       if (eval_exp(b, env) == 1) eval_stmts(sn(l), env) 
       
  1100       else eval_stmts(rest, env)
       
  1101     case Goto(l)::rest & eval_stmts(sn(l), env)
       
  1102   }
       
  1103 
       
  1104   eval_stmts(sn(""), Map())
       
  1105 }
       
  1106 \end{lstlisting}
       
  1107 
       
  1108 \end{frame}
       
  1109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
  1110 
       
  1111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
  1112 \begin{frame}[fragile]
       
  1113 \frametitle{The Idea}
       
  1114 \small
       
  1115 \mbox{}\bigskip\\
       
  1116 
       
  1117 \begin{columns}
       
  1118 \begin{column}{5cm}
       
  1119 \begin{bubble}[4.5cm]\footnotesize
       
  1120 \begin{lstlisting}[numbers=none,
       
  1121                    language={},
       
  1122                    basicstyle=\ttfamily,
       
  1123                    xleftmargin=1mm]
       
  1124       a := 1
       
  1125       n := 5 
       
  1126 top:  jmp? n = 0 done 
       
  1127       a := a * n 
       
  1128       n := n + -1 
       
  1129       goto top 
       
  1130 done:
       
  1131 \end{lstlisting}
       
  1132 \end{bubble}
       
  1133 \end{column}
       
  1134 
       
  1135 \begin{column}{1cm}
       
  1136 \raisebox{-20mm}{\LARGE\bf$\Rightarrow$}
       
  1137 \end{column}
       
  1138 \begin{column}{6cm}
       
  1139 \begin{bubble}[4.7cm]\footnotesize
       
  1140 \begin{lstlisting}[numbers=none,
       
  1141                    language={},
       
  1142                    basicstyle=\ttfamily,
       
  1143                    xleftmargin=1mm,
       
  1144                    escapeinside={(*@}{@*)}]
       
  1145       a := (*@\hl{'+'}@*)
       
  1146       n := (*@\hl{'+'}@*) 
       
  1147 top:  jmp? n = (*@\hl{'0'}@*) done 
       
  1148       a := a * n 
       
  1149       n := n + (*@\hl{'-'}@*) 
       
  1150       goto top 
       
  1151 done:
       
  1152 \end{lstlisting}
       
  1153 \end{bubble}
       
  1154 \end{column}
       
  1155 \end{columns}\bigskip\bigskip
       
  1156 
       
  1157 Replace all constants and variables by either 
       
  1158 \pcode{+}, \pcode{-} or \pcode{0}. What we want to find out
       
  1159 is what the sign of \texttt{a} and \texttt{n} is (they are 
       
  1160 always positive).
       
  1161 
       
  1162 \end{frame}
       
  1163 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
  1164 
       
  1165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
  1166   \begin{frame}[c]
       
  1167   \frametitle{Sign Analysis?}
       
  1168 
       
  1169   
       
  1170   \begin{columns}
       
  1171   \begin{column}{4cm}
       
  1172   \begin{tabular}{cc|l}
       
  1173   $e_1$ & $e_2$ & $e_1 + e_2$\\\hline{}
       
  1174   - & - & -\\
       
  1175   - & 0 & -\\
       
  1176   - & + & -, 0, +\\
       
  1177   0 & $x$ & $x$\\
       
  1178   + & - & -, 0, +\\
       
  1179   + & 0 & +\\
       
  1180   + & + & +\\
       
  1181   \end{tabular}
       
  1182   \end{column}
       
  1183 
       
  1184   \begin{column}{4cm}
       
  1185   \begin{tabular}{cc|l}
       
  1186   $e_1$ & $e_2$ & $e_1 * e_2$\\\hline{}
       
  1187   - & - & +\\
       
  1188   - & 0 & 0\\
       
  1189   - & + & -\\
       
  1190   0 & $x$ & 0\\
       
  1191   + & - & -\\
       
  1192   + & 0 & 0\\
       
  1193   + & + & +\\
       
  1194   \end{tabular}
       
  1195   \end{column}
       
  1196   \end{columns}
       
  1197 
       
  1198   \end{frame}
       
  1199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   932 
  1200 
   933 
  1201 
   934 \end{document}
  1202 \end{document}
   935 
       
   936 %         n := 5 
       
   937 % top:    jump? n = 0 done 
       
   938 %         a := a * n 
       
   939 %         n := n + -1 
       
   940 %         goto top 
       
   941 % done:
       
   942 
  1203 
   943 
  1204 
   944 %%% Local Variables:  
  1205 %%% Local Variables:  
   945 %%% mode: latex
  1206 %%% mode: latex
   946 %%% TeX-master: t
  1207 %%% TeX-master: t