Class SDFDirector
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.cg.kernel.generic.CodeGeneratorAdapter
-
- ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
-
- ptolemy.cg.kernel.generic.program.NamedProgramCodeGeneratorAdapter
-
- ptolemy.cg.adapter.generic.adapters.ptolemy.actor.Director
-
- ptolemy.cg.adapter.generic.adapters.ptolemy.actor.PortDirector
-
- ptolemy.cg.adapter.generic.program.procedural.adapters.ptolemy.actor.sched.StaticSchedulingDirector
-
- ptolemy.cg.adapter.generic.program.procedural.adapters.ptolemy.domains.sdf.kernel.SDFDirector
-
- ptolemy.cg.adapter.generic.program.procedural.c.adapters.ptolemy.domains.sdf.kernel.SDFDirector
-
- All Implemented Interfaces:
java.lang.Cloneable
,Changeable
,Debuggable
,DebugListener
,Derivable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
SDFDirector
public class SDFDirector extends SDFDirector
Code generator adapter associated with the SDFDirector class. This class is also associated with a code generator.- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Ye Zhou, Gang Zhou
- Pt.AcceptedRating:
- Red (eal)
- Pt.ProposedRating:
- Yellow (zgang)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.cg.kernel.generic.program.NamedProgramCodeGeneratorAdapter
NamedProgramCodeGeneratorAdapter.VariableScope
-
Nested classes/interfaces inherited from class ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
ProgramCodeGeneratorAdapter.Channel
-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
-
Fields inherited from class ptolemy.cg.adapter.generic.program.procedural.adapters.ptolemy.domains.sdf.kernel.SDFDirector
_referencedParameters
-
Fields inherited from class ptolemy.cg.adapter.generic.program.procedural.adapters.ptolemy.actor.sched.StaticSchedulingDirector
CURRENTTIME_DECLARATION
-
Fields inherited from class ptolemy.cg.adapter.generic.adapters.ptolemy.actor.PortDirector
_sanitizedDirectorName, ports
-
Fields inherited from class ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
_component, _defaultBlocks, _eol, _templateParser
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
-
Constructor Summary
Constructors Constructor Description SDFDirector(SDFDirector sdfDirector)
Construct the code generator adapter associated with the given SDFDirector.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.String
_generateVariableDeclaration(NamedProgramCodeGeneratorAdapter target)
Generate variable declarations for inputs and outputs and parameters.java.lang.String
generateConstructorCode()
Generate the constructor code for the specified director.java.lang.String
generateFunctionsDeclaration()
Generate The functions' declaration code for this director.java.lang.String
generateInitializeFunctionCode()
Generate the initialize function code for the associated SDF director.java.lang.String
generateMainLoop()
Generate a main loop for an execution under the control of this director.java.lang.String
generatePostFireFunctionCode()
Generate The postfire function code for a SDF director.java.lang.String
generatePreFireFunctionCode()
Generate The prefire function code for a SDF director Usually we have to check if all the input ports have enough tokens to fire.java.lang.String
generatePreinitializeCode()
Generate the preinitialize code for this director.java.lang.String
generatePreinitializeMethodBodyCode()
Generate the preinitialize code for this director.java.lang.String
generateSchedule()
Generate the code representing the schedule statically inferred from the Ptolemy model.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.java.lang.String
generateVariableDeclaration()
Generate constant for the period parameter, if there is one.java.lang.String
generateWrapupCode()
Generate The wrapup function code.CCodeGenerator
getCodeGenerator()
Get the code generator associated with this adapter class.-
Methods inherited from class ptolemy.cg.adapter.generic.program.procedural.adapters.ptolemy.domains.sdf.kernel.SDFDirector
_createDynamicOffsetVariables, _createInputBufferSizeAndOffsetMap, _createOffsetVariablesIfNeeded, _generateVariableInitialization, _getParameter, _updatePortBufferSize, generateFireFunctionCode, generateInitializeCode, getBufferSize
-
Methods inherited from class ptolemy.cg.adapter.generic.program.procedural.adapters.ptolemy.actor.sched.StaticSchedulingDirector
_generateUpdatePortOffsetCode, _updateConnectedPortsOffset, _updatePortOffset, allowDynamicMultiportReference, createDecoratorAttributes, generateFireCode, generatePortName, padBuffers
-
Methods inherited from class ptolemy.cg.adapter.generic.adapters.ptolemy.actor.PortDirector
_checkLocal, _checkRemote, _generateChannelOffset, _generatePortReference, _getCastType, _getChannelAndOffset, _getRefName, _getRefType, getReference, getReference, getSanitizedDirectorName
-
Methods inherited from class ptolemy.cg.adapter.generic.adapters.ptolemy.actor.Director
_ceilToPowerOfTwo, generateCodeForGet, generateCodeForSend, generateModeTransitionCode, generatePostfireCode, generateTransferInputsCode, generateTransferOutputsCode, generateVariableDeclaration, generateVariableInitialization, generateVariableInitialization, getComponent, getIncludeDirectories, getLibraries, getLibraryDirectories, getModifiedVariables, getParameter
-
Methods inherited from class ptolemy.cg.kernel.generic.program.NamedProgramCodeGeneratorAdapter
_generateFireCode, _generateTypeConvertStatement, analyzeTypeConvert, copyFilesToCodeDirectory, generatePrefireCode, generateSimpleName, generateTypeConvertFireCode, generateTypeConvertFireCode, getAddTimeString, getBufferSize, getDeclareSharedCode, getDefaultBlocks, getFireFunctionParameters, getHeaderFiles, getName, getParameterValue, getReference, getReference, getSharedCode, getSinkChannels, getSourceTimeString, getTimeSourcePortName, getTypeConvertChannels, getTypeConvertReference, getTypeConvertSinkChannels, setupAdapter, targetType
-
Methods inherited from class ptolemy.cg.kernel.generic.program.ProgramCodeGeneratorAdapter
_generateBlockByName, getAdapter, getTemplateParser, processCode, setCodeGenerator, setTemplateParser, toString
-
Methods inherited from class ptolemy.cg.kernel.generic.CodeGeneratorAdapter
generateName
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _description, _executeChangeRequests, _exportMoMLContents, _getContainedObject, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateExistence, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeChanged, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, clone, containedObjectsIterator, decorators, 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, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setName, setPersistent, setSource, sortContainedObjects, toplevel, uniqueName, validateSettables, workspace
-
-
-
-
Constructor Detail
-
SDFDirector
public SDFDirector(SDFDirector sdfDirector)
Construct the code generator adapter associated with the given SDFDirector.- Parameters:
sdfDirector
- The associated ptolemy.domains.sdf.kernel.SDFDirector
-
-
Method Detail
-
generateConstructorCode
public java.lang.String generateConstructorCode() throws IllegalActionException
Generate the constructor code for the specified director. In this class we initialize the director with its internal parameters and fields as well as with the depths of the actors- Overrides:
generateConstructorCode
in classDirector
- Returns:
- The generated constructor code
- Throws:
IllegalActionException
- Not thrown in this base class.
-
generateFunctionsDeclaration
public java.lang.String generateFunctionsDeclaration() throws IllegalActionException
Generate The functions' declaration code for this director.- Returns:
- The functions' declaration function code.
- Throws:
IllegalActionException
- If thrown while generating code.
-
generateInitializeFunctionCode
public java.lang.String generateInitializeFunctionCode() throws IllegalActionException
Generate the initialize function code for the associated SDF director.- Returns:
- The generated initialize code.
- Throws:
IllegalActionException
- If the adapter associated with an actor throws it while generating initialize code for the actor.
-
generateMainLoop
public java.lang.String generateMainLoop() throws IllegalActionException
Generate a main loop for an execution under the control of this director. If the associated director has a parameter named iterations with a value greater than zero, then wrap code generated by generateFireCode() in a loop that executes the specified number of iterations. Otherwise, wrap it in a loop that executes forever. In the loop, first get the code returned by generateFireCode(), and follow that with the code produced by the container help for generateModeTransitionCode(). That code will make state transitions in modal models at the conclusion of each iteration. Next, this code calls postfire(), and that returns false, breaks out of the main loop. Finally, if the director has a parameter named period, then increment the variable _currentTime after each pass through the loop.- Overrides:
generateMainLoop
in classStaticSchedulingDirector
- Returns:
- Code for the main loop of an execution.
- Throws:
IllegalActionException
- If something goes wrong.
-
generatePostFireFunctionCode
public java.lang.String generatePostFireFunctionCode() throws IllegalActionException
Generate The postfire function code for a SDF director.- Returns:
- The postfire function code.
- Throws:
IllegalActionException
- If thrown while generating fire code.
-
generatePreFireFunctionCode
public java.lang.String generatePreFireFunctionCode() throws IllegalActionException
Generate The prefire function code for a SDF director Usually we have to check if all the input ports have enough tokens to fire. In here we also update the time of the director with its container time. If it is top level director, there is no need for that. But in the SDFReceiver we assume that receivers have always enough tokens, therefore the prefire methods always returns true.- Returns:
- The prefire function code.
- Throws:
IllegalActionException
- If thrown while generating fire code.
-
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.- Overrides:
generatePreinitializeCode
in classSDFDirector
- Returns:
- The generated preinitialize code.
- Throws:
IllegalActionException
- If getting the adapter fails, or if generating the preinitialize code for a adapter fails, or if there is a problem getting the buffer size of a port.
-
generatePreinitializeMethodBodyCode
public java.lang.String generatePreinitializeMethodBodyCode() 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.- Overrides:
generatePreinitializeMethodBodyCode
in classDirector
- Returns:
- The generated preinitialize code.
- Throws:
IllegalActionException
- If getting the adapter fails, or if generating the preinitialize code for a adapter fails, or if there is a problem getting the buffer size of a port.
-
generateSchedule
public java.lang.String generateSchedule() throws IllegalActionException
Generate the code representing the schedule statically inferred from the Ptolemy model.- Returns:
- the code representing the schedule.
- Throws:
IllegalActionException
- if something happens while writing the code
-
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 classDirector
- 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 classDirector
- 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.
-
generateVariableDeclaration
public java.lang.String generateVariableDeclaration() throws IllegalActionException
Generate constant for the period parameter, if there is one.- Overrides:
generateVariableDeclaration
in classStaticSchedulingDirector
- Returns:
- code The generated code.
- Throws:
IllegalActionException
- If the adapter class for the model director cannot be found.
-
generateWrapupCode
public java.lang.String generateWrapupCode() throws IllegalActionException
Generate The wrapup function code.- Overrides:
generateWrapupCode
in classDirector
- Returns:
- The wrapup function code.
- Throws:
IllegalActionException
- If thrown while generating fire code.
-
getCodeGenerator
public CCodeGenerator getCodeGenerator()
Get the code generator associated with this adapter class.- Overrides:
getCodeGenerator
in classProgramCodeGeneratorAdapter
- Returns:
- The code generator associated with this adapter class.
- See Also:
ProgramCodeGeneratorAdapter.setCodeGenerator(GenericCodeGenerator)
-
_generateVariableDeclaration
protected java.lang.String _generateVariableDeclaration(NamedProgramCodeGeneratorAdapter target) throws IllegalActionException
Generate variable declarations for inputs and outputs and parameters. Append the declarations to the given string buffer.- Overrides:
_generateVariableDeclaration
in classDirector
- Parameters:
target
- The ProgramCodeGeneratorAdapter for which code needs to be generated.- Returns:
- code The generated code.
- Throws:
IllegalActionException
- If the adapter class for the model director cannot be found.
-
-