|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object minijava.translate.PigletContext
public final class PigletContext
A wrapper class that packages a logical context in a given translation step.
It encapsulates a mapping of symbols (in MJ) to its allocated temporaries
(in Piglet), and a context node. As an argument type, the node represent the
parent node to which Piglet statements instantiated in a translation step
attach themselves. More concretely, this parent node is a
StmtList
.
Field Summary | |
---|---|
Class |
currentClass
The reference to the class that a method belongs to, in a translation step that reads the procedural statements within said method. |
SymbolTable<PigletTemp> |
tempBinding
A mapping between MiniJava variables and Piglet Temps they are assigned to. |
Constructor Summary | |
---|---|
PigletContext()
Creates a helper context, where the node reference is a StmtList node. |
|
PigletContext(SymbolTable<PigletTemp> binding,
Node node)
|
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(Exp cond,
PigletLabel alt)
Creates a CJumpStmt node with the given
conditional expression, and Label of the false branch, then attaches
it to the context. |
void |
attachErrorStmt()
Creates a ErrorStmt node and then attaches
it to the context. |
void |
attachHLoadStmt(PigletTemp dest,
Exp addr,
int offset)
Creates a HLoadStmt node with the given Temp
where to the loaded data is to be stored, the expression that evaluates
to the address of the data, and the offset into that address, and then
attaches it to the context. |
void |
attachHStoreStmt(Exp addr,
int offset,
Exp val)
Creates a HStoreStmt node with the given
expression that evaluates to the address where the data is to be to
stored, the offset into that address, and the expression that evaluates
to the value to be stored, then attaches it to the context. |
void |
attachJumpStmt(PigletLabel label)
Creates a JumpStmt node with the given Label
argument, then attaches it as a Stmt node
to the context. |
void |
attachLabeledNoOpStmt(PigletLabel 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 |
attachMoveStmt(PigletTemp 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 . |
NodeListOptional |
getNodeListContext()
|
StmtList |
getStmtListContext()
|
void |
setCurrentClass(Class cls)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public SymbolTable<PigletTemp> tempBinding
public Class currentClass
Constructor Detail |
---|
public PigletContext(SymbolTable<PigletTemp> binding, Node node)
public PigletContext()
StmtList
node. There is no Temp binding in
this context (at least initially).
Method Detail |
---|
public void setCurrentClass(Class cls)
public StmtList getStmtListContext()
public NodeListOptional getNodeListContext()
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 attachMoveStmt(PigletTemp 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(Exp cond, PigletLabel alt)
CJumpStmt
node with the given
conditional expression, and Label of the false branch, then attaches
it to the context.
cond
- the conditional expressionalt
- the Label of the false branchpublic void attachJumpStmt(PigletLabel label)
JumpStmt
node with the given Label
argument, then attaches it as a Stmt
node
to the context.
label
- the labelpublic void attachLabeledNoOpStmt(PigletLabel 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 and then attaches
it to the context.
public void attachHLoadStmt(PigletTemp dest, Exp addr, int offset)
HLoadStmt
node with the given Temp
where to the loaded data is to be stored, the expression that evaluates
to the address of the data, and the offset into that address, and then
attaches it to the context.
dest
- the Temp where to the loaded data is to be storedaddr
- evaluates to the address of the dataoffset
- the offset into the addresspublic void attachHStoreStmt(Exp addr, int offset, Exp val)
HStoreStmt
node with the given
expression that evaluates to the address where the data is to be to
stored, the offset into that address, and the expression that evaluates
to the value to be stored, then attaches it to the context.
addr
- evaluates to the address where data is to be storedoffset
- the offset into the addressval
- evaluates to the value to be storedpublic void attachProcedure(Procedure proc)
NodeListOptional
.
proc
- the Procedure
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |