minijava.translate
Class PigletContext

java.lang.Object
  extended by minijava.translate.PigletContext

public final class PigletContext
extends java.lang.Object

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.

Author:
Santoso Wijaya

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

tempBinding

public SymbolTable<PigletTemp> tempBinding
A mapping between MiniJava variables and Piglet Temps they are assigned to.


currentClass

public Class currentClass
The reference to the class that a method belongs to, in a translation step that reads the procedural statements within said method.

Constructor Detail

PigletContext

public PigletContext(SymbolTable<PigletTemp> binding,
                     Node node)

PigletContext

public PigletContext()
Creates a helper context, where the node reference is a StmtList node. There is no Temp binding in this context (at least initially).

Method Detail

setCurrentClass

public void setCurrentClass(Class cls)

getStmtListContext

public StmtList getStmtListContext()

getNodeListContext

public NodeListOptional getNodeListContext()

attach

public 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.

Parameters:
statement - the statement subtree

attachMoveStmt

public 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.

Parameters:
temp - the Temp to assign the expression to
expr - the expression subtree

attachCJumpStmt

public 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.

Parameters:
cond - the conditional expression
alt - the Label of the false branch

attachJumpStmt

public void attachJumpStmt(PigletLabel label)
Creates a JumpStmt node with the given Label argument, then attaches it as a Stmt node to the context.

Parameters:
label - the label

attachLabeledNoOpStmt

public 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

Parameters:
label - the label

attachErrorStmt

public void attachErrorStmt()
Creates a ErrorStmt node and then attaches it to the context.


attachHLoadStmt

public 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.

Parameters:
dest - the Temp where to the loaded data is to be stored
addr - evaluates to the address of the data
offset - the offset into the address

attachHStoreStmt

public 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.

Parameters:
addr - evaluates to the address where data is to be stored
offset - the offset into the address
val - evaluates to the value to be stored

attachProcedure

public void attachProcedure(Procedure proc)
Attaches a Procedure node to the context, which is pre-conditioned to be a NodeListOptional.

Parameters:
proc - the Procedure