ptolemy.codegen.c.actor
Class TypedCompositeActor

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.codegen.kernel.CodeGeneratorHelper
          extended by ptolemy.codegen.c.kernel.CCodeGeneratorHelper
              extended by ptolemy.codegen.c.actor.TypedCompositeActor
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ActorCodeGenerator, ComponentCodeGenerator, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
Direct Known Subclasses:
CompiledCompositeActor, ModalModel, ModalModel, MultiCompositeActor, MultiInstanceComposite, Refinement, Refinement, Refinement

public class TypedCompositeActor
extends CCodeGeneratorHelper

Code generator helper for typed composite actor.

Since:
Ptolemy II 6.0
Version:
$Id: TypedCompositeActor.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Gang Zhou, Contributors: Teale Fristoe
See Also:
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[] _firingsPerGlobalIteration
          An int array of firings per global iteration.
private  int[][] _rates
          A two-dimensional int array of rates of this actor.
 
Fields inherited from class ptolemy.codegen.kernel.CodeGeneratorHelper
_codeGenerator, _codeStream, _eol, _INDENT1, _INDENT2, _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
TypedCompositeActor(TypedCompositeActor component)
          Construct the code generator helper associated with the given TypedCompositeActor.
 
Method Summary
protected  void _createBufferSizeAndOffsetMap()
          Create and initialize the buffer size and offset maps for this composite actor.
protected  void _createOutputBufferSizeAndOffsetMap()
          Create the output buffer and offset map.
protected  java.lang.String _generateFireCode()
          Generate the fire code of the associated composite actor.
 void analyzeTypeConvert()
          For each actor in this typed composite actor, determine which ports need type conversion.
 java.lang.String createOffsetVariablesIfNeeded()
          Create read and write offset variables if needed for the associated composite actor.
 java.lang.String generateFireFunctionCode()
          Generate The fire function code.
 java.lang.String generateInitializeCode()
          Generate the initialize code of the associated composite actor.
 void generateModeTransitionCode(java.lang.StringBuffer code)
          Generate mode transition code.
 java.lang.String generatePostfireCode()
          Generate the postfire code of the associated composite actor.
 java.lang.String generatePreinitializeCode()
          Generate the preinitialize code of the associated composite actor.
 java.lang.String generateVariableDeclaration()
          Generate variable declarations for input ports, output ports and parameters if necessary, as well as for the director and the contained actors.
 java.lang.String generateVariableInitialization()
          Generate variable initialization for the referenced parameters.
 java.lang.String generateWrapupCode()
          Generate the wrapup code of the associated composite actor.
 int[] getFiringsPerGlobalIteration()
          Return an int array of firings per global iteration.
 java.util.Set getHeaderFiles()
          Get the header files needed by the code generated from this helper class.
 java.util.Set getIncludeDirectories()
          Return the include directories specified in the "includeDirectories" blocks in the templates of the actors included in this CompositeActor.
 java.util.Set getLibraries()
          Return the libraries specified in the "libraries" blocks in the templates of the actors included in this CompositeActor.
 java.util.Set getModifiedVariables()
          Return a set of parameters that will be modified during the execution of the model.
 int[][] getRates()
          Return a two-dimensional int array of rates of this actor.
 java.util.Set getSharedCode()
          Generate a set of shared code fragments of the associated composite actor.
 java.lang.String resetOutputPortsOffset()
          Reset the offsets of all inside buffers of all output ports of the associated composite actor to the default value of 0.
 void setFiringsPerGlobalIteration(int[] firingsPerGlobalIteration)
          Set the int array of firings per global iteration.
 void setRates(int[][] rates)
          Set the two-dimensional int array of rates of this actor.
 
Methods inherited from class ptolemy.codegen.c.kernel.CCodeGeneratorHelper
_generateInputVariableDeclaration, _generateOutputVariableDeclaration, _generateReferencedParameterDeclaration, _generateTypeConvertStatement, _generateTypeConvertVariableDeclaration, _getFireFunctionArguments, _replaceMacro, getCodeGenerator, getJVMHeaderFiles, getParseTreeCodeGenerator
 
Methods inherited from class ptolemy.codegen.kernel.CodeGeneratorHelper
_createInputBufferSizeAndOffsetMap, _findClosedParen, _generateBlockCode, _generateBlockCode, _generateTypeConvertMethod, _generateTypeConvertStatements, _getCastType, _getChannelAndOffset, _getHelper, _getHelper, _getIndentPrefix, _getReference, _getReferenceChannels, _getTypeConvertChannels, _getTypeConvertReference, _indexOf, addFunctionUsed, addNewTypeUsed, checkLocal, checkRemote, codeGenType, copyFilesToCodeDirectory, generateChannelOffset, generateFireCode, generateFireFunctionCode2, generateName, generateOffset, generatePortReference, generatePrefireCode, generateSimpleName, generateTypeConvertFireCode, generateTypeConvertFireCode, generateVariableName, getBufferSize, getBufferSize, getComponent, getDefaultBlocks, getDirector, getDirectorHelper, getFunctionInvocation, getLibraryDirectories, getNewInvocation, getObject, getParameterValue, getPort, getReadOffset, getReference, getReference, getReference, getReference, getSinkChannels, getSize, getSourceChannel, getWCET, 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

_firingsPerGlobalIteration

private int[] _firingsPerGlobalIteration
An int array of firings per global iteration.


_rates

private int[][] _rates
A two-dimensional int array of rates of this actor.

Constructor Detail

TypedCompositeActor

public TypedCompositeActor(TypedCompositeActor component)
Construct the code generator helper associated with the given TypedCompositeActor.

Parameters:
component - The associated component.
Method Detail

analyzeTypeConvert

public void analyzeTypeConvert()
                        throws IllegalActionException
For each actor in this typed composite actor, determine which ports need type conversion.

Overrides:
analyzeTypeConvert in class CodeGeneratorHelper
Throws:
IllegalActionException - If any of the helpers of the inside actors is unavailable.
See Also:
CodeGeneratorHelper.analyzeTypeConvert()

createOffsetVariablesIfNeeded

public java.lang.String createOffsetVariablesIfNeeded()
                                               throws IllegalActionException
Create read and write offset variables if needed for the associated composite actor. It delegates to the director helper of the local director.

Specified by:
createOffsetVariablesIfNeeded in interface ActorCodeGenerator
Overrides:
createOffsetVariablesIfNeeded in class CodeGeneratorHelper
Returns:
A string containing declared read and write offset variables.
Throws:
IllegalActionException - If the helper class cannot be found or the director helper throws it.

_generateFireCode

protected java.lang.String _generateFireCode()
                                      throws IllegalActionException
Generate the fire code of the associated composite actor. This method first generates code for transferring any data from the input ports of this composite to the ports connected on the inside by calling the generateTransferInputsCode() method of the local director helper. It then invokes the generateFireCode() method of its local director helper. After the generateFireCode() method of the director helper returns, generate code for transferring any output data created by calling the local director helper's generateTransferOutputsCode() method.

Overrides:
_generateFireCode in class CodeGeneratorHelper
Returns:
The generated fire code.
Throws:
IllegalActionException - If the helper associated with an actor throws it while generating fire code for the actor, or the director helper throws it while generating code for transferring data.

generateFireFunctionCode

public java.lang.String generateFireFunctionCode()
                                          throws IllegalActionException
Generate The fire function code. This method is called when the firing code of each actor is not inlined. Each actor's firing code is in a function with the same name as that of the actor.

Specified by:
generateFireFunctionCode in interface ActorCodeGenerator
Overrides:
generateFireFunctionCode in class CodeGeneratorHelper
Returns:
The fire function code.
Throws:
IllegalActionException - If thrown while generating fire code.

generateInitializeCode

public java.lang.String generateInitializeCode()
                                        throws IllegalActionException
Generate the initialize code of the associated composite actor. It first resets the read and write offset of all input ports of all contained actors and all output ports. It then gets the result of generateInitializeCode() method of the local director helper.

Specified by:
generateInitializeCode in interface ComponentCodeGenerator
Overrides:
generateInitializeCode in class CodeGeneratorHelper
Returns:
The initialize code of the associated composite actor.
Throws:
IllegalActionException - If the helper associated with an actor throws it while generating initialize code for the actor or while resetting read and write offset.

generateModeTransitionCode

public void generateModeTransitionCode(java.lang.StringBuffer code)
                                throws IllegalActionException
Generate mode transition code. It delegates to the director helper of the local director. The mode transition code generated in this method is executed after each global iteration, e.g., in HDF model.

Specified by:
generateModeTransitionCode in interface ActorCodeGenerator
Overrides:
generateModeTransitionCode in class CodeGeneratorHelper
Parameters:
code - The string buffer that the generated code is appended to.
Throws:
IllegalActionException - If the director helper throws it while generating mode transition code.

generatePostfireCode

public java.lang.String generatePostfireCode()
                                      throws IllegalActionException
Generate the postfire code of the associated composite actor. It returns the result of generatePostfireCode() method of the local director helper.

Specified by:
generatePostfireCode in interface ActorCodeGenerator
Overrides:
generatePostfireCode in class CodeGeneratorHelper
Returns:
The postfire code of the associated composite actor.
Throws:
IllegalActionException - If the helper associated with an actor throws it while generating postfire code for the actor.

generatePreinitializeCode

public java.lang.String generatePreinitializeCode()
                                           throws IllegalActionException
Generate the preinitialize code of the associated composite actor. It first creates buffer size and offset map for its input ports and output ports. It then gets the result of generatePreinitializeCode() method of the local director helper.

Specified by:
generatePreinitializeCode in interface ActorCodeGenerator
Overrides:
generatePreinitializeCode in class CodeGeneratorHelper
Returns:
The preinitialize code of the associated composite actor.
Throws:
IllegalActionException - If the helper associated with an actor throws it while generating preinitialize code for the actor or while creating buffer size and offset map.

generateVariableDeclaration

public java.lang.String generateVariableDeclaration()
                                             throws IllegalActionException
Generate variable declarations for input ports, output ports and parameters if necessary, as well as for the director and the contained actors.

Specified by:
generateVariableDeclaration in interface ActorCodeGenerator
Overrides:
generateVariableDeclaration in class CCodeGeneratorHelper
Returns:
code The generated code.
Throws:
IllegalActionException - If the helper associated with an actor throws it while generating variable declarations for the actor.

generateVariableInitialization

public java.lang.String generateVariableInitialization()
                                                throws IllegalActionException
Generate variable initialization for the referenced parameters.

Specified by:
generateVariableInitialization in interface ActorCodeGenerator
Overrides:
generateVariableInitialization in class CodeGeneratorHelper
Returns:
code The generated code.
Throws:
IllegalActionException - If the helper associated with an actor throws it while generating variable declarations for the actor.

generateWrapupCode

public java.lang.String generateWrapupCode()
                                    throws IllegalActionException
Generate the wrapup code of the associated composite actor. It returns the result of generateWrapupCode() method of the local director helper.

Specified by:
generateWrapupCode in interface ComponentCodeGenerator
Overrides:
generateWrapupCode in class CodeGeneratorHelper
Returns:
The wrapup code of the associated composite actor.
Throws:
IllegalActionException - If the helper associated with an actor throws it while generating wrapup code for the actor.

getFiringsPerGlobalIteration

public int[] getFiringsPerGlobalIteration()
Return an int array of firings per global iteration. For each internal configuration of this composite actor, the array contains a corresponding element representing the number of firings of this composite actor per global iteration.

Returns:
An int array of firings per global iteration.
See Also:
setFiringsPerGlobalIteration(int[])

getHeaderFiles

public java.util.Set getHeaderFiles()
                             throws IllegalActionException
Get the header files needed by the code generated from this helper class. It returns the result of calling getHeaderFiles() method of the helpers of all contained actors.

Specified by:
getHeaderFiles in interface ActorCodeGenerator
Overrides:
getHeaderFiles in class CCodeGeneratorHelper
Returns:
A set of strings that are header files.
Throws:
IllegalActionException - If the helper associated with an actor throws it while generating header files for the actor.

getIncludeDirectories

public java.util.Set getIncludeDirectories()
                                    throws IllegalActionException
Return the include directories specified in the "includeDirectories" blocks in the templates of the actors included in this CompositeActor.

Specified by:
getIncludeDirectories in interface ActorCodeGenerator
Overrides:
getIncludeDirectories in class CodeGeneratorHelper
Returns:
A Set of the include directories.
Throws:
IllegalActionException - If thrown when gathering include directories.

getLibraries

public java.util.Set getLibraries()
                           throws IllegalActionException
Return the libraries specified in the "libraries" blocks in the templates of the actors included in this CompositeActor.

Specified by:
getLibraries in interface ActorCodeGenerator
Overrides:
getLibraries in class CodeGeneratorHelper
Returns:
A Set of libraries.
Throws:
IllegalActionException - If thrown when gathering libraries.

getModifiedVariables

public java.util.Set getModifiedVariables()
                                   throws IllegalActionException
Return a set of parameters that will be modified during the execution of the model. These parameters are those returned by getModifiedVariables() method of directors or actors that implement ExplicitChangeContext interface.

Specified by:
getModifiedVariables in interface ActorCodeGenerator
Overrides:
getModifiedVariables in class CodeGeneratorHelper
Returns:
a set of parameters that will be modified.
Throws:
IllegalActionException - If the helper associated with an actor or director throws it while getting modified variables.

getRates

public int[][] getRates()
Return a two-dimensional int array of rates of this actor. For each internal configuration of this composite actor, the array contains a corresponding one-dimensional int array representing the rates of all ports of this composite actor. It returns null when there is only one internal configuration, e.g., when the internal model is an SDF model.

Overrides:
getRates in class CodeGeneratorHelper
Returns:
A two-dimensional int array of rates of this actor or null.
See Also:
setRates(int[][])

getSharedCode

public java.util.Set getSharedCode()
                            throws IllegalActionException
Generate a set of shared code fragments of the associated composite actor. It returns the result of calling getSharedCode() method of the helpers of all contained actors.

Specified by:
getSharedCode in interface ActorCodeGenerator
Overrides:
getSharedCode in class CodeGeneratorHelper
Returns:
a set of shared code fragments.
Throws:
IllegalActionException - If the helper associated with an actor throws it while generating shared code for the actor.

resetOutputPortsOffset

public java.lang.String resetOutputPortsOffset()
                                        throws IllegalActionException
Reset the offsets of all inside buffers of all output ports of the associated composite actor to the default value of 0.

Returns:
The reset code of the associated composite actor.
Throws:
IllegalActionException - If thrown while getting or setting the offset.

setFiringsPerGlobalIteration

public void setFiringsPerGlobalIteration(int[] firingsPerGlobalIteration)
Set the int array of firings per global iteration. For each internal configuration of this composite actor, the array contains a corresponding element representing the number of firings of this composite actor per global iteration.

Parameters:
firingsPerGlobalIteration - An int array of firings per global iteration
See Also:
getFiringsPerGlobalIteration()

setRates

public void setRates(int[][] rates)
Set the two-dimensional int array of rates of this actor. For each internal configuration of this composite actor, the array contains a corresponding one-dimensional int array representing the rates of all ports of this composite actor.

Parameters:
rates - A two-dimensional int array of rates of this actor.
See Also:
getRates()

_createBufferSizeAndOffsetMap

protected void _createBufferSizeAndOffsetMap()
                                      throws IllegalActionException
Create and initialize the buffer size and offset maps for this composite actor. A key of the map is an IOPort of the actor. The corresponding value is an array of buffer sizes or an array of offsets. The i-th element in the array corresponds to the i-th channel of that IOPort.

Overrides:
_createBufferSizeAndOffsetMap in class CodeGeneratorHelper
Throws:
IllegalActionException - If thrown while getting helper or buffer size.

_createOutputBufferSizeAndOffsetMap

protected void _createOutputBufferSizeAndOffsetMap()
                                            throws IllegalActionException
Create the output buffer and offset map.

Throws:
IllegalActionException - If thrown while getting the director helper or while getting the buffer size or read offset or write offset.