|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object piglet.translate.SpigletContext
public final class SpigletContext
This class represents a context in a given step of translation between
Piglet and Spiglet. It stores a context
node where statements
are attached (as well as helper functions to attach different kinds of
statements), a mapping of Labels and Temps (from Piglet Labels and Temps),
and the number of parameter Temps (when translating a Procedure) that aren't
supposed to be mapped.
Constructor Summary | |
---|---|
SpigletContext(Node node)
Creates a SpigletContext with the given context node and an empty variable mapping. |
|
SpigletContext(Node node,
java.util.Map<java.lang.String,SpigletTemp> varMap)
Creates a SpigletContext with the given context node and pre-made variable mapping. |
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 |
attachCJumpStmt(SpigletTemp cond,
SpigletLabel alt)
Creates a CJumpStmt node with the given
Temp 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(SpigletTemp dest,
SpigletTemp addr,
IntegerLiteral offset)
Creates a HLoadStmt node with the given
Temps (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(SpigletTemp addr,
IntegerLiteral offset,
SpigletTemp val)
Creates a HStoreStmt node with the given
Temps (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 contex. |
void |
attachJumpStmt(SpigletLabel label)
Creates a JumpStmt node with the given Label
argument, then attaches it as a Stmt node
to the context. |
void |
attachLabeledNoOpStmt(SpigletLabel 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(SpigletLabel label,
Stmt statement)
Creates a node sequence of Label and Stmt to be attached to the context. |
void |
attachMoveStmt(SpigletTemp temp,
Exp expr)
Creates a MoveStmt node with the given
Temp and expression subtree, then attaches it as a
Stmt node to the context. |
void |
attachProcedure(Procedure proc)
Attaches a Procedure node to the context, which is pre-conditioned to be a NodeListOptional node. |
NodeListOptional |
getNodeListContext()
Returns the context node as a NodeListOptional
node. |
StmtList |
getStmtListContext()
Returns the context node as a StmtList node. |
SpigletTemp |
map(java.lang.String var)
Maps a variable to a Spiglet temporary. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SpigletContext(Node node, java.util.Map<java.lang.String,SpigletTemp> varMap)
node
- the contextvarMap
- the mapping of variables to Spiglet temporariespublic SpigletContext(Node node)
node
- the contextMethod Detail |
---|
public StmtList getStmtListContext()
StmtList
node.
Pre-condition is assumed.
StmtList
nodepublic NodeListOptional getNodeListContext()
NodeListOptional
node. Pre-condition is assumed.
NodeListOptional
nodepublic SpigletTemp map(java.lang.String var)
var
- the variable to look up
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(SpigletLabel label, Stmt statement)
label
- the labelstatement
- the labeled statementpublic void attachLabeledNoOpStmt(SpigletLabel 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(SpigletLabel label)
JumpStmt
node with the given Label
argument, then attaches it as a Stmt
node
to the context.
label
- the labelpublic void attachMoveStmt(SpigletTemp temp, Exp expr)
MoveStmt
node with the given
Temp and expression subtree, then attaches it as a
Stmt
node to the context.
temp
- the Temp to assign the expression toexpr
- the expression subtreepublic void attachCJumpStmt(SpigletTemp cond, SpigletLabel alt)
CJumpStmt
node with the given
Temp as the conditional expression, and the given Label as the false
branch destination, and then attaches the node to the context.
cond
- the Temp where the evaluated conditional expression is storedalt
- the Label of the false branchpublic void attachHLoadStmt(SpigletTemp dest, SpigletTemp addr, IntegerLiteral offset)
HLoadStmt
node with the given
Temps (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 Temp to which the loaded data is to be storedaddr
- the Temp that contains the address valueoffset
- contains the byte value of the offset into the addresspublic void attachHStoreStmt(SpigletTemp addr, IntegerLiteral offset, SpigletTemp val)
HStoreStmt
node with the given
Temps (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 contex.
addr
- the Temp that contains the address valueoffset
- contains the byte value of the offset into the addressval
- the Temp that contains the data to be storedpublic 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 |