|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object spiglet.translate.KangaContext
public final class KangaContext
This class represents a context in a given step of translation between
Spiglet and Kanga. It stores a context
node where statements
are attached (as well as helper functions to attach different kinds of
statements).
Field Summary | |
---|---|
int |
sp
The stack pointer. |
java.util.Map<java.lang.String,KangaStorage> |
varMap
The mapping between a Spiglet temporary (represented by the temporary's ordinal number in string) and its storage in a Kanga construct. |
Constructor Summary | |
---|---|
KangaContext(Node node,
java.util.Map<java.lang.String,KangaStorage> storageMap)
Create a context with the given context node, a premade mapping of variables to Kanga storage (registers, really). |
Method Summary | |
---|---|
void |
attach(Node statement)
Attaches a Stmt (possibly a
(Label)? Stmt sequence) node to the context node, which in
pre-condition assumed to be a StmtList node
or a NodeListOptional node. |
void |
attachALoadStmt(KangaReg reg,
int spillOffset)
Creates a ALoadStmt node with the given
spill offset and register to where loaded data is to be stored, then
attaches the statement node to the context. |
void |
attachAStoreStmt(int spillOffset,
KangaReg reg)
Creates a AStoreStmt node with the given
spill offset and register where the data to be stored is, then attaches
the node to the context. |
void |
attachCallStmt(SimpleExp expr)
Creates a SimpleExp node with the given
expression, then attaches it to the context. |
void |
attachCJumpStmt(KangaReg cond,
KangaLabel alt)
Creates a CJumpStmt node with the given
Reg as the conditional expression, and the given Label as the false
branch destination, and then attaches the node to the context. |
void |
attachErrorStmt()
Creates an attaches a ErrorStmt node
to the context. |
void |
attachHLoadStmt(KangaReg dest,
KangaReg addr,
IntegerLiteral offset)
Creates a HLoadStmt node with the given
Regs (referring to where to store the data and where the address pointer
is stored, respectively) and offset node, then attaches it to the
context. |
void |
attachHStoreStmt(KangaReg addr,
IntegerLiteral offset,
KangaReg val)
Creates a HStoreStmt node with the given
Regs (referring to the address to which to store the data and the the
data itself to be stored, respectively) and offset node, then attaches
it to the context. |
void |
attachJumpStmt(KangaLabel label)
Creates a JumpStmt node with the given Label
argument, then attaches it as a Stmt node
to the context. |
void |
attachLabeledNoOpStmt(KangaLabel label)
Creates a NoOpStmt node sequenced with a
Label node with the given label value, then
attaches it as a Stmt node to the context |
void |
attachLabeledStmt(KangaLabel label,
Stmt statement)
Creates a node sequence of Label and Stmt to be attached to the context. |
void |
attachMoveStmt(KangaReg reg,
Exp expr)
Creates a MoveStmt node with the given
Reg and expression subtree, then attaches it as a
Stmt node to the context. |
void |
attachPassArgStmt(int offset,
KangaReg reg)
Creates a PassArgStmt node with the given
offset and register, then attaches it to the context. |
void |
attachProcedure(Procedure proc)
Attaches a Procedure node to the context, which is pre-conditioned to be a NodeListOptional node. |
int |
getMaxCallArgs()
Returns the maximum number of arguments of a call in the body of this context. |
NodeListOptional |
getNodeListContext()
Returns the context node as a NodeListOptional
node. |
StmtList |
getStmtListContext()
Returns the context node as a StmtList node. |
void |
offerMaxCallArgs(int args)
Sets the context's maxCallArgs , the maximum number of arguments
of a call in the body of this context, if the offered number is larger
than it is currently. |
void |
restoreCalleeRegisters()
In this context, generate code that pops the values stored on the stack back to callee-saved registers that were previously saved. |
void |
restoreCallerRegisters()
In this context, generate code that pops the values stored on the stack back to caller-saved registers that were previously saved. |
void |
saveCaleeRegisters()
Given the mapping of variables and kanga storage constructs (registers) in this context, generate code that pushes the values stored in callee-saved registers in the mapping onto the stack. |
void |
saveCalerRegisters()
Given the mapping of variables and kanga storage constructs (registers) in this context, generate code that pushes the values stored in caller-saved registers in the mapping onto the stack. |
int |
spillReg(KangaReg reg)
Injects Kanga code that pushes the value stored in the given register on to the stack. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public java.util.Map<java.lang.String,KangaStorage> varMap
public int sp
SpilledArg
Kanga stack in the current frame.
Constructor Detail |
---|
public KangaContext(Node node, java.util.Map<java.lang.String,KangaStorage> storageMap)
storageMap
- the mapping of variables to Kanga storage constructnode
- the contextMethod Detail |
---|
public int spillReg(KangaReg reg)
reg
- the register where the value to be spilled is
public void offerMaxCallArgs(int args)
maxCallArgs
, the maximum number of arguments
of a call in the body of this context, if the offered number is larger
than it is currently.
args
- the offered number of maximum call argumentspublic int getMaxCallArgs()
public StmtList getStmtListContext()
StmtList
node.
Pre-condition is assumed.
StmtList
nodepublic NodeListOptional getNodeListContext()
NodeListOptional
node. Pre-condition is assumed.
NodeListOptional
nodepublic void saveCaleeRegisters()
public void restoreCalleeRegisters()
public void saveCalerRegisters()
public void restoreCallerRegisters()
public void attach(Node statement)
Stmt
(possibly a
(Label)? Stmt
sequence) node to the context node, which in
pre-condition assumed to be a StmtList
node
or a NodeListOptional
node.
statement
- the statement subtreepublic void attachLabeledStmt(KangaLabel label, Stmt statement)
label
- the labelstatement
- the labeled statementpublic void attachLabeledNoOpStmt(KangaLabel label)
NoOpStmt
node sequenced with a
Label
node with the given label value, then
attaches it as a Stmt
node to the context
label
- the labelpublic void attachErrorStmt()
ErrorStmt
node
to the context.
public void attachJumpStmt(KangaLabel label)
JumpStmt
node with the given Label
argument, then attaches it as a Stmt
node
to the context.
label
- the labelpublic void attachMoveStmt(KangaReg reg, Exp expr)
MoveStmt
node with the given
Reg and expression subtree, then attaches it as a
Stmt
node to the context.
reg
- the Reg to assign the expression toexpr
- the expression subtreepublic void attachCJumpStmt(KangaReg cond, KangaLabel alt)
CJumpStmt
node with the given
Reg as the conditional expression, and the given Label as the false
branch destination, and then attaches the node to the context.
cond
- the Reg where the evaluated conditional expression is storedalt
- the Label of the false branchpublic void attachHLoadStmt(KangaReg dest, KangaReg addr, IntegerLiteral offset)
HLoadStmt
node with the given
Regs (referring to where to store the data and where the address pointer
is stored, respectively) and offset node, then attaches it to the
context.
dest
- the Reg to which the loaded data is to be storedaddr
- the Reg that contains the address valueoffset
- contains the byte value of the offset into the addresspublic void attachHStoreStmt(KangaReg addr, IntegerLiteral offset, KangaReg val)
HStoreStmt
node with the given
Regs (referring to the address to which to store the data and the the
data itself to be stored, respectively) and offset node, then attaches
it to the context.
addr
- the Reg that contains the address valueoffset
- contains the byte value of the offset into the addressval
- the Reg that contains the data to be storedpublic void attachAStoreStmt(int spillOffset, KangaReg reg)
AStoreStmt
node with the given
spill offset and register where the data to be stored is, then attaches
the node to the context.
spillOffset
- the spill offset where the data is to be storedreg
- the register where the data ispublic void attachALoadStmt(KangaReg reg, int spillOffset)
ALoadStmt
node with the given
spill offset and register to where loaded data is to be stored, then
attaches the statement node to the context.
reg
- the register to where loaded data is storedspillOffset
- the offset of the stack where the data ispublic void attachCallStmt(SimpleExp expr)
SimpleExp
node with the given
expression, then attaches it to the context.
expr
- the expression subtreepublic void attachPassArgStmt(int offset, KangaReg reg)
PassArgStmt
node with the given
offset and register, then attaches it to the context.
offset
- the offset of the spilled argument stackreg
- the register from which the argument is spilledpublic void attachProcedure(Procedure proc)
NodeListOptional
node.
proc
- the procedure
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |