Java Reference
In-Depth Information
-pOnlyparseinputandprintASTtoSTDOUT
-paOnlyparseandpre-analyzeinputandprintASTtoSTDOUT
-aOnlyparse,pre-analyze,andanalyzeinputandprintASTtoSTDOUT
-s<naive|linear|graph>GenerateSPIMcode
-r<num>Max.physicalregisters(1-18)availableforallocation;default=8
-d<dir>Specifywheretoplaceoutputfiles;default=.
In order to compile the j-- source program to SPIM code, one must specify the
-s
and the
optional
-r
switches along with appropriate arguments. The
-s
switch tells the compiler
that we want SPIM code for output and the associated argument specifies the register
allocation mechanism that must be used; the options are \naive" for a na ve round robin
allocation, \linear" for allocation using the linear scan algorithm, or \graph" for allocation
using the graph coloring algorithm. See Chapter 7 for a detailed description of these register
allocation algorithms. The optional
-r
switch forces the compiler to allocate only up to a
certain number of physical registers, specified as argument; the argument can take values
between 3 and 18, inclusive, for linear register allocation, and between 1 and 18, inclusive,
for the other two register allocation methods. If this switch is not specified, then a default
value of 8 is used. Registers are allocated starting at
$t0
2
.
For example, here is the command-line syntax for compiling the
Factorial
program to
SPIM code allocating up to 18 (the maximum) physical registers using the na ve allocation
procedure:
>$j/j--/bin/j---snaive-r18$j/j--/tests/spim/Factorial.java
The compiler first translates the source program to JVM byte code in memory, which
in turn is translated into SPIM code. The compiler prints to
STDOUT
the details of the
translation process for each method, such as the basic block structure with JVM instructions
represented as tuples, the high-level (HIR) instructions in each basic block, the low-level
(LIR) instructions for each basic block before allocation of physical registers to virtual
registers, the intervals and associated ranges for each register, and the LIR instructions
for each basic block after the physical registers have been allocated and spills have been
handled where needed. In addition, the compiler also produces a target .s file containing the
SPIM code (
Factorial.s
in above example) in the folder in which the command is run.
One can specify an alternate folder name for the target .s file using the
-d
command-line
switch.
Once the .s file has been produced, there are several ways to execute it using the SPIM
simulator. The simplest way is to run the following command:
>spim-file<inputfile>
where
spim
is the command-line version of the SPIM simulator. The
-file
argument spec-
ifies the name of the file with a .s extension that contains the SPIM code to execute. For
example, we can execute the
Factorial.s
file from above as
>spim-fileFactorial.s
which produces the following output:
SPIMVersion8.0ofJanuary8,2010
Copyright1990-2010,JamesR.Larus.
AllRightsReserved.
SeethefileREADMEforafullcopyrightnotice.
Loaded:/usr/lib/spim/exceptions.s
5040
5040
2
That is a total of up to eighteen registers (
$t0,$t1,...,$t9,$s0,...,$s7
) available for
allocation.
Search WWH ::
Custom Search