slides/slides08.tex
changeset 534 6937caaff1d9
parent 532 15670cd83c44
child 535 095be64c03c1
equal deleted inserted replaced
533:1276d7013c2c 534:6937caaff1d9
   496 \end{textblock}
   496 \end{textblock}
   497 \end{frame}
   497 \end{frame}
   498 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   498 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   499 
   499 
   500 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   500 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   501 \begin{frame}[c,fragile]
       
   502 \frametitle{Compiling Ifs}
       
   503 
       
   504 For example
       
   505 
       
   506 \begin{lstlisting}[mathescape,numbers=none,language=While]
       
   507 if 1 = 1 then x := 2 else y := 3
       
   508 \end{lstlisting}
       
   509 
       
   510 
       
   511 \begin{center}
       
   512 \begin{lstlisting}[mathescape,language=JVMIS,numbers=none]
       
   513    ldc 1
       
   514    ldc 1
       
   515    if_icmpne L_ifelse $\quad\tikz[remember picture] \node (C) {\mbox{}};$
       
   516    ldc 2
       
   517    istore 0
       
   518    goto L_ifend $\quad\tikz[remember picture] \node (A) {\mbox{}};$
       
   519 L_ifelse: $\quad\tikz[remember picture] \node[] (D) {\mbox{}};$
       
   520    ldc 3
       
   521    istore 1
       
   522 L_ifend: $\quad\tikz[remember picture] \node[] (B) {\mbox{}};$
       
   523 \end{lstlisting}
       
   524 \end{center}
       
   525 
       
   526 \begin{tikzpicture}[remember picture,overlay]
       
   527   \draw[->,very thick] (A) edge [->,to path={-- ++(10mm,0mm) 
       
   528            -- ++(0mm,-17.3mm) |- (\tikztotarget)},line width=1mm] (B.east);
       
   529   \draw[->,very thick] (C) edge [->,to path={-- ++(10mm,0mm) 
       
   530            -- ++(0mm,-17.3mm) |- (\tikztotarget)},line width=1mm] (D.east);
       
   531 \end{tikzpicture}
       
   532 
       
   533 \end{frame}
       
   534 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
       
   535 
       
   536 
       
   537 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   501 \begin{frame}[t]
   538 \begin{frame}[t]
   502 \frametitle{Compiling BExps}
   539 \frametitle{Compiling BExps}
   503 
   540 
   504 {\Large\bl{$a_1 = a_2$}}
   541 {\Large\bl{$a_1 = a_2$}}
   505 
   542 
   639 
   676 
   640 \end{frame}
   677 \end{frame}
   641 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
   678 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
   642 
   679 
   643 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   680 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   644 \begin{frame}[t]
   681 \begin{frame}[c,fragile]
       
   682 \frametitle{Compiling Whiles}
       
   683 
       
   684 For example
       
   685 
       
   686 \begin{lstlisting}[mathescape,numbers=none,language=While]
       
   687 while x <= 10 do x := x + 1
       
   688 \end{lstlisting}
       
   689 
       
   690 
       
   691 \begin{center}
       
   692 \begin{lstlisting}[mathescape,language=JVMIS,numbers=none]
       
   693 L_wbegin: $\quad\tikz[remember picture] \node[] (LB) {\mbox{}};$
       
   694    iload 0
       
   695    ldc 10
       
   696    if_icmpgt L_wend $\quad\tikz[remember picture] \node (LC) {\mbox{}};$
       
   697    iload 0
       
   698    ldc 1
       
   699    iadd
       
   700    istore 0
       
   701    goto L_wbegin $\quad\tikz[remember picture] \node (LA) {\mbox{}};$
       
   702 L_wend: $\quad\tikz[remember picture] \node[] (LD) {\mbox{}};$
       
   703 \end{lstlisting}
       
   704 \end{center}
       
   705 
       
   706 \begin{tikzpicture}[remember picture,overlay]
       
   707   \draw[->,very thick] (LA) edge [->,to path={-- ++(12mm,0mm) 
       
   708            -- ++(0mm,17.3mm) |- (\tikztotarget)},line width=1mm] (LB.east);
       
   709   \draw[->,very thick] (LC) edge [->,to path={-- ++(12mm,0mm) 
       
   710            -- ++(0mm,-17.3mm) |- (\tikztotarget)},line width=1mm] (LD.east);
       
   711 \end{tikzpicture}
       
   712 
       
   713 \end{frame}
       
   714 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
       
   715 
       
   716 
       
   717 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   718 \begin{frame}[c,fragile]
   645 \frametitle{Compiling Writes}
   719 \frametitle{Compiling Writes}
   646 
   720 
   647 {\Large\bl{write $x$}}
   721 \small
   648 
   722 \begin{lstlisting}[language=JVMIS,mathescape,
   649 \begin{center}
   723                    numbers=none,xleftmargin=-6mm]
   650 \small\bl{\begin{tabular}{l}
   724 .method public static write(I)V 
   651 .method public static write(I)V\hspace{1cm}\textcolor{black}{(library function)}\\ 
   725   .limit locals 1 
   652 \;\;    .limit locals 5 \\
   726   .limit stack 2 
   653 \;\;    .limit stack 5 \\
   727   getstatic java/lang/System/out 
   654 \;\;    iload 0 \\
   728                             Ljava/io/PrintStream; 
   655 \;\;    getstatic java/lang/System/out Ljava/io/PrintStream;\\ 
   729   iload 0
   656 \;\;    swap \\
   730   invokevirtual java/io/PrintStream/println(I)V 
   657 \;\;    invokevirtual java/io/PrintStream/println(I)V \\
   731   return 
   658 \;\;    return \\
   732 .end method
   659 .end method\bigskip\bigskip\\
   733 
   660 %
   734 
   661 \normalsize
   735 
   662 iload $E(x)$\\
   736 iload $E(x)$ 
   663 invokestatic write(I)V\\
   737 invokestatic XXX/XXX/write(I)V
   664 \end{tabular}}
   738 \end{lstlisting}
   665 \end{center}
   739 
   666 
   740 \end{frame}
   667 \end{frame}
   741 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   668 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
   742 
       
   743 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
       
   744 \begin{frame}[c,fragile]
       
   745 \frametitle{Compiling Main}
       
   746 
       
   747 \footnotesize
       
   748 \begin{lstlisting}[language=JVMIS,mathescape,
       
   749                    numbers=none,xleftmargin=-6mm]
       
   750 .class public XXX.XXX
       
   751 .super java/lang/Object
       
   752 
       
   753 .method public <init>()V
       
   754     aload_0
       
   755     invokenonvirtual java/lang/Object/<init>()V
       
   756     return
       
   757 .end method
       
   758 
       
   759 .method public static main([Ljava/lang/String;)V
       
   760     .limit locals 200
       
   761     .limit stack 200
       
   762 
       
   763       $\textit{\ldots{}here comes the compiled code\ldots}$
       
   764 
       
   765     return
       
   766 .end method
       
   767 \end{lstlisting}
       
   768 
       
   769 \end{frame}
       
   770 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
       
   771 
   669 
   772 
   670 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   773 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   671 \mode<presentation>{
   774 \mode<presentation>{
   672 \begin{frame}[c]
   775 \begin{frame}[c]
   673 \frametitle{\begin{tabular}{c}Next Compiler Phases\end{tabular}}
   776 \frametitle{\begin{tabular}{c}Next Compiler Phases\end{tabular}}