diff -r 4a5876f321ae -r b93f4d2aeee1 handouts/ho07.tex --- a/handouts/ho07.tex Sat Oct 15 14:27:01 2016 +0100 +++ b/handouts/ho07.tex Mon Oct 17 13:18:34 2016 +0100 @@ -17,15 +17,33 @@ the fastest possible code, but code that is fast enough and has the advantage that the virtual machine takes care of things a compiler would normally need to take care of (like -explicit memory management). +explicit memory management). Why study compilers? John Regher +gives this answer in his compiler blog:\footnote{\url{http://blog.regehr.org/archives/1419}} -As a first example we will implement a compiler for the very -simple While-language. It will generate code for the Java -Virtual Machine (JVM). This is a stack-based virtual machine, -a fact which will make it easy to generate code for arithmetic -expressions. For example for generating code for the -expression $1 + 2$ we need to generate the following three -instructions +\begin{quote}\it{}``We can start off with a couple of observations + about the role of compilers. First, hardware is getting weirder + rather than getting clocked faster: almost all processors are + multicores and it looks like there is increasing asymmetry in + resources across cores. Processors come with vector units, crypto + accelerators, bit twiddling instructions, and lots of features to + make virtualization and concurrency work. We have DSPs, GPUs, + big.little, and Xeon Phi. This is only scratching the + surface. Second, we’re getting tired of low-level languages and + their associated security disasters, we want to write new code, to + whatever extent possible, in safer, higher-level + languages. Compilers are caught right in the middle of these + opposing trends: one of their main jobs is to help bridge the large + and growing gap between increasingly high-level languages and + increasingly wacky platforms. It’s effectively a perpetual + employment act for solid compiler hackers.'' +\end{quote} + +As a first example in this module we will implement a compiler for the +very simple While-language. It will generate code for the Java Virtual +Machine (JVM). This is a stack-based virtual machine, a fact which +will make it easy to generate code for arithmetic expressions. For +example for generating code for the expression $1 + 2$ we need to +generate the following three instructions \begin{lstlisting}[numbers=none] ldc 1