Java Reference
In-Depth Information
Yet another way of running the .s file is to launch the SPIM command-line interpreter,
and at the (spim) prompt, use SPIM commands load and run to load and execute a .s
file. The quit() command exits the SPIM interpreter. For example, Factorial.s can be
executed as follows:
>spim
SPIMVersion8.0ofJanuary8,2010
Copyright1990-2010,JamesR.Larus.
AllRightsReserved.
SeethefileREADMEforafullcopyrightnotice.
Loaded:/usr/lib/spim/exceptions.s
(spim)load"Factorial.s"
(spim)run
5040
5040
(spim)quit()
>
For a complete list of all the SPIM commands that are supported by the command-line
interpreter, execute the command help at the (spim) prompt.
Finally, one can load a .s file into the QtSpim user interface and click the run button
to execute the program. QtSpim offers a convenient interface for inspecting values in regis-
ters and memory, and also facilitates easy debugging of programs by stepping through the
instructions, one at a time.
E.4 Extending the JVM-to-SPIM Translator
The j-- compiler translates only a limited number of the JVM instructions to SPIM code,
just enough to compile and run the four j-- programs ( Factorial , GCD , Fibonacci , and
Formals ) under $j/j--/tests/spim . Nevertheless, it provides sucient machinery with
which one could build on to translate more instructions to SPIM code.
Unlike the j-- programs that are compiled for the JVM, the ones that target SPIM
cannot import any Java libraries. Any low-level library support for SPIM must be made
available in the form of SPIM run-time files: a .s file and a corresponding Java wrapper for
each library. For example, if j-- programs that target SPIM need to perform input/output
(IO) operations, it must import spim.SPIM , which is a Java wrapper for the SPIM.s file,
the run-time library for IO operations in SPIM. These two files can be found under $j/j
--/src/spim . The Java wrapper only needs to provide the function headers and not the
implementation, as it is only needed to make the compiler happy. The actual implementation
of the functions resides in the .s file. The compiler copies the run-time .s files verbatim to
the end of the compiled .s program. This saves us the trouble of loading the run-time files
separately into SPIM before loading the compiled .s program.
If one needs to extend the SPIM run-time to, say, support objects, strings, and arrays,
then for each one of them, a .s file and a Java wrapper must be implemented under $j/j
--/src/spim , and the following code in NEmitter.write() must be updated to copy the
new run-time libraries to the end of the compiled j-- program.
//EmitSPIMruntimecode;justSPIM.sfornow.
String[]libs={"SPIM.s"};
out.printf("#SPIMRuntime\n\n");
for(Stringlib:libs){
...
 
Search WWH ::




Custom Search