Assignment 2: Testing the compiler
Compiling the compile
program
To compile the compiler, cd
into the src/ch3
directory and type make
.
This will compile the compiler (which is an executable file called compile
).
You should see a number of warnings when you compile the compiler;
that's expected.
(As you fill in the code for the compiler passes,
these warnings will go away).
Running the compile
program
To run the compiler, type ./compile
in the ch3
directory, along
with the path of a file to compile and (optionally) some command-line options.
Most of this is the same as it was in the last assignment.
Typing ./compile --help
(or just ./compile
with no arguments)
will display this usage message:
usage: compile <filename> [-pass <pass>] [-only] [-eval] [-no-fix-label]
[-sexp-width n] [-sexp-indent n]
[-regs reg1,reg2,...] [-help]
-pass Last compiler pass (one of: lvar un rc ec si ul bi ar pi pc pa)
-only Only do one compiler pass
-eval Evaluate after compiling
-no-fix-label disable `fix_label`
-sexp-width S-expression maximum line width
-sexp-indent S-expression indent
-regs Registers to use
-help Display this list of options
--help Display this list of options
This is the same as the compile
usage message
from the previous assignment,
except that there is a new command-line option:
-regs reg1,reg2,...
This is a new feature of the compiler, starting with this assignment and continuing through all the subsequent ones. It allows you to select which registers can be used for register allocation. If this option is not used, all registers (other than the reserved ones) can be used. This is extremely useful for checking whether variables get spilled to the stack correctly once there are no more registers available, and for whether callee-saved registers are handled correctly in the preludes and conclusions of functions.
The test scripts use this option in these ways:
- unused -- use all avaiable registers
-regs rcx
-- only use the%rcx
register (caller-saved)-regs rbx
-- only use the%rbx
register (callee-saved)-regs rcx,rbx
-- only use the%rcx
and%rbx
registers
For instance, if the only register you use is %rbx
(a callee-saved register),
then if you don't save and restore callee-saved registers properly,
you'll get an error.
Testing your compiler: the test scripts
The test scripts are the same
as those described in the previous assignment,
except that the test scripts will also use the
-regs
command-line option as described above.
As a result, there will be many more reference files generated
for passes that use registers.