Class Director
- 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
-
- All Implemented Interfaces:
java.lang.Cloneable
,Changeable
,Debuggable
,DebugListener
,Derivable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
CaseDirector
,FSMDirector
,PortDirector
,PtidesPreemptiveEDFDirector
,PtidesTopLevelDirector
public class Director extends NamedProgramCodeGeneratorAdapter
Code generator adapter associated with the ptolemy.actor.Director class. This class is also associated with a code generator.- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Ye Zhou, Gang Zhou
- See Also:
GenericCodeGenerator
- Pt.AcceptedRating:
- Yellow (zhouye)
- Pt.ProposedRating:
- Yellow (zhouye)
-
-
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 protected Director
_director
The associated director.-
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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
_ceilToPowerOfTwo(int value)
Return the minimum number of power of two that is greater than or equal to the given integer.protected java.lang.String
_generateVariableDeclaration(NamedProgramCodeGeneratorAdapter target)
Generate variable declarations for inputs and outputs and parameters.protected java.lang.String
_generateVariableInitialization(NamedProgramCodeGeneratorAdapter target)
Generate variable initialization for the referenced parameters.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.java.lang.String
generateCodeForGet(IOPort port, int channel)
Generate the get code for Port port.java.lang.String
generateCodeForSend(IOPort port, int channel, java.lang.String dataToken)
Generate the send code for Port port.java.lang.String
generateConstructorCode()
Generate the constructor code for the specified director.java.lang.String
generateFireCode()
Generate the code for the firing of actors.java.lang.String
generateFireFunctionCode()
Generate The fire function code.java.lang.String
generateInitializeCode()
Generate the initialize code for this director.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 for this director.java.lang.String
generatePreinitializeMethodBodyCode()
Generate the preinitialization method body.void
generateTransferInputsCode(IOPort inputPort, java.lang.StringBuffer code)
Generate code for transferring enough tokens to complete an internal iteration.void
generateTransferInputsCode(IOPort inputPort, java.lang.StringBuffer code, boolean executive)
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.void
generateTransferOutputsCode(IOPort outputPort, java.lang.StringBuffer code, boolean executive)
Generate code for transferring enough tokens to fulfill the output production rate.java.lang.String
generateVariableDeclaration()
Generate variable declarations for inputs and outputs and parameters.java.lang.String
generateVariableDeclaration(NamedProgramCodeGeneratorAdapter adapter)
Generate variable declarations for inputs and outputs and parameters.java.lang.String
generateVariableInitialization()
Generate variable initialization for the referenced parameters.java.lang.String
generateVariableInitialization(NamedProgramCodeGeneratorAdapter adapter)
Generate variable initialization for the referenced parameters.java.lang.String
generateWrapupCode()
Generate the wrapup code of the director associated with this adapter class.NamedObj
getComponent()
Return the director associated with this class.java.util.Set<java.lang.String>
getIncludeDirectories()
Return an empty HashSet.java.util.Set<java.lang.String>
getLibraries()
Return an empty HashSet.java.util.Set<java.lang.String>
getLibraryDirectories()
Return an empty HashSet.java.util.Set<Parameter>
getModifiedVariables()
Return a set of parameters that will be modified during the execution of the model.java.lang.String
getParameter(NamedProgramCodeGeneratorAdapter target, Attribute attribute, java.lang.String[] channelAndOffset)
Gets the parameter.java.lang.String
getReference(java.lang.String name, boolean isWrite, NamedProgramCodeGeneratorAdapter target)
Return the reference to the specified parameter or port of the associated actor.-
Methods inherited from class ptolemy.cg.kernel.generic.program.NamedProgramCodeGeneratorAdapter
_generateFireCode, _generateTypeConvertStatement, analyzeTypeConvert, copyFilesToCodeDirectory, generateMainLoop, 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
createDecoratorAttributes, 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
-
-
-
-
Field Detail
-
_director
protected Director _director
The associated director.
-
-
Constructor Detail
-
Director
public Director(Director director)
Construct the code generator adapter associated with the given director. Note before calling the generate*() methods, you must also call setCodeGenerator(GenericCodeGenerator).- Parameters:
director
- The associated director.
-
-
Method Detail
-
generateCodeForSend
public java.lang.String generateCodeForSend(IOPort port, int channel, java.lang.String dataToken)
Generate the send code for Port port.- Parameters:
port
- The port for which to generate send code.channel
- The channel for which the send code is generated.dataToken
- The token to be sent- Returns:
- The code that sends the dataToken on the channel.
-
generateCodeForGet
public java.lang.String generateCodeForGet(IOPort port, int channel)
Generate the get code for Port port.- Parameters:
port
- The port for which to generate get code.channel
- The channel for which the get code is generated.- Returns:
- The code that gets data from the channel.
-
generateFireCode
public java.lang.String generateFireCode() throws IllegalActionException
Generate the code for the firing of actors. In this base class, it is attempted to fire all the actors once. In subclasses such as the adapters for SDF and Giotto directors, the firings of actors observe the associated schedule. In addition, some special handling is needed, e.g., the iteration limit in SDF and time advancement in Giotto.- Overrides:
generateFireCode
in classNamedProgramCodeGeneratorAdapter
- Returns:
- The generated code.
- Throws:
IllegalActionException
- If the adapter associated with an actor throws it while generating fire code for the actor.
-
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.- Overrides:
generateFireFunctionCode
in classNamedProgramCodeGeneratorAdapter
- Returns:
- The fire function code.
- Throws:
IllegalActionException
- If thrown while generating fire code.
-
generateConstructorCode
public java.lang.String generateConstructorCode() throws IllegalActionException
Generate the constructor code for the specified director. This is only used in the C Code generation.- Returns:
- If the container is an instance of the PtidesPlatform, then return constructor code. Otherwise return the empty string.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
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 classNamedProgramCodeGeneratorAdapter
- Returns:
- The generated initialize code.
- Throws:
IllegalActionException
- If illegal macro names are found.
-
generatePostfireCode
public java.lang.String generatePostfireCode() throws IllegalActionException
Generate the postfire code of the associated composite actor.- Overrides:
generatePostfireCode
in classNamedProgramCodeGeneratorAdapter
- Returns:
- The postfire code of the associated composite actor.
- Throws:
IllegalActionException
- If the adapter associated with an actor throws it while generating postfire code for the actor or while creating buffer size and offset map.
-
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 classNamedProgramCodeGeneratorAdapter
- 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 preinitialization method body.Typically, the preinitialize code consists of variable declarations. However, AutoAdapter generates method calls that instantiate wrapper TypedCompositeActors, so we need to invoke those method calls.
- Overrides:
generatePreinitializeMethodBodyCode
in classNamedProgramCodeGeneratorAdapter
- Returns:
- a string for the preinitialization method body. In this base class, return the empty string.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
generateModeTransitionCode
public void generateModeTransitionCode(java.lang.StringBuffer code) throws IllegalActionException
Generate mode transition code. It delegates to the adapters of actors under the control of this director. The mode transition code generated in this method is executed after each global iteration, e.g., in HDF model.- Overrides:
generateModeTransitionCode
in classNamedProgramCodeGeneratorAdapter
- Parameters:
code
- The string buffer that the generated code is appended to.- Throws:
IllegalActionException
- If an actor adapter throws it while generating mode transition code.
-
generateTransferInputsCode
public void generateTransferInputsCode(IOPort inputPort, java.lang.StringBuffer code) throws IllegalActionException
Generate code for transferring enough tokens to complete an internal iteration. The reference is looked for in the director not in the executive director (the director of the container).- 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.
-
generateTransferInputsCode
public void generateTransferInputsCode(IOPort inputPort, java.lang.StringBuffer code, boolean executive) throws IllegalActionException
Generate code for transferring enough tokens to complete an internal iteration.- Parameters:
inputPort
- The port to transfer tokens.code
- The string buffer that the generated code is appended to.executive
- If true, then look for the reference in the executive director (the director of the container). The CaseDirector calls this with executive == true, most (all?) other Directors call this with executive == false.- 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. The reference is looked for in the director not in the executive director (the director of the container).- 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.
-
generateTransferOutputsCode
public void generateTransferOutputsCode(IOPort outputPort, java.lang.StringBuffer code, boolean executive) throws IllegalActionException
Generate code for transferring enough tokens to fulfill the output production rate.- Parameters:
outputPort
- The port to transfer tokens.code
- The string buffer that the generated code is appended to.executive
- If true, then look for the reference in the executive director (the director of the container). The CaseDirector calls this with executive == true, most (all?) other Directors call this with executive == false.- Throws:
IllegalActionException
- If thrown while transferring tokens.
-
generateVariableDeclaration
public java.lang.String generateVariableDeclaration() throws IllegalActionException
Generate variable declarations for inputs and outputs and parameters. Append the declarations to the given string buffer.- Overrides:
generateVariableDeclaration
in classNamedProgramCodeGeneratorAdapter
- Returns:
- code The generated code.
- Throws:
IllegalActionException
- If the adapter class for the model director cannot be found.
-
generateVariableDeclaration
public java.lang.String generateVariableDeclaration(NamedProgramCodeGeneratorAdapter adapter) throws IllegalActionException
Generate variable declarations for inputs and outputs and parameters. Append the declarations to the given string buffer. This method returns the declarations for the param actor only.- Parameters:
adapter
- The adapter for which to generate variable declarations.- Returns:
- code The generated code.
- Throws:
IllegalActionException
- If the adapter class for the model director cannot be found.
-
generateVariableInitialization
public java.lang.String generateVariableInitialization() throws IllegalActionException
Generate variable initialization for the referenced parameters.- Overrides:
generateVariableInitialization
in classNamedProgramCodeGeneratorAdapter
- Returns:
- code The generated code.
- Throws:
IllegalActionException
- If the adapter class for the model director cannot be found.
-
generateVariableInitialization
public java.lang.String generateVariableInitialization(NamedProgramCodeGeneratorAdapter adapter) throws IllegalActionException
Generate variable initialization for the referenced parameters. for the adapter given in argument- Parameters:
adapter
- The adapter for which to generate variable initialization.- 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 code of the director associated with this adapter class. For this base class, this method just generate the wrapup code for each actor.- Overrides:
generateWrapupCode
in classNamedProgramCodeGeneratorAdapter
- Returns:
- The generated wrapup code.
- Throws:
IllegalActionException
- If the adapter class for each actor cannot be found, or if an error occurs while the adapter generate the wrapup code.
-
getReference
public java.lang.String getReference(java.lang.String name, boolean isWrite, NamedProgramCodeGeneratorAdapter target) throws IllegalActionException
Return the reference to the specified parameter or port of the associated actor. For a parameter, the returned string is in the form "fullName_parameterName". For a port, the returned string is in the form "fullName_portName[channelNumber][offset]", if any channel number or offset is given.- Parameters:
name
- The name of the parameter or portisWrite
- Whether to generate the write or read offset.target
- The ProgramCodeGeneratorAdapter for which code needs to be generated.- Returns:
- The reference to that parameter or port (a variable name, for example).
- Throws:
IllegalActionException
- If the parameter or port does not exist or does not have a value.
-
getComponent
public NamedObj getComponent()
Return the director associated with this class.- Overrides:
getComponent
in classNamedProgramCodeGeneratorAdapter
- Returns:
- The director associated with this class.
-
getIncludeDirectories
public java.util.Set<java.lang.String> getIncludeDirectories() throws IllegalActionException
Return an empty HashSet.- Overrides:
getIncludeDirectories
in classNamedProgramCodeGeneratorAdapter
- Returns:
- An empty HashSet.
- Throws:
IllegalActionException
- Not thrown in this method.
-
getLibraries
public java.util.Set<java.lang.String> getLibraries() throws IllegalActionException
Return an empty HashSet.- Overrides:
getLibraries
in classNamedProgramCodeGeneratorAdapter
- Returns:
- An empty HashSet.
- Throws:
IllegalActionException
- Not thrown in this method.
-
getLibraryDirectories
public java.util.Set<java.lang.String> getLibraryDirectories() throws IllegalActionException
Return an empty HashSet.- Overrides:
getLibraryDirectories
in classNamedProgramCodeGeneratorAdapter
- Returns:
- An empty HashSet.
- Throws:
IllegalActionException
- Not thrown in this method.
-
getModifiedVariables
public java.util.Set<Parameter> getModifiedVariables() throws IllegalActionException
Return a set of parameters that will be modified during the execution of the model. The director gets those variables if it implements ExplicitChangeContext interface.- Overrides:
getModifiedVariables
in classNamedProgramCodeGeneratorAdapter
- Returns:
- a set of parameters that will be modified.
- Throws:
IllegalActionException
- If the adapter associated with an actor or director throws it while getting modified variables.
-
getParameter
public java.lang.String getParameter(NamedProgramCodeGeneratorAdapter target, Attribute attribute, java.lang.String[] channelAndOffset) throws IllegalActionException
Gets the parameter.- Parameters:
target
- An adapterattribute
- The attributechannelAndOffset
- The given channel and offset.- Returns:
- code for the parameter
- Throws:
IllegalActionException
- If the adapter throws it while generating the label.
-
_ceilToPowerOfTwo
protected int _ceilToPowerOfTwo(int value) throws IllegalActionException
Return the minimum number of power of two that is greater than or equal to the given integer.- Parameters:
value
- The given integer.- Returns:
- the minimum number of power of two that is greater than or equal to the given integer.
- Throws:
IllegalActionException
- If the given integer is not positive.
-
_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.- 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.
-
_generateVariableInitialization
protected java.lang.String _generateVariableInitialization(NamedProgramCodeGeneratorAdapter target) throws IllegalActionException
Generate variable initialization for the referenced parameters.- 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.
-
_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.- 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.
-
-