Class StaticSchedulingDirector
- 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
-
- All Implemented Interfaces:
java.lang.Cloneable
,Changeable
,Debuggable
,DebugListener
,Derivable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
SDFDirector
public class StaticSchedulingDirector extends PortDirector
Code generator adapter associated with the StaticSchedulingDirector class. This class is also associated with a code generator.- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Gang Zhou, Contributor: Bert Rodiers, Christopher Brooks
- 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 Modifier and Type Field Description static java.lang.String
CURRENTTIME_DECLARATION
The declaration for the _currentTime variable.-
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 StaticSchedulingDirector(StaticSchedulingDirector staticSchedulingDirector)
Construct the code generator adapter associated with the given StaticSchedulingDirector.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_generateUpdatePortOffsetCode(java.lang.StringBuffer code, Actor actor)
Generate the code that updates the input/output port offset.protected java.lang.String
_getParameter(NamedProgramCodeGeneratorAdapter target, Attribute attribute, java.lang.String[] channelAndOffset)
Return an unique label for the given attribute referenced by the given adapter.protected void
_updateConnectedPortsOffset(IOPort port, java.lang.StringBuffer code, int rate)
Update the offsets of the buffers associated with the ports connected with the given port in its downstream.protected void
_updatePortOffset(IOPort port, java.lang.StringBuffer code, int rate)
Update the read offsets of the buffer associated with the given port.java.lang.Boolean
allowDynamicMultiportReference()
Return whether the channels in multiports can be dynamically referenced using the $ref macro.DecoratorAttributes
createDecoratorAttributes(NamedObj target, GenericCodeGenerator genericCodeGenerator)
Create and return the decorated attributes for the corresponding Ptolemy component.java.lang.String
generateFireCode()
Generate the code for the firing of actors according to the SDF schedule.java.lang.String
generateInitializeCode()
Generate the initialize code for this director.java.lang.String
generateMainLoop()
Generate a main loop for an execution under the control of this director.java.lang.String
generatePortName(TypedIOPort port)
Generate sanitized name for the given named object.java.lang.String
generatePreinitializeCode()
Generate the preinitialize code for this director.java.lang.String
generateVariableDeclaration()
Generate a variable declaration for the period parameter, if there is one.java.lang.Boolean
padBuffers()
Return whether we need to pad buffers or not.-
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, _generateVariableDeclaration, _generateVariableInitialization, generateCodeForGet, generateCodeForSend, generateConstructorCode, generateFireFunctionCode, generateModeTransitionCode, generatePostfireCode, generatePreinitializeMethodBodyCode, generateTransferInputsCode, generateTransferInputsCode, generateTransferOutputsCode, generateTransferOutputsCode, generateVariableDeclaration, generateVariableInitialization, generateVariableInitialization, generateWrapupCode, 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, 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, getCodeGenerator, 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
-
StaticSchedulingDirector
public StaticSchedulingDirector(StaticSchedulingDirector staticSchedulingDirector)
Construct the code generator adapter associated with the given StaticSchedulingDirector.- Parameters:
staticSchedulingDirector
- The associated ptolemy.actor.sched.StaticSchedulingDirector
-
-
Method Detail
-
allowDynamicMultiportReference
public final java.lang.Boolean allowDynamicMultiportReference() throws IllegalActionException
Return whether the channels in multiports can be dynamically referenced using the $ref macro.- Specified by:
allowDynamicMultiportReference
in classPortDirector
- Returns:
- True when the channels in multiports can be dynamically referenced using the $ref macro.
- Throws:
IllegalActionException
- If the expression cannot be parsed or cannot be evaluated, or if the result of evaluation violates type constraints, or if the result of evaluation is null and there are variables that depend on this one.
-
createDecoratorAttributes
public DecoratorAttributes createDecoratorAttributes(NamedObj target, GenericCodeGenerator genericCodeGenerator)
Create and return the decorated attributes for the corresponding Ptolemy component.- Overrides:
createDecoratorAttributes
in classCodeGeneratorAdapter
- Parameters:
target
- The corresponding Ptolemy Component.genericCodeGenerator
- The code generator that is the decorator for the corresponding Ptolemy Component.- Returns:
- The decorated attributes.
-
generateFireCode
public java.lang.String generateFireCode() throws IllegalActionException
Generate the code for the firing of actors according to the SDF schedule.- Overrides:
generateFireCode
in classDirector
- Returns:
- The generated fire code.
- Throws:
IllegalActionException
- If the SDF director does not have an attribute called "iterations" or a valid schedule, or the actor to be fired cannot find its associated adapter.
-
generateInitializeCode
public java.lang.String generateInitializeCode() throws IllegalActionException
Generate the initialize code for this director. The initialize code for the director is generated by appending the initialize code for each actor.- Overrides:
generateInitializeCode
in classDirector
- 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 classNamedProgramCodeGeneratorAdapter
- Returns:
- Code for the main loop of an execution.
- Throws:
IllegalActionException
- If something goes wrong.
-
generatePortName
public java.lang.String generatePortName(TypedIOPort port) throws IllegalActionException
Generate sanitized name for the given named object. Remove all underscores to avoid conflicts with systems functions.- Specified by:
generatePortName
in classPortDirector
- Parameters:
port
- The port for which the name is generated.- Returns:
- The sanitized name.
- Throws:
IllegalActionException
- If the variablesAsArrays parameter cannot be read or if the buffer size of the port cannot be read.
-
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 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.
-
generateVariableDeclaration
public java.lang.String generateVariableDeclaration() throws IllegalActionException
Generate a variable declaration for the period parameter, if there is one.- Overrides:
generateVariableDeclaration
in classDirector
- Returns:
- code The generated code.
- Throws:
IllegalActionException
- If the adapter class for the model director cannot be found.
-
padBuffers
public final java.lang.Boolean padBuffers() throws IllegalActionException
Return whether we need to pad buffers or not.- Specified by:
padBuffers
in classPortDirector
- Returns:
- True when we need to pad buffers.
- Throws:
IllegalActionException
- If the expression cannot be parsed or cannot be evaluated, or if the result of evaluation violates type constraints, or if the result of evaluation is null and there are variables that depend on this one.
-
_generateUpdatePortOffsetCode
protected void _generateUpdatePortOffsetCode(java.lang.StringBuffer code, Actor actor) throws IllegalActionException
Generate the code that updates the input/output port offset.- Parameters:
code
- The given code buffer.actor
- The given actor.- Throws:
IllegalActionException
- Thrown if _updatePortOffset(IOPort, StringBuffer, int) or getRate(IOPort) throw it.
-
_getParameter
protected java.lang.String _getParameter(NamedProgramCodeGeneratorAdapter target, Attribute attribute, java.lang.String[] channelAndOffset) throws IllegalActionException
Return an unique label for the given attribute referenced by the given adapter. Subclass should override this method to generate the desire label according to the given parameters.- Overrides:
_getParameter
in classDirector
- Parameters:
target
- The ProgramCodeGeneratorAdapter for which code needs to be generated.attribute
- The given attribute.channelAndOffset
- The given channel and offset.- Returns:
- an unique label for the given attribute.
- Throws:
IllegalActionException
- If the adapter throws it while generating the label.
-
_updateConnectedPortsOffset
protected final void _updateConnectedPortsOffset(IOPort port, java.lang.StringBuffer code, int rate) throws IllegalActionException
Update the offsets of the buffers associated with the ports connected with the given port in its downstream.- Parameters:
port
- The port whose directly connected downstream actors update their write offsets.code
- The string buffer that the generated code is appended to.rate
- The rate, which must be greater than or equal to 0.- Throws:
IllegalActionException
- If thrown while reading or writing offsets, or getting the buffer size, or if the rate is less than 0.
-
_updatePortOffset
protected void _updatePortOffset(IOPort port, java.lang.StringBuffer code, int rate) throws IllegalActionException
Update the read offsets of the buffer associated with the given port.- Parameters:
port
- The port whose read offset is to be updated.code
- The string buffer that the generated code is appended to.rate
- The rate, which must be greater than or equal to 0.- Throws:
IllegalActionException
- If thrown while reading or writing offsets, or getting the buffer size, or if the rate is less than 0.
-
-