at.dms.kjc.rstream
Class FusionState

java.lang.Object
  extended by at.dms.kjc.rstream.FusionState
Direct Known Subclasses:
FilterFusionState, JoinerFusionState, SplitterFusionState

public abstract class FusionState
extends Object

This abstract class represents the state necessary for each FlatNode in the application to be converted to imperative SIR code by GenerateCCode. Any state that can be shared over FilterFusionState, JoinerFusionState, and SplitterFusionState is here. Plus it defines a common interface (getWork(), initTasks()) for those nodes.

Author:
Michael Gordon

Field Summary
protected static String BACKUPCOUNTER
           
static String BUFFERNAME
          the variaible prefix of the incoming buffer
protected  JVariableDefinition[] bufferVar
          the size of the incoming buffers for each incoming edge
protected static HashMap<FlatNode,FusionState> fusionState
          a hashmap of all fusionstates created so far, indexed by flatnode
protected  int myUniqueID
          the unique ID of this fusionstate
protected  boolean necessary
          true if this node *needs* to code generated for correctness false for some identity's and duplicate splitters
protected  FlatNode node
          the flatnode that this object represents
protected  int[] remaining
          the number of items remaining on the tape after the init stage has completed for each incoming channel of the node
 
Constructor Summary
protected FusionState(FlatNode node)
          create a new FusionState object that represents *node*, note one should never create fusionstates, they are created using getFusionState().
 
Method Summary
abstract  int getBufferSize(FlatNode prev, boolean init)
          get the size of the buffer from *prev* to this node
abstract  JVariableDefinition getBufferVar(FlatNode prev, boolean init)
          Return the JVariableDefinition associated with the incoming buffer from *prev* to this node.
static FusionState getFusionState(FlatNode node)
          Given FlatNode *node*, return the fusion state object representing it.
 FlatNode getNode()
          Return the FlatNode associated with this FusionState
abstract  int getRemaining(FlatNode prev, boolean init)
          get the number of items remaining after the init stage on the incoming buffer from *prev* to this node
abstract  JStatement[] getWork(JBlock enclosingBlock, boolean isInit)
          get the block that will perform the init stage (*isInit* = true) or the steady-state (*isInit* = false), add any var decls to *enclosingBlock*
abstract  void initTasks(Vector<JFieldDeclaration> fields, Vector<JMethodDeclaration> functions, JBlock initFunctionCalls, JBlock main)
          called by GenerateCCode so that this node can add any initialization code to the application
protected  JStatement intAssignStm(JVariableDefinition def, int value)
          Returnn a JAssignmentStatement that will assign *value* to def*.
 boolean isNecesary()
           
protected  JVariableDefinition makeBuffer(int bufferSize, CType elementType, String bufferName)
          create a JVarDef representing an array of type *elementType* (which itself can be an array, with *bufferSize* elements and name *bufferName*.
protected  JStatement remainingBackupLoop(JVariableDefinition buffer, JVariableDefinition loopCounterBackup, int offset, int remainingItems)
          Return SIR code to move *remainingItems* to the beginning of *buffer* starting at *offset*, using *loopCounterBackup* as the induction variable of the loop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

necessary

protected boolean necessary
true if this node *needs* to code generated for correctness false for some identity's and duplicate splitters


node

protected FlatNode node
the flatnode that this object represents


remaining

protected int[] remaining
the number of items remaining on the tape after the init stage has completed for each incoming channel of the node


bufferVar

protected JVariableDefinition[] bufferVar
the size of the incoming buffers for each incoming edge


fusionState

protected static HashMap<FlatNode,FusionState> fusionState
a hashmap of all fusionstates created so far, indexed by flatnode


myUniqueID

protected int myUniqueID
the unique ID of this fusionstate


BUFFERNAME

public static String BUFFERNAME
the variaible prefix of the incoming buffer


BACKUPCOUNTER

protected static String BACKUPCOUNTER
Constructor Detail

FusionState

protected FusionState(FlatNode node)
create a new FusionState object that represents *node*, note one should never create fusionstates, they are created using getFusionState().

Method Detail

getBufferSize

public abstract int getBufferSize(FlatNode prev,
                                  boolean init)
get the size of the buffer from *prev* to this node


getRemaining

public abstract int getRemaining(FlatNode prev,
                                 boolean init)
get the number of items remaining after the init stage on the incoming buffer from *prev* to this node


isNecesary

public boolean isNecesary()

initTasks

public abstract void initTasks(Vector<JFieldDeclaration> fields,
                               Vector<JMethodDeclaration> functions,
                               JBlock initFunctionCalls,
                               JBlock main)
called by GenerateCCode so that this node can add any initialization code to the application


getWork

public abstract JStatement[] getWork(JBlock enclosingBlock,
                                     boolean isInit)
get the block that will perform the init stage (*isInit* = true) or the steady-state (*isInit* = false), add any var decls to *enclosingBlock*


getFusionState

public static FusionState getFusionState(FlatNode node)
Given FlatNode *node*, return the fusion state object representing it. This forces only one fusion state to be created for each node. Remember all fusionstates in a hashmap indexed by FlatNode.


getBufferVar

public abstract JVariableDefinition getBufferVar(FlatNode prev,
                                                 boolean init)
Return the JVariableDefinition associated with the incoming buffer from *prev* to this node.


getNode

public FlatNode getNode()
Return the FlatNode associated with this FusionState


intAssignStm

protected JStatement intAssignStm(JVariableDefinition def,
                                  int value)
Returnn a JAssignmentStatement that will assign *value* to def*.


remainingBackupLoop

protected JStatement remainingBackupLoop(JVariableDefinition buffer,
                                         JVariableDefinition loopCounterBackup,
                                         int offset,
                                         int remainingItems)
Return SIR code to move *remainingItems* to the beginning of *buffer* starting at *offset*, using *loopCounterBackup* as the induction variable of the loop.


makeBuffer

protected JVariableDefinition makeBuffer(int bufferSize,
                                         CType elementType,
                                         String bufferName)
create a JVarDef representing an array of type *elementType* (which itself can be an array, with *bufferSize* elements and name *bufferName*.