|
@@ -3527,12 +3527,11 @@ $\Tail$.}
|
|
|
\python{We recommend implementing an auxiliary function
|
|
|
named \code{select\_stmt} for the $\Stmt$ non-terminal.}
|
|
|
|
|
|
-\racket{
|
|
|
-The cases for $\Atm$ are straightforward; variables stay
|
|
|
-the same and integer constants change to immediates:
|
|
|
-$\INT{n}$ changes to $\IMM{n}$.}
|
|
|
+\racket{The cases for $\Atm$ are straightforward; variables stay the
|
|
|
+ same and integer constants change to immediates, that is, $\INT{n}$
|
|
|
+ changes to $\IMM{n}$.}
|
|
|
|
|
|
-We consider the cases for the $\Stmt$ non-terminal, starting with
|
|
|
+Next consider the cases for the $\Stmt$ non-terminal, starting with
|
|
|
arithmetic operations. For example, consider the addition operation
|
|
|
below, on the left side. There is an \key{addq} instruction in x86,
|
|
|
but it performs an in-place update. So we could move $\Arg_1$
|
|
@@ -3674,9 +3673,9 @@ programs.
|
|
|
\section{Assign Homes}
|
|
|
\label{sec:assign-Lvar}
|
|
|
|
|
|
-The \key{assign\_homes} pass compiles \LangXVar{} programs to
|
|
|
+The \code{assign\_homes} pass compiles \LangXVar{} programs to
|
|
|
\LangXVar{} programs that no longer use program variables.
|
|
|
-Thus, the \key{assign-homes} pass is responsible for placing all of
|
|
|
+Thus, the \code{assign\_homes} pass is responsible for placing all of
|
|
|
the program variables in registers or on the stack. For runtime
|
|
|
efficiency, it is better to place variables in registers, but as there
|
|
|
are only 16 registers, some programs must necessarily resort to
|
|
@@ -3722,24 +3721,29 @@ movq -16(%rbp), %rax
|
|
|
\end{lstlisting}
|
|
|
\end{transformation}
|
|
|
|
|
|
-\racket{The \code{locals-types} entry in the $\itm{info}$ of the
|
|
|
- \code{X86Program} node is an alist mapping all the variables in the
|
|
|
- program to their types (for now just \code{Integer}). The
|
|
|
- \code{assign\_homes} pass should replace all uses of those variables
|
|
|
- with stack locations. As an aside, the \code{locals-types} entry is
|
|
|
+\racket{
|
|
|
+ The \code{assign\_homes} pass should replace all variables
|
|
|
+ with stack locations.
|
|
|
+ The list of variables can be obtain from
|
|
|
+ the \code{locals-types} entry in the $\itm{info}$ of the
|
|
|
+ \code{X86Program} node. The \code{locals-types} entry is an alist
|
|
|
+ mapping all the variables in the program to their types
|
|
|
+ (for now just \code{Integer}).
|
|
|
+ As an aside, the \code{locals-types} entry is
|
|
|
computed by \code{type-check-Cvar} in the support code, which
|
|
|
installs it in the $\itm{info}$ field of the \code{CProgram} node,
|
|
|
- which should be propagated to the \code{X86Program} node.}
|
|
|
+ which you should propagate to the \code{X86Program} node.}
|
|
|
%
|
|
|
\python{The \code{assign\_homes} pass should replace all uses of
|
|
|
variables with stack locations.}
|
|
|
%
|
|
|
In the process of assigning variables to stack locations, it is
|
|
|
convenient for you to compute and store the size of the frame (in
|
|
|
-bytes) in%
|
|
|
-\racket{the $\itm{info}$ field of the \key{X86Program} node, with the key \code{stack-space}}
|
|
|
+bytes) in
|
|
|
+\racket{the $\itm{info}$ field of the \key{X86Program} node, with the key \code{stack-space},}
|
|
|
+%
|
|
|
+\python{the field \code{stack\_space} of the \key{X86Program} node,}
|
|
|
%
|
|
|
-\python{the field \code{stack\_space} of the \key{X86Program} node},
|
|
|
which is needed later to generate the conclusion of the \code{main}
|
|
|
procedure. The x86-64 standard requires the frame size to be a
|
|
|
multiple of 16 bytes.\index{subject}{frame}
|
|
@@ -3747,7 +3751,7 @@ multiple of 16 bytes.\index{subject}{frame}
|
|
|
% TODO: store the number of variables instead? -Jeremy
|
|
|
|
|
|
\begin{exercise}\normalfont
|
|
|
-Implement the \key{assign\_homes} pass in
|
|
|
+Implement the \code{assign\_homes} pass in
|
|
|
\racket{\code{compiler.rkt}}\python{\code{compiler.py}}, defining
|
|
|
auxiliary functions for each of the non-terminals in the \LangXVar{}
|
|
|
grammar. We recommend that the auxiliary functions take an extra
|
|
@@ -3794,7 +3798,7 @@ print(b)
|
|
|
\end{lstlisting}
|
|
|
\fi}
|
|
|
\end{minipage}\\
|
|
|
-The \key{assign\_homes} pass produces the following translation. \\
|
|
|
+The \code{assign\_homes} pass produces the following translation. \\
|
|
|
\begin{minipage}{0.5\textwidth}
|
|
|
{\if\edition\racketEd
|
|
|
\begin{lstlisting}
|