Browse Source

fix x86callq* grammar

Jeremy Siek 3 years ago
parent
commit
b10c0ab0bc
2 changed files with 20 additions and 8 deletions
  1. 13 5
      book.tex
  2. 7 3
      defs.tex

+ 13 - 5
book.tex

@@ -26,7 +26,7 @@
 
 \def\racketEd{0}
 \def\pythonEd{1}
-\def\edition{1}
+\def\edition{0}
 
 % material that is specific to the Racket edition of the book
 \newcommand{\racket}[1]{{\if\edition\racketEd{#1}\fi}}
@@ -14532,7 +14532,7 @@ new instructions as needed in this section.  \index{subject}{x86}
   \gray{\ASTXGlobalRacket} \\ \hline
   \ASTXIndCallRacket \\
 \begin{array}{lcl}
-\LangXIndCallM{} &::= & \PROGRAMDEFS{\itm{info}}{\LP\Def\ldots\RP}
+\LangXIndCallM{} &::= & \XPROGRAMDEFS{\itm{info}}{\LP\Def\ldots\RP}
 \end{array}
 \end{array}
 \]
@@ -14823,6 +14823,16 @@ The conclusion of every function should do the following.
 \item Return to the caller with the \code{retq} instruction.
 \end{enumerate}
 
+The output of this pass is \LangXIndCallFlat{}, which differs from
+\LangXIndCall{} in that there is no longer an AST node for function
+definitions. Instead, a program is just an association list of basic
+blocks, as in \LangXGlobal{}. So we have the following grammar rule:
+\[
+\LangXIndCallFlatM{} ::= \XPROGRAM{\itm{info}}{\LP\LP\itm{label} \,\key{.}\, \Block \RP\ldots\RP}
+\]
+
+Figure~\ref{fig:Lfun-passes} gives an overview of the passes for
+compiling \LangFun{} to x86.
 
 \begin{exercise}\normalfont\normalsize
 Expand your compiler to handle \LangFun{} as outlined in this chapter.
@@ -14850,7 +14860,7 @@ previously created test programs.
 \node (x86-2) at (3,-4)  {\large \LangXIndCallVar{}};
 \node (x86-3) at (6,-4)  {\large \LangXIndCallVar{}};
 \node (x86-4) at (9,-4) {\large \LangXIndCall{}};
-\node (x86-5) at (9,-6) {\large \LangXIndCall{}};
+\node (x86-5) at (9,-6) {\large \LangXIndCallFlat{}};
 
 \node (x86-2-1) at (3,-6)  {\large \LangXIndCallVar{}};
 \node (x86-2-2) at (6,-6)  {\large \LangXIndCallVar{}};
@@ -14889,8 +14899,6 @@ previously created test programs.
 \label{fig:Lfun-passes}
 \end{figure}
 
-Figure~\ref{fig:Lfun-passes} gives an overview of the passes for
-compiling \LangFun{} to x86.
 
 \section{An Example Translation}
 \label{sec:functions-example}

+ 7 - 3
defs.tex

@@ -90,9 +90,11 @@
 \newcommand{\LangXGlobal}{$\mathrm{x86}_{\mathsf{Global}}$} %x86^{\dagger}_2
 \newcommand{\LangXGlobalM}{\mathrm{x86}_{\mathsf{Global}}} %x86^{\dagger}_2
 \newcommand{\LangXGlobalVar}{\ensuremath{\mathrm{x86}^{\mathsf{Var}}_{\mathsf{Global}}}} %x86^{*}_2
-\newcommand{\LangXIndCall}{$\mathrm{x86}_{\mathsf{callq*}}$} %x86_3
-\newcommand{\LangXIndCallM}{\mathrm{x86}_{\mathsf{callq*}}} %x86_3
-\newcommand{\LangXIndCallVar}{\ensuremath{\mathrm{x86}^{\mathsf{Var}}_{\mathsf{callq*}}}} %x86^*_3
+\newcommand{\LangXIndCall}{$\mathrm{x86}^{\mathsf{Def}}_{\mathsf{callq*}}$} %x86_3
+\newcommand{\LangXIndCallM}{\mathrm{x86}^{\mathsf{Def}}_{\mathsf{callq*}}} %x86_3
+\newcommand{\LangXIndCallFlat}{$\mathrm{x86}_{\mathsf{callq*}}$} %x86_3
+\newcommand{\LangXIndCallFlatM}{\mathrm{x86}_{\mathsf{callq*}}} %x86_3
+\newcommand{\LangXIndCallVar}{\ensuremath{\mathrm{x86}^{\mathsf{Var},\mathsf{Def}}_{\mathsf{callq*}}}} %x86^*_3
 
 \newcommand{\Stmt}{\itm{stmt}}
 \newcommand{\Exp}{\itm{exp}}
@@ -276,6 +278,7 @@
 \newcommand{\CWHILE}[2]{\LP\key{while}~#1~#2\RP}
 \newcommand{\WHILE}[2]{\LP\key{WhileLoop}~#1~#2\RP}
 \newcommand{\CMAKEVEC}[2]{\LP\key{make-vector}~#1~#2\RP}
+\newcommand{\MAKEVEC}[2]{\LP\key{make-vector}~#1~#2\RP}
 \newcommand{\CSETBANG}[2]{\LP\key{set!}~#1~#2\RP}
 \newcommand{\SETBANG}[2]{\LP\key{SetBang}~#1~#2\RP}
 \newcommand{\GETBANG}[1]{\LP\key{GetBang}~#1\RP}
@@ -355,6 +358,7 @@
 \newcommand{\JMPIF}[2]{\key{(JmpIf}~#1~#2\key{)}}
 \newcommand{\RETQ}{\key{(Retq)}}
 \newcommand{\XPROGRAM}[2]{\LP\code{X86Program}~#1~#2\RP}
+\newcommand{\XPROGRAMDEFS}[2]{\LP\code{X86Program}~#1~#2\RP}
 \newcommand{\BYTEREG}[1]{\key{(ByteReg}~#1\key{)}}
 \newcommand{\CDEF}[4]{\LP\key{define}~\LP#1~#2\RP\,\key{:}\,#3~#4\RP}
 \newcommand{\DEF}[5]{\LP\key{Def}~#1~#2~#3~#4~#5\RP}