ptolemy.codegen.java.domains.sdf.kernel
Class SDFDirector

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.codegen.kernel.CodeGeneratorHelper
          extended by ptolemy.codegen.actor.Director
              extended by ptolemy.codegen.java.actor.sched.StaticSchedulingDirector
                  extended by ptolemy.codegen.java.domains.sdf.kernel.SDFDirector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ActorCodeGenerator, ComponentCodeGenerator, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class SDFDirector
extends StaticSchedulingDirector

Code generator helper associated with the SDFDirector class. This class is also associated with a code generator.

Since:
Ptolemy II 8.0
Version:
$Id: SDFDirector.java 57044 2010-01-27 22:41:05Z cxh $
Author:
Ye Zhou, Gang Zhou
See Also:
Serialized Form
Accepted Rating:
Red (eal)
Proposed Rating:
Yellow (zgang)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.codegen.kernel.CodeGeneratorHelper
CodeGeneratorHelper.Channel, CodeGeneratorHelper.VariableScope
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
private  int _portNumber
           
 
Fields inherited from class ptolemy.codegen.actor.Director
_director, _eol, _INDENT1, _INDENT2, _INDENT3, _INDENT4
 
Fields inherited from class ptolemy.codegen.kernel.CodeGeneratorHelper
_codeGenerator, _codeStream, _parseTreeCodeGenerator, _portConversions, _referencedParameters
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Constructor Summary
SDFDirector(SDFDirector sdfDirector)
          Construct the code generator helper associated with the given SDFDirector.
 
Method Summary
protected  java.lang.String _createDynamicOffsetVariables(IOPort port)
          Create offset variables for the channels of the given port.
protected  java.lang.String _createOffsetVariablesIfNeeded()
          Check to see if variables are needed to represent read and write offsets for the ports in the director's container.
protected  java.lang.String _createOffsetVariablesIfNeeded(IOPort port, int channelNumber, int readTokens, int writeTokens)
          Check for the given channel of the given port to see if variables are needed for recording read offset and write offset.
private  int _padBuffer(IOPort port, int channelNumber)
          Pad the buffer for the channel of the given port with the given channel number to a power of two.
protected  void _updatePortBufferSize()
          Check to see if the buffer size for the current schedule is greater than the previous size.
 java.lang.String createOffsetVariablesIfNeeded()
          Generate code for declaring read and write offset variables if needed.
 java.lang.String generateInitializeCode()
          Generate the initialize code for the associated SDF director.
 java.lang.String generatePreinitializeCode()
          Generate the preinitialize code for this director.
 void generateTransferInputsCode(IOPort inputPort, java.lang.StringBuffer code)
          Generate code for transferring enough tokens to complete an internal iteration.
 void generateTransferOutputsCode(IOPort outputPort, java.lang.StringBuffer code)
          Generate code for transferring enough tokens to fulfill the output production rate.
 int getBufferSize(IOPort port, int channelNumber)
          Return the buffer size of a given channel (i.e, a given port and a given channel number).
 
Methods inherited from class ptolemy.codegen.java.actor.sched.StaticSchedulingDirector
generateFireCode, generateMainLoop, generateVariableDeclaration
 
Methods inherited from class ptolemy.codegen.actor.Director
_ceilToPowerOfTwo, _getIndentPrefix, _updateConnectedPortsOffset, _updatePortOffset, generateCodeForGet, generateCodeForSend, generateFireFunctionCode, generateModeTransitionCode, generateOffset, generatePostfireCode, generateVariableInitialization, generateWrapupCode, getComponent, getHeaderFiles, getIncludeDirectories, getLibraries, getLibraryDirectories, getModifiedVariables, getReference, getReference, getReferenceChannels, getWCET
 
Methods inherited from class ptolemy.codegen.kernel.CodeGeneratorHelper
_createBufferSizeAndOffsetMap, _createInputBufferSizeAndOffsetMap, _findClosedParen, _generateBlockCode, _generateBlockCode, _generateFireCode, _generateTypeConvertMethod, _generateTypeConvertStatement, _generateTypeConvertStatements, _getCastType, _getChannelAndOffset, _getFireFunctionArguments, _getHelper, _getHelper, _getReference, _getReferenceChannels, _getTypeConvertChannels, _getTypeConvertReference, _indexOf, _replaceMacro, addFunctionUsed, addNewTypeUsed, analyzeTypeConvert, checkLocal, checkRemote, codeGenType, copyFilesToCodeDirectory, generateChannelOffset, generateFireFunctionCode2, generateName, generateOffset, generatePortReference, generatePrefireCode, generateSimpleName, generateTypeConvertFireCode, generateTypeConvertFireCode, generateVariableName, getBufferSize, getCodeGenerator, getDefaultBlocks, getDirector, getDirectorHelper, getFunctionInvocation, getNewInvocation, getObject, getParameterValue, getParseTreeCodeGenerator, getPort, getRates, getReadOffset, getReference, getReference, getReference, getReference, getSharedCode, getSinkChannels, getSize, getSourceChannel, getWriteOffset, isPrimitive, isPrimitive, parseList, processCode, resetInputPortsOffset, setBufferSize, setCodeGenerator, setReadOffset, setWriteOffset, targetType, toString
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _description, _exportMoMLContents, _getContainedObject, _isMoMLSuppressed, _markContentsDerived, _propagateExistence, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, attributeTypeChanged, clone, clone, containedObjectsIterator, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getContainer, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setName, setPersistent, setSource, sortContainedObjects, toplevel, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_portNumber

private int _portNumber
Constructor Detail

SDFDirector

public SDFDirector(SDFDirector sdfDirector)
Construct the code generator helper associated with the given SDFDirector.

Parameters:
sdfDirector - The associated ptolemy.domains.sdf.kernel.SDFDirector
Method Detail

createOffsetVariablesIfNeeded

public java.lang.String createOffsetVariablesIfNeeded()
                                               throws IllegalActionException
Generate code for declaring read and write offset variables if needed.

Specified by:
createOffsetVariablesIfNeeded in interface ActorCodeGenerator
Overrides:
createOffsetVariablesIfNeeded in class Director
Returns:
The generated code.
Throws:
IllegalActionException - If thrown while creating offset variables.

generateInitializeCode

public java.lang.String generateInitializeCode()
                                        throws IllegalActionException
Generate the initialize code for the associated SDF director.

Specified by:
generateInitializeCode in interface ComponentCodeGenerator
Overrides:
generateInitializeCode in class Director
Returns:
The generated initialize code.
Throws:
IllegalActionException - If the helper associated with an actor throws it while generating initialize code for the actor.

generatePreinitializeCode

public java.lang.String generatePreinitializeCode()
                                           throws IllegalActionException
Generate the preinitialize code for this director. The preinitialize code for the director is generated by appending the preinitialize code for each actor.

Specified by:
generatePreinitializeCode in interface ActorCodeGenerator
Overrides:
generatePreinitializeCode in class StaticSchedulingDirector
Returns:
The generated preinitialize code.
Throws:
IllegalActionException - If getting the helper fails, or if generating the preinitialize code for a helper fails, or if there is a problem getting the buffer size of a port.

generateTransferInputsCode

public void generateTransferInputsCode(IOPort inputPort,
                                       java.lang.StringBuffer code)
                                throws IllegalActionException
Generate code for transferring enough tokens to complete an internal iteration.

Overrides:
generateTransferInputsCode in class Director
Parameters:
inputPort - The port to transfer tokens.
code - The string buffer that the generated code is appended to.
Throws:
IllegalActionException - If thrown while transferring tokens.

generateTransferOutputsCode

public void generateTransferOutputsCode(IOPort outputPort,
                                        java.lang.StringBuffer code)
                                 throws IllegalActionException
Generate code for transferring enough tokens to fulfill the output production rate.

Overrides:
generateTransferOutputsCode in class Director
Parameters:
outputPort - The port to transfer tokens.
code - The string buffer that the generated code is appended to.
Throws:
IllegalActionException - If thrown while transferring tokens.

getBufferSize

public int getBufferSize(IOPort port,
                         int channelNumber)
                  throws IllegalActionException
Return the buffer size of a given channel (i.e, a given port and a given channel number). The default value is 1. If the port is an output port, then the buffer size is obtained from the inside receiver. If it is an input port, then it is obtained from the specified port.

Overrides:
getBufferSize in class Director
Parameters:
port - The given port.
channelNumber - The given channel number.
Returns:
The buffer size of the given channel.
Throws:
IllegalActionException - If the channel number is out of range or if the port is neither an input nor an output.
See Also:
CodeGeneratorHelper.setBufferSize(IOPort, int, int)

_createDynamicOffsetVariables

protected java.lang.String _createDynamicOffsetVariables(IOPort port)
                                                  throws IllegalActionException
Create offset variables for the channels of the given port. The offset variables are generated unconditionally, but this method is only called when dynamic multiport references are desired. The buffers should be padded before this method is called.

Parameters:
port - The port whose offset variables are generated.
Returns:
Code that declares the read and write offset variables.
Throws:
IllegalActionException - If getting the rate or reading parameters throws it.

_createOffsetVariablesIfNeeded

protected java.lang.String _createOffsetVariablesIfNeeded()
                                                   throws IllegalActionException
Check to see if variables are needed to represent read and write offsets for the ports in the director's container. If variables are needed, create them.

Returns:
Code that declares the read and write offset variables.
Throws:
IllegalActionException - If getting the rate or reading parameters throws it.

_createOffsetVariablesIfNeeded

protected java.lang.String _createOffsetVariablesIfNeeded(IOPort port,
                                                          int channelNumber,
                                                          int readTokens,
                                                          int writeTokens)
                                                   throws IllegalActionException
Check for the given channel of the given port to see if variables are needed for recording read offset and write offset. If the buffer size of a channel divides the readTokens and writeTokens given in the argument, then there is no need for the variables. Otherwise the integer offsets are replaced with variables and the code to initialize these variables are generated. If padded buffers are desired (based on the padBuffers parameter of the CodeGenerator), pad the buffers.

Parameters:
port - The port to be checked.
channelNumber - The channel number.
readTokens - The number of tokens read.
writeTokens - The number of tokens written.
Returns:
Code that declares the read and write offset variables.
Throws:
IllegalActionException - If getting the rate or reading parameters throws it.

_updatePortBufferSize

protected void _updatePortBufferSize()
                              throws IllegalActionException
Check to see if the buffer size for the current schedule is greater than the previous size. If so, set the buffer size to the current buffer size needed.

Throws:
IllegalActionException - If thrown while getting helper or buffer size.

_padBuffer

private int _padBuffer(IOPort port,
                       int channelNumber)
                throws IllegalActionException
Pad the buffer for the channel of the given port with the given channel number to a power of two. Return the new buffer size.

Parameters:
port - The port which has the buffer to pad.
channelNumber - The number of the channel which has the buffer to pad.
Returns:
The size of the new buffer.
Throws:
IllegalActionException - If thrown when getting the port's helper.