浏览代码

updated output figures in ch 5

Jeremy Siek 4 年之前
父节点
当前提交
3b5a0c626d
共有 1 个文件被更改,包括 148 次插入158 次删除
  1. 148 158
      book.tex

+ 148 - 158
book.tex

@@ -68,7 +68,6 @@
 
 
 \definecolor{comment-red}{rgb}{0.8,0,0}
 \definecolor{comment-red}{rgb}{0.8,0,0}
 \if{0}
 \if{0}
-% Peanut gallery comments:
 \newcommand{\rn}[1]{{\color{comment-red}{(RRN: #1)}}}
 \newcommand{\rn}[1]{{\color{comment-red}{(RRN: #1)}}}
 \newcommand{\margincomment}[1]{\marginpar{#1}}
 \newcommand{\margincomment}[1]{\marginpar{#1}}
 \else
 \else
@@ -79,7 +78,7 @@
 \lstset{%
 \lstset{%
 language=Lisp,
 language=Lisp,
 basicstyle=\ttfamily\small,
 basicstyle=\ttfamily\small,
-morekeywords={seq,assign,program,block,define,lambda,match,goto,if,else,then,struct,Integer,Boolean},
+morekeywords={seq,assign,program,block,define,lambda,match,goto,if,else,then,struct,Integer,Boolean,Vector,Void},
 deletekeywords={read},
 deletekeywords={read},
 escapechar=|,
 escapechar=|,
 columns=flexible,
 columns=flexible,
@@ -4809,13 +4808,13 @@ conclusion:
 \node (R2-5) at (9,0)  {\large $R_2$};
 \node (R2-5) at (9,0)  {\large $R_2$};
 \node (C1-1) at (3,-2)  {\large $C_1$};
 \node (C1-1) at (3,-2)  {\large $C_1$};
 
 
-\node (x86-2) at (3,-4)  {\large $\text{x86}^{*}$};
-\node (x86-3) at (6,-4)  {\large $\text{x86}^{*}$};
-\node (x86-4) at (9,-4) {\large $\text{x86}^{*}$};
-\node (x86-5) at (9,-6) {\large $\text{x86}^{\dagger}$};
+\node (x86-2) at (3,-4)  {\large $\text{x86}^{*}_1$};
+\node (x86-3) at (6,-4)  {\large $\text{x86}^{*}_1$};
+\node (x86-4) at (9,-4) {\large $\text{x86}^{*}_1$};
+\node (x86-5) at (9,-6) {\large $\text{x86}^{\dagger}_1$};
 
 
-\node (x86-2-1) at (3,-6)  {\large $\text{x86}^{*}$};
-\node (x86-2-2) at (6,-6)  {\large $\text{x86}^{*}$};
+\node (x86-2-1) at (3,-6)  {\large $\text{x86}^{*}_1$};
+\node (x86-2-2) at (6,-6)  {\large $\text{x86}^{*}_1$};
 
 
 \path[->,bend left=15] (R2) edge [above] node {\ttfamily\footnotesize\color{red} typecheck} (R2-2);
 \path[->,bend left=15] (R2) edge [above] node {\ttfamily\footnotesize\color{red} typecheck} (R2-2);
 \path[->,bend left=15] (R2-2) edge [above] node {\ttfamily\footnotesize\color{red} shrink} (R2-3);
 \path[->,bend left=15] (R2-2) edge [above] node {\ttfamily\footnotesize\color{red} shrink} (R2-3);
@@ -5619,9 +5618,9 @@ before \code{remove-complex-opera*} because the code generated by
 \code{expose-allocation} introduces new variables using \code{let},
 \code{expose-allocation} introduces new variables using \code{let},
 but \code{let} is gone after \code{explicate-control}.
 but \code{let} is gone after \code{explicate-control}.
 
 
-The output of \code{expose-allocation} is a language that extends
-$R_3$ with the three new forms that we use in the translation of the
-\code{vector} form.
+The output of \code{expose-allocation} is a language $R'_3$ that
+extends $R_3$ with the three new forms that we use in the translation
+of the \code{vector} form.
 \[
 \[
 \begin{array}{lcl}
 \begin{array}{lcl}
   \Exp &::=& \cdots
   \Exp &::=& \cdots
@@ -5677,7 +5676,7 @@ Figure~\ref{fig:expose-alloc-output} shows the output of the
   (let ([vecinit7976
   (let ([vecinit7976
          (let ([vecinit7972 42])
          (let ([vecinit7972 42])
            (let ([collectret7974
            (let ([collectret7974
-                  (if (< (+ free_ptr 16) fromspace_end)
+                  (if (< (+ (global free_ptr) 16) (global fromspace_end))
                       (void)
                       (void)
                       (collect 16)
                       (collect 16)
                       )])
                       )])
@@ -5689,7 +5688,7 @@ Figure~\ref{fig:expose-alloc-output} shows the output of the
            )
            )
          ])
          ])
     (let ([collectret7978
     (let ([collectret7978
-           (if (< (+ free_ptr 16) fromspace_end)
+           (if (< (+ (global free_ptr) 16) (global fromspace_end))
                (void)
                (void)
                (collect 16)
                (collect 16)
                )])
                )])
@@ -5703,7 +5702,7 @@ Figure~\ref{fig:expose-alloc-output} shows the output of the
  0)
  0)
 \end{lstlisting}
 \end{lstlisting}
 \caption{Output of the \code{expose-allocation} pass, minus
 \caption{Output of the \code{expose-allocation} pass, minus
-  all of the \code{HasType} forms.}
+  all of the \code{has-type} forms.}
 \label{fig:expose-alloc-output}
 \label{fig:expose-alloc-output}
 \end{figure}
 \end{figure}
 
 
@@ -5772,7 +5771,7 @@ C_2 & ::= & \gray{ \PROGRAM{\itm{info}}{\CFG{(\itm{label}\,\key{.}\,\Tail)^{+}}}
 \]
 \]
 \end{minipage}
 \end{minipage}
 }
 }
-\caption{The abstract syntax $C_2$, an extention of $C_1$
+\caption{The abstract syntax of $C_2$, an extention of $C_1$
   (Figure~\ref{fig:c1-syntax}).}
   (Figure~\ref{fig:c1-syntax}).}
 \label{fig:c2-syntax}
 \label{fig:c2-syntax}
 \end{figure}
 \end{figure}
@@ -5814,43 +5813,43 @@ locals:
     tmp7984 : 'Integer, tmp7979 : 'Integer, tmp7982 : 'Integer,
     tmp7984 : 'Integer, tmp7979 : 'Integer, tmp7982 : 'Integer,
     alloc7971 : '(Vector Integer), tmp7981 : 'Integer,
     alloc7971 : '(Vector Integer), tmp7981 : 'Integer,
     vecinit7972 : 'Integer, initret7973 : 'Void, 
     vecinit7972 : 'Integer, initret7973 : 'Void, 
-block7991:
+block91:
     (collect 16)
     (collect 16)
-    goto block7989;
-block7990:
+    goto block89;
+block90:
     collectret7974 = (void);
     collectret7974 = (void);
-    goto block7989;
-block7989:
+    goto block89;
+block89:
     alloc7971 = (allocate 1 (Vector Integer));
     alloc7971 = (allocate 1 (Vector Integer));
     initret7973 = (vector-set! alloc7971 0 vecinit7972);
     initret7973 = (vector-set! alloc7971 0 vecinit7972);
     vecinit7976 = alloc7971;
     vecinit7976 = alloc7971;
-    tmp7982 = free_ptr;
+    tmp7982 = (global free_ptr);
     tmp7983 = (+ tmp7982 16);
     tmp7983 = (+ tmp7982 16);
-    tmp7984 = fromspace_end;
+    tmp7984 = (global fromspace_end);
     if (< tmp7983 tmp7984) then
     if (< tmp7983 tmp7984) then
-       goto block7987;
+       goto block87;
     else
     else
-       goto block7988;
-block7988:
+       goto block88;
+block88:
     (collect 16)
     (collect 16)
-    goto block7986;
-block7987:
+    goto block86;
+block87:
     collectret7978 = (void);
     collectret7978 = (void);
-    goto block7986;
-block7986:
+    goto block86;
+block86:
     alloc7975 = (allocate 1 (Vector (Vector Integer)));
     alloc7975 = (allocate 1 (Vector (Vector Integer)));
     initret7977 = (vector-set! alloc7975 0 vecinit7976);
     initret7977 = (vector-set! alloc7975 0 vecinit7976);
     tmp7985 = (vector-ref alloc7975 0);
     tmp7985 = (vector-ref alloc7975 0);
     return (vector-ref tmp7985 0);
     return (vector-ref tmp7985 0);
 start:
 start:
     vecinit7972 = 42;
     vecinit7972 = 42;
-    tmp7979 = free_ptr;
+    tmp7979 = (global free_ptr);
     tmp7980 = (+ tmp7979 16);
     tmp7980 = (+ tmp7979 16);
-    tmp7981 = fromspace_end;
+    tmp7981 = (global fromspace_end);
     if (< tmp7980 tmp7981) then
     if (< tmp7980 tmp7981) then
-       goto block7990;
+       goto block90;
     else
     else
-       goto block7991;
+       goto block91;
 \end{lstlisting}
 \end{lstlisting}
 \caption{Output of \code{uncover-locals} for the running example.}
 \caption{Output of \code{uncover-locals} for the running example.}
 \label{fig:uncover-locals-r3}
 \label{fig:uncover-locals-r3}
@@ -5878,19 +5877,19 @@ The \code{vector-ref} and \code{vector-set!} forms translate into
 plus one is to get past the tag at the beginning of the tuple
 plus one is to get past the tag at the beginning of the tuple
 representation.)
 representation.)
 \begin{lstlisting}
 \begin{lstlisting}
-   (assign |$\itm{lhs}$| (vector-ref |$\itm{vec}$| |$n$|))
+   |$\itm{lhs}$| = (vector-ref |$\itm{vec}$| |$n$|);
    |$\Longrightarrow$|
    |$\Longrightarrow$|
-   (movq |$\itm{vec}'$| (reg r11))
-   (movq (deref r11 |$8(n+1)$|) |$\itm{lhs}$|)
+   movq |$\itm{vec}'$|, %r11
+   movq |$-8(n+1)$|(%r11), |$\itm{lhs}$|
 
 
-   (assign |$\itm{lhs}$| (vector-set! |$\itm{vec}$| |$n$| |$\itm{arg}$|))
+   |$\itm{lhs}$| = (vector-set! |$\itm{vec}$| |$n$| |$\itm{arg}$|);
    |$\Longrightarrow$|
    |$\Longrightarrow$|
-   (movq |$\itm{vec}'$| (reg r11))
-   (movq |$\itm{arg}'$| (deref r11 |$8(n+1)$|))
-   (movq (int 0) |$\itm{lhs}$|)
+   movq |$\itm{vec}'$|, %r11
+   movq |$\itm{arg}'$|, |$8(n+1)$|(%r11)
+   movq $0, |$\itm{lhs}$|
 \end{lstlisting}
 \end{lstlisting}
-The $\itm{vec}'$ and $\itm{arg}'$ are obtained by recursively
-processing $\itm{vec}$ and $\itm{arg}$.  The move of $\itm{vec}'$ to
+The $\itm{vec}'$ and $\itm{arg}'$ are obtained by translating
+$\itm{vec}$ and $\itm{arg}$ to x86.  The move of $\itm{vec}'$ to
 register \code{r11} ensures that offsets are only performed with
 register \code{r11} ensures that offsets are only performed with
 register operands. This requires removing \code{r11} from
 register operands. This requires removing \code{r11} from
 consideration by the register allocating.
 consideration by the register allocating.
@@ -5907,12 +5906,12 @@ how the tag is organized. We recommend using the Racket operations
 The type annotation in the \code{vector} form is used to determine the
 The type annotation in the \code{vector} form is used to determine the
 pointer mask region of the tag.
 pointer mask region of the tag.
 \begin{lstlisting}
 \begin{lstlisting}
-   (assign |$\itm{lhs}$| (allocate |$\itm{len}$| (Vector |$\itm{type} \ldots$|)))
+   |$\itm{lhs}$| = (allocate |$\itm{len}$| (Vector |$\itm{type} \ldots$|));
    |$\Longrightarrow$|
    |$\Longrightarrow$|
-   (movq (global free_ptr) |$\itm{lhs}'$|)
-   (addq (int |$8(\itm{len}+1)$|) (global free_ptr))
-   (movq |$\itm{lhs}'$| (reg r11))
-   (movq (int |$\itm{tag}$|) (deref r11 0))
+   movq (global free_ptr), |$\itm{lhs}'$|
+   addq $|$8(\itm{len}+1)$|, (global free_ptr)
+   movq |$\itm{lhs}'$|, %r11
+   movq $|$\itm{tag}$|, 0(%r11)
 \end{lstlisting}
 \end{lstlisting}
 
 
 The \code{collect} form is compiled to a call to the \code{collect}
 The \code{collect} form is compiled to a call to the \code{collect}
@@ -5924,9 +5923,9 @@ the register allocator.
 \begin{lstlisting}
 \begin{lstlisting}
    (collect |$\itm{bytes}$|)
    (collect |$\itm{bytes}$|)
    |$\Longrightarrow$|
    |$\Longrightarrow$|
-   (movq (reg r15) (reg rdi))
-   (movq |\itm{bytes}| (reg rsi))
-   (callq collect)
+   movq %r15, %rdi
+   movq $|\itm{bytes}|, %rsi
+   callq collect
 \end{lstlisting}
 \end{lstlisting}
 
 
 
 
@@ -5972,66 +5971,62 @@ Figure~\ref{fig:select-instr-output-gc} shows the output of the
 \begin{figure}[tbp]
 \begin{figure}[tbp]
 \centering
 \centering
 \begin{minipage}{0.75\textwidth}
 \begin{minipage}{0.75\textwidth}
+% tests/s2_17.rkt
 \begin{lstlisting}[basicstyle=\ttfamily\scriptsize]
 \begin{lstlisting}[basicstyle=\ttfamily\scriptsize]
-(program
- ((locals . ((tmp54 . Integer) (tmp51 . Integer) (tmp53 . Integer)
-             (alloc43 . (Vector Integer)) (tmp55 . Integer)
-             (initret45 . Void) (alloc47 . (Vector (Vector Integer)))
-             (collectret46 . Void) (vecinit48 . (Vector Integer))
-             (tmp52 . Integer) (tmp57 Vector Integer) (vecinit44 . Integer)
-             (tmp56 . Integer) (initret49 . Void) (collectret50 . Void))))
- ((block63 . (block ()
-               (movq (reg r15) (reg rdi))
-               (movq (int 16) (reg rsi))
-               (callq collect)
-               (jmp block61)))
-  (block62 . (block () (movq (int 0) (var collectret46)) (jmp block61)))
-  (block61 . (block ()
-               (movq (global free_ptr) (var alloc43))
-               (addq (int 16) (global free_ptr))
-               (movq (var alloc43) (reg r11))
-               (movq (int 3) (deref r11 0))
-               (movq (var alloc43) (reg r11))
-               (movq (var vecinit44) (deref r11 8))
-               (movq (int 0) (var initret45))
-               (movq (var alloc43) (var vecinit48))
-               (movq (global free_ptr) (var tmp54))
-               (movq (var tmp54) (var tmp55))
-               (addq (int 16) (var tmp55))
-               (movq (global fromspace_end) (var tmp56))
-               (cmpq (var tmp56) (var tmp55))
-               (jmp-if l block59)
-               (jmp block60)))
-  (block60 . (block ()
-               (movq (reg r15) (reg rdi))
-               (movq (int 16) (reg rsi))
-               (callq collect)
-               (jmp block58))
-  (block59 . (block () 
-               (movq (int 0) (var collectret50)) 
-               (jmp block58)))
-  (block58 . (block ()
-               (movq (global free_ptr) (var alloc47))
-               (addq (int 16) (global free_ptr))
-               (movq (var alloc47) (reg r11))
-               (movq (int 131) (deref r11 0))
-               (movq (var alloc47) (reg r11))
-               (movq (var vecinit48) (deref r11 8))
-               (movq (int 0) (var initret49))
-               (movq (var alloc47) (reg r11))
-               (movq (deref r11 8) (var tmp57))
-               (movq (var tmp57) (reg r11))
-               (movq (deref r11 8) (reg rax))
-               (jmp conclusion)))
-  (start . (block ()
-             (movq (int 42) (var vecinit44))
-             (movq (global free_ptr) (var tmp51))
-             (movq (var tmp51) (var tmp52))
-             (addq (int 16) (var tmp52))
-             (movq (global fromspace_end) (var tmp53))
-             (cmpq (var tmp53) (var tmp52))
-             (jmp-if l block62)
-             (jmp block63))))))
+block35:
+    movq (global free_ptr), alloc9024
+    addq $16, (global free_ptr)
+    movq alloc9024, %r11
+    movq $131, 0(%r11)
+    movq alloc9024, %r11
+    movq vecinit9025, 8(%r11)
+    movq $0, initret9026
+    movq alloc9024, %r11
+    movq 8(%r11), tmp9034
+    movq tmp9034, %r11
+    movq 8(%r11), %rax
+    jmp conclusion
+block36:
+    movq $0, collectret9027
+    jmp block35
+block37:
+    movq %r15, %rdi
+    movq $16, %rsi
+    callq 'collect
+    jmp block35
+block38:
+    movq (global free_ptr), alloc9020
+    addq $16, (global free_ptr)
+    movq alloc9020, %r11
+    movq $3, 0(%r11)
+    movq alloc9020, %r11
+    movq vecinit9021, 8(%r11)
+    movq $0, initret9022
+    movq alloc9020, vecinit9025
+    movq (global free_ptr), tmp9031
+    movq tmp9031, tmp9032
+    addq $16, tmp9032
+    movq (global fromspace_end), tmp9033
+    cmpq tmp9033, tmp9032
+    jl block36
+    jmp block37
+block39:
+    movq $0, collectret9023
+    jmp block38
+block40:
+    movq %r15, %rdi
+    movq $16, %rsi
+    callq 'collect
+    jmp block38
+start:
+    movq $42, vecinit9021
+    movq (global free_ptr), tmp9028
+    movq tmp9028, tmp9029
+    addq $16, tmp9029
+    movq (global fromspace_end), tmp9030
+    cmpq tmp9030, tmp9029
+    jl block39
+    jmp block40
 \end{lstlisting}
 \end{lstlisting}
 \end{minipage}
 \end{minipage}
 \caption{Output of the \code{select-instructions} pass.}
 \caption{Output of the \code{select-instructions} pass.}
@@ -6113,9 +6108,9 @@ if it is null prior to dereferencing it.
 \begin{figure}[htbp]
 \begin{figure}[htbp]
 \begin{minipage}[t]{0.5\textwidth}
 \begin{minipage}[t]{0.5\textwidth}
 \begin{lstlisting}[basicstyle=\ttfamily\scriptsize]
 \begin{lstlisting}[basicstyle=\ttfamily\scriptsize]
-_block58:
-	movq	_free_ptr(%rip), %rcx
-	addq	$16, _free_ptr(%rip)
+block35:
+	movq	free_ptr(%rip), %rcx
+	addq	$16, free_ptr(%rip)
 	movq	%rcx, %r11
 	movq	%rcx, %r11
 	movq	$131, 0(%r11)
 	movq	$131, 0(%r11)
 	movq	%rcx, %r11
 	movq	%rcx, %r11
@@ -6126,74 +6121,69 @@ _block58:
 	movq	8(%r11), %rcx
 	movq	8(%r11), %rcx
 	movq	%rcx, %r11
 	movq	%rcx, %r11
 	movq	8(%r11), %rax
 	movq	8(%r11), %rax
-	jmp _conclusion
-_block59:
-	movq	$0, %rcx
-	jmp _block58
-_block62:
+	jmp conclusion
+block36:
 	movq	$0, %rcx
 	movq	$0, %rcx
-	jmp _block61
-_block60:
-	movq	%r15, %rdi
-	movq	$16, %rsi
-	callq	_collect
-	jmp _block58
-_block63:
-	movq	%r15, %rdi
-	movq	$16, %rsi
-	callq	_collect
-	jmp _block61
-_start:
-	movq	$42, %rbx
-	movq	_free_ptr(%rip), %rdx
-	addq	$16, %rdx
-	movq	_fromspace_end(%rip), %rcx
-	cmpq	%rcx, %rdx
-	jl _block62
-	jmp _block63
-\end{lstlisting}
-\end{minipage}
-\begin{minipage}[t]{0.45\textwidth}
-\begin{lstlisting}[basicstyle=\ttfamily\scriptsize]
-_block61:
-	movq	_free_ptr(%rip), %rcx
-	addq	$16, _free_ptr(%rip)
+	jmp block35
+block38:
+	movq	free_ptr(%rip), %rcx
+	addq	$16, free_ptr(%rip)
 	movq	%rcx, %r11
 	movq	%rcx, %r11
 	movq	$3, 0(%r11)
 	movq	$3, 0(%r11)
 	movq	%rcx, %r11
 	movq	%rcx, %r11
 	movq	%rbx, 8(%r11)
 	movq	%rbx, 8(%r11)
 	movq	$0, %rdx
 	movq	$0, %rdx
 	movq	%rcx, -8(%r15)
 	movq	%rcx, -8(%r15)
-	movq	_free_ptr(%rip), %rcx
+	movq	free_ptr(%rip), %rcx
 	addq	$16, %rcx
 	addq	$16, %rcx
-	movq	_fromspace_end(%rip), %rdx
+	movq	fromspace_end(%rip), %rdx
 	cmpq	%rdx, %rcx
 	cmpq	%rdx, %rcx
-	jl _block59
-	jmp _block60
-
-	.globl _main
-_main:
+	jl block36
+	movq	%r15, %rdi
+	movq	$16, %rsi
+	callq	collect
+	jmp block35
+block39:
+	movq	$0, %rcx
+	jmp block38
+\end{lstlisting}
+\end{minipage}
+\begin{minipage}[t]{0.45\textwidth}
+\begin{lstlisting}[basicstyle=\ttfamily\scriptsize]
+start:
+	movq	$42, %rbx
+	movq	free_ptr(%rip), %rdx
+	addq	$16, %rdx
+	movq	fromspace_end(%rip), %rcx
+	cmpq	%rcx, %rdx
+	jl block39
+	movq	%r15, %rdi
+	movq	$16, %rsi
+	callq	collect
+	jmp block38
+	.globl main
+main:
 	pushq	%rbp
 	pushq	%rbp
 	movq	%rsp, %rbp
 	movq	%rsp, %rbp
+	pushq	%r13
 	pushq	%r12
 	pushq	%r12
 	pushq	%rbx
 	pushq	%rbx
-	pushq	%r13
 	pushq	%r14
 	pushq	%r14
 	subq	$0, %rsp
 	subq	$0, %rsp
 	movq $16384, %rdi
 	movq $16384, %rdi
 	movq $16, %rsi
 	movq $16, %rsi
-	callq _initialize
-	movq _rootstack_begin(%rip), %r15
+	callq initialize
+	movq rootstack_begin(%rip), %r15
 	movq $0, (%r15)
 	movq $0, (%r15)
 	addq $8, %r15
 	addq $8, %r15
-	jmp _start
-_conclusion:
+	jmp start
+conclusion:
 	subq $8, %r15
 	subq $8, %r15
 	addq	$0, %rsp
 	addq	$0, %rsp
 	popq	%r14
 	popq	%r14
-	popq	%r13
 	popq	%rbx
 	popq	%rbx
 	popq	%r12
 	popq	%r12
+	popq	%r13
 	popq	%rbp
 	popq	%rbp
 	retq
 	retq
 \end{lstlisting}
 \end{lstlisting}
@@ -6215,8 +6205,8 @@ _conclusion:
 \node (R3-2) at (3,2)  {\large $R_3$};
 \node (R3-2) at (3,2)  {\large $R_3$};
 \node (R3-3) at (6,2)  {\large $R_3$};
 \node (R3-3) at (6,2)  {\large $R_3$};
 \node (R3-4) at (9,2)  {\large $R_3$};
 \node (R3-4) at (9,2)  {\large $R_3$};
-\node (R3-5) at (9,0)  {\large $R_3$};
-\node (R3-6) at (6,0)  {\large $R_3$};
+\node (R3-5) at (9,0)  {\large $R'_3$};
+\node (R3-6) at (6,0)  {\large $R'_3$};
 \node (C2-4) at (3,-2)  {\large $C_2$};
 \node (C2-4) at (3,-2)  {\large $C_2$};
 \node (C2-3) at (0,-2)  {\large $C_2$};
 \node (C2-3) at (0,-2)  {\large $C_2$};