ptolemy.codegen.c.domains.hdf.kernel
Class HDFDirector

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.c.actor.sched.StaticSchedulingDirector
                  extended by ptolemy.codegen.c.domains.sdf.kernel.SDFDirector
                      extended by ptolemy.codegen.c.domains.hdf.kernel.HDFDirector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ActorCodeGenerator, ComponentCodeGenerator, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class HDFDirector
extends SDFDirector

Code generator helper class associated with the HDFDirector class.

Since:
Ptolemy II 6.0
Version:
$Id: HDFDirector.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Gang Zhou
See Also:
HDFDirector, Serialized Form
Accepted Rating:
Red (zgang)
Proposed Rating:
Yellow (cxh)

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[] _divisors
          An array of integers helping to establish the relationship between the configuration number of the container actor and the configuration numbers of contained actors.
private  Schedule[] _schedules
          An array of schedules, each element corresponding to one configuration.
 
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
HDFDirector(HDFDirector director)
          Construct the code generator helper associated with the given HDFDirector.
 
Method Summary
protected  java.lang.String _createOffsetVariablesIfNeeded()
          Create read and write offset variables if needed for any output port of the container actor and any input port of contained actors.
protected  java.lang.String _createOffsetVariablesIfNeeded(IOPort port)
          Check to see if variables are needed to represent read and write offsets for the given port.
protected  void _updateConfigurationNumber(java.lang.StringBuffer code)
          Generate code for updating configuration number of the container actor as a function of the configuration numbers of contained actors.
 java.lang.String createOffsetVariablesIfNeeded()
          Generate code for declaring read and write offset variables if needed.
 java.lang.String generateFireCode()
          Generate the code for the firing of actors according to the HDF schedules.
 java.lang.String generateInitializeCode()
          Generate the initialize code for the associated HDF director.
 void generateModeTransitionCode(java.lang.StringBuffer code)
          Generate mode transition code.
 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.
 
Methods inherited from class ptolemy.codegen.c.domains.sdf.kernel.SDFDirector
_createDynamicOffsetVariables, _createOffsetVariablesIfNeeded, _updatePortBufferSize, getBufferSize
 
Methods inherited from class ptolemy.codegen.c.actor.sched.StaticSchedulingDirector
generateMainLoop, generateVariableDeclaration
 
Methods inherited from class ptolemy.codegen.actor.Director
_ceilToPowerOfTwo, _getIndentPrefix, _updateConnectedPortsOffset, _updatePortOffset, generateCodeForGet, generateCodeForSend, generateFireFunctionCode, 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

_divisors

private int[] _divisors
An array of integers helping to establish the relationship between the configuration number of the container actor and the configuration numbers of contained actors.


_schedules

private Schedule[] _schedules
An array of schedules, each element corresponding to one configuration.

Constructor Detail

HDFDirector

public HDFDirector(HDFDirector director)
Construct the code generator helper associated with the given HDFDirector.

Parameters:
director - The associated ptolemy.domains.hdf.kernel.HDFDirector
Method Detail

createOffsetVariablesIfNeeded

public java.lang.String createOffsetVariablesIfNeeded()
                                               throws IllegalActionException
Generate code for declaring read and write offset variables if needed. First relay the information of firings per global iteration of the container actor to the contained actors if necessary. Then call the same method in its super class to create read and write offset variables if needed.

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

generateFireCode

public java.lang.String generateFireCode()
                                  throws IllegalActionException
Generate the code for the firing of actors according to the HDF schedules.

Specified by:
generateFireCode in interface ActorCodeGenerator
Overrides:
generateFireCode in class StaticSchedulingDirector
Returns:
The generated fire code.
Throws:
IllegalActionException - If the actor to be fired cannot find its associated helper or fire code generation fails.

generateInitializeCode

public java.lang.String generateInitializeCode()
                                        throws IllegalActionException
Generate the initialize code for the associated HDF director. Generate code for initializing the configuration number of the container actor.

Specified by:
generateInitializeCode in interface ComponentCodeGenerator
Overrides:
generateInitializeCode in class SDFDirector
Returns:
The generated initialize code.
Throws:
IllegalActionException - If thrown while calling the same method in its super class or updating the configuration number.

generateModeTransitionCode

public void generateModeTransitionCode(java.lang.StringBuffer code)
                                throws IllegalActionException
Generate mode transition code. It generates code for updating configuration number of the container actor. The code generated in this method is executed after each global iteration.

Specified by:
generateModeTransitionCode in interface ActorCodeGenerator
Overrides:
generateModeTransitionCode in class Director
Parameters:
code - The string buffer that the generated code is appended to.
Throws:
IllegalActionException - If getting helper fails, processing code fails, or updating configuration number fails.

generatePreinitializeCode

public java.lang.String generatePreinitializeCode()
                                           throws IllegalActionException
Generate the preinitialize code for this director. It computes and records schedules for all configurations of the container actor, also records external port rates of the container actor under all configurations.

Specified by:
generatePreinitializeCode in interface ActorCodeGenerator
Overrides:
generatePreinitializeCode in class SDFDirector
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 SDFDirector
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 SDFDirector
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.

_createOffsetVariablesIfNeeded

protected java.lang.String _createOffsetVariablesIfNeeded()
                                                   throws IllegalActionException
Create read and write offset variables if needed for any output port of the container actor and any input port of contained actors.

Overrides:
_createOffsetVariablesIfNeeded in class SDFDirector
Returns:
A string containing declared read and write offset variables.
Throws:
IllegalActionException - If thrown while creating offset variables.

_createOffsetVariablesIfNeeded

protected java.lang.String _createOffsetVariablesIfNeeded(IOPort port)
                                                   throws IllegalActionException
Check to see if variables are needed to represent read and write offsets for the given port.

Parameters:
port - The given port.
Returns:
A string containing declared read and write offset variables.
Throws:
IllegalActionException - If thrown while creating offset variables.

_updateConfigurationNumber

protected void _updateConfigurationNumber(java.lang.StringBuffer code)
                                   throws IllegalActionException
Generate code for updating configuration number of the container actor as a function of the configuration numbers of contained actors. The total number of configurations of the container is the product of numbers of configurations of contained actors.

Parameters:
code - The string buffer that the generated code is appended to.
Throws:
IllegalActionException - If thrown while getting helper or processing code.