Java Reference
In-Depth Information
/**WrapperforSPIM.exit().*/
publicstaticvoidexit(){}
/**WrapperforSPIM.exit2().*/
publicstaticvoidexit2(intstatus){}
}
Because the SPIM class is defined in the package spim , that package name is part of the
label for the entry point to each SPIM method, for example,
spim.SPIM.printInt:
6.3.6 Generating SPIM Code
After LIR with virtual registers has been generated, we invoke register allocation for map-
ping the virtual registers to physical registers. In this chapter we use a na ve register alloca-
tion scheme where physical registers are arbitrarily assigned to virtual registers (see Section
7.2). Register allocation is discussed in greater detail in Chapter 7.
Once virtual registers have been mapped to physical registers, translating LIR to SPIM
code is pretty straightforward.
1. We iterate through the list of methods for each class; for each method, we do the
following:
(a) We generate a label for the method's entry point, for example,
Factorial.computeIter:
(b) We generate code to push a new frame onto the run-time stack (remember this
stack grows downward in memory) and then code to save all our registers. In this
compiler, we treat all of SPIM's general-purpose registers $t0 to $t9 and $s0 to
$s7 as callee-saved registers; that is, we make it the responsibility of the invoked
method to save any registers it uses. As we shall see in Chapter 7, some register
allocation schemes do otherwise; that is, the caller saves just those registers that
contain meaningful values when call is encountered.
For computeIter() , the LIR uses seven general purpose registers, so we generate
the following:
subu $sp,$sp,36 #Stackframeis36byteslong
sw $ra,32($sp) #Savereturnaddress
sw $fp,28($sp) #Saveframepointer
sw $t0,24($sp) #Saveregister$t0
sw $t1,20($sp) #Saveregister$t1
sw $t2,16($sp) #Saveregister$t2
sw $t3,12($sp) #Saveregister$t3
sw $t4,8($sp) #Saveregister$t4
sw $t5,4($sp) #Saveregister$t5
sw $t6,0($sp) #Saveregister$t6
addiu $fp,$sp,32 #Saveframepointer
(c) Because all branches in the code are expressed as branches to basic blocks, a
unique label for each basic block is generated into the code; for example,
Factorial.computeIter.2:
 
Search WWH ::




Custom Search