Package ptolemy.domains.giotto.cgc
Class GiottoCEmachineFrameworkGenerator
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.util.Attribute
-
- ptolemy.domains.giotto.kernel.GiottoCodeGenerator
-
- ptolemy.domains.giotto.cgc.GiottoCEmachineFrameworkGenerator
-
- All Implemented Interfaces:
java.lang.Cloneable
,Changeable
,Debuggable
,DebugListener
,Derivable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class GiottoCEmachineFrameworkGenerator extends GiottoCodeGenerator
This attribute is a visible attribute that when configured (by double clicking on it), displays a dialog box asking the user to select a directory. Once the user selects and has clicked on the "Generate Files" button, the attribute does two things- Generates the Giotto code for the model and stores it in "selected_directory/model_name/model_name.giotto".
- Generates the Emachine framework code files and stores them in "selected_directory/model_name/c_functionality/fcode". This particular directory structure is chosen to reflect the Emachine directory structure.
The framework code consists of
- f_code.c
- This contains the driver code for the model, including the output driver initialization code, and memory allocation for array data types.
- f_code.h
- Header file for the previous file. Simply contains the driver function declarations, and the task frequency definitions
- task_code.h
- Contains the function declarations for the task codes. this is simply provided as a convenience to the user as he does not need to worry about the exact syntax of the functions, and can simply copy them from here.
- Since:
- Ptolemy II 11.0
- Version:
- $Id$
- Author:
- Edward A. Lee, Vinay Krishnan
- Pt.AcceptedRating:
- Red (vkris)
- Pt.ProposedRating:
- Red (eal)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
GiottoCEmachineFrameworkGenerator.CEmachineFrameworkEditorFactory
An editor for CE machines.-
Nested classes/interfaces inherited from class ptolemy.domains.giotto.kernel.GiottoCodeGenerator
GiottoCodeGenerator.GiottoEditorFactory
-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
_endLine
The character use at the end of a line.protected java.lang.String
_tabChar
The character to use for a tab.protected java.lang.String
copyrightString
The text to be used for the copyright in the generated code.protected java.util.Set
dataTypes
The set of all unique types used.protected java.lang.StringBuffer
FCinDriversImplString
The functions to implement the input drivers.protected java.lang.StringBuffer
FCoutDriversImplString
The code for the initialization of output drivers.protected java.lang.StringBuffer
FCVarInitString
The code for the initialization of the array variables.protected java.lang.StringBuffer
FHfuncVarDeclString
The declaration of the driver functions and array variables.protected java.lang.StringBuffer
TCfuncImplString
Contains the skeleton code for the task functions.protected java.lang.String
THfuncDeclString
Contains the declaration of the task functions.-
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 GiottoCEmachineFrameworkGenerator(NamedObj container, java.lang.String name)
Construct a factory with the specified container and name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_arrayVariablesAllocationCode(TypedCompositeActor model)
Generate the memory allocation code for the output ports that are of type array.protected void
_driversImplementationCode(TypedCompositeActor model)
Generate implementation code for the drivers.protected void
_generateCodeStrings(TypedCompositeActor model)
Generate the various code strings for the framework C and Header code, as well as the strings for the task C and Header code.protected java.lang.String
_generateFrameworkHeaderCode(TypedCompositeActor model)
Generate code for the H file f_code.h.protected java.lang.String
_generateFrameworkImplementationCode(TypedCompositeActor model)
Generate Framework Implementation C code (f_code.c) for the given model.protected java.lang.String
_generateTaskHeaderCode(TypedCompositeActor model)
Generate code for the H file task_code.h.protected java.lang.String
_generateTaskImplementationCode(TypedCompositeActor model)
Generate the Task Implementation C code (task_code.c) for the given model.protected java.lang.String
_getArrayLength(TypedIOPort port)
Return the value of the "arrayLength" attribute for the given port.protected java.lang.String
_getInitialValueString(TypedIOPort port)
Return the correct Giotto initial value string for the given port.protected java.lang.String
_getTypeString(TypedIOPort port)
Return the type of the port.protected void
_inputDriversImplementationCode(TypedCompositeActor model)
Generate input driver implementation code.protected void
_instantiateEditorFactoryClass()
Method to instantiate the Editor Factory class called from the constructor.protected void
_outputDriversImplementationCode(TypedCompositeActor model)
Generate code which will copy the output local data to the global data.protected void
_outputInitializationCode(TypedCompositeActor model)
Generate initialization code for the output drivers.protected void
_taskCodeSkeleton(TypedCompositeActor model)
Generate code for the task.void
writeFrameworkCode(TypedCompositeActor model, java.io.File directory)
Generate the Framework code for the given model.void
writeGiottoCode(TypedCompositeActor model, java.io.File directory)
Generate Giotto code for the given model and write into the file model name.giotto in the directory specified by parameter "directory".-
Methods inherited from class ptolemy.domains.giotto.kernel.GiottoCodeGenerator
generateGiottoCode
-
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, clone, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setContainer, setName, updateContent
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _description, _executeChangeRequests, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeChanged, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
-
-
-
-
Field Detail
-
dataTypes
protected java.util.Set dataTypes
The set of all unique types used.
-
_endLine
protected java.lang.String _endLine
The character use at the end of a line.
-
_tabChar
protected java.lang.String _tabChar
The character to use for a tab.
-
FHfuncVarDeclString
protected java.lang.StringBuffer FHfuncVarDeclString
The declaration of the driver functions and array variables.
-
FCoutDriversImplString
protected java.lang.StringBuffer FCoutDriversImplString
The code for the initialization of output drivers.
-
FCVarInitString
protected java.lang.StringBuffer FCVarInitString
The code for the initialization of the array variables.
-
FCinDriversImplString
protected java.lang.StringBuffer FCinDriversImplString
The functions to implement the input drivers.
-
THfuncDeclString
protected java.lang.String THfuncDeclString
Contains the declaration of the task functions.
-
TCfuncImplString
protected java.lang.StringBuffer TCfuncImplString
Contains the skeleton code for the task functions.
-
copyrightString
protected java.lang.String copyrightString
The text to be used for the copyright in the generated code.
-
-
Constructor Detail
-
GiottoCEmachineFrameworkGenerator
public GiottoCEmachineFrameworkGenerator(NamedObj container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Construct a factory with the specified container and name.- Parameters:
container
- The container.name
- The name of the factory.- Throws:
IllegalActionException
- If the factory is not of an acceptable attribute for the container.NameDuplicationException
- If the name coincides with an attribute already in the container.
-
-
Method Detail
-
writeGiottoCode
public void writeGiottoCode(TypedCompositeActor model, java.io.File directory) throws IllegalActionException, NameDuplicationException
Generate Giotto code for the given model and write into the file model name.giotto in the directory specified by parameter "directory".- Parameters:
model
- The model for which the Giotto code is to be generateddirectory
- The directory into which the generated file (model_name.giotto) is to be written- Throws:
IllegalActionException
- If the file "directory"/"model_name"/model_name.giotto cannot be openedNameDuplicationException
- If any actor name coincides with the name of another actor already in the model.
-
writeFrameworkCode
public void writeFrameworkCode(TypedCompositeActor model, java.io.File directory) throws IllegalActionException, NameDuplicationException
Generate the Framework code for the given model. It creates the directory "directory"/"model_name"/c_functionality/fcode with the files f_code.c, f_code.h and task_code.h in it.- Parameters:
model
- The model for which the Framework code is to be generateddirectory
- The directory into which the generated files are to be written- Throws:
IllegalActionException
- If any of the files cannot be openedNameDuplicationException
- If any actor name coincides with the name of another actor already in the model.
-
_instantiateEditorFactoryClass
protected void _instantiateEditorFactoryClass() throws IllegalActionException, NameDuplicationException
Method to instantiate the Editor Factory class called from the constructor. The reason for having this is that it can be overridden by subclasses- Overrides:
_instantiateEditorFactoryClass
in classGiottoCodeGenerator
- Throws:
IllegalActionException
- If the editor factory can not be created.NameDuplicationException
- If there is already another editor factory with the same name.
-
_getTypeString
protected java.lang.String _getTypeString(TypedIOPort port)
Return the type of the port.- Parameters:
port
- The port for which to get the type.- Returns:
- The type string describing the type of the port.
-
_getInitialValueString
protected java.lang.String _getInitialValueString(TypedIOPort port) throws IllegalActionException
Return the correct Giotto initial value string for the given port.- Parameters:
port
- The given port.- Returns:
- The Giotto initial value of the string, which is the value of the "initialOutputValue" attribute of the port, if any. If the port does not have an "initialOutputValue" attribute, then the empty string is returned.
- Throws:
IllegalActionException
- If there is a problem reading the "initialOutputValue" attribute from the port.
-
_getArrayLength
protected java.lang.String _getArrayLength(TypedIOPort port) throws IllegalActionException
Return the value of the "arrayLength" attribute for the given port.- Parameters:
port
- The given port- Returns:
- The value of the "arrayLength" attribute, or 1 if the port does not have an "arrayLength" attribute.
- Throws:
IllegalActionException
- If there is a problem reading the attribute from the port.
-
_generateFrameworkImplementationCode
protected java.lang.String _generateFrameworkImplementationCode(TypedCompositeActor model)
Generate Framework Implementation C code (f_code.c) for the given model. This function generates function implementation for a couple of legacy emachine implementations, and the output driver initialization code as well as the input driver code.- Parameters:
model
- The model for which to generate code.- Returns:
- The Framework Implementation C code.
-
_generateFrameworkHeaderCode
protected java.lang.String _generateFrameworkHeaderCode(TypedCompositeActor model) throws IllegalActionException
Generate code for the H file f_code.h. This function generates the function and variable declarations for the implementation in f_code.c- Parameters:
model
- The model for which to generate code.- Returns:
- The output code.
- Throws:
IllegalActionException
- If thrown while reading the frequency parameter.
-
_generateTaskImplementationCode
protected java.lang.String _generateTaskImplementationCode(TypedCompositeActor model)
Generate the Task Implementation C code (task_code.c) for the given model. This function generates function implementation for a couple of legacy emachine implementations, and the output driver initialization code as well as the input driver code.- Parameters:
model
- The model for which to generate code.- Returns:
- The Task Implementation C code.
-
_generateTaskHeaderCode
protected java.lang.String _generateTaskHeaderCode(TypedCompositeActor model)
Generate code for the H file task_code.h. This function generates the function and variable declarations for the implementation in f_code.c- Parameters:
model
- The model for which to generate code.- Returns:
- The output code.
-
_generateCodeStrings
protected void _generateCodeStrings(TypedCompositeActor model) throws IllegalActionException
Generate the various code strings for the framework C and Header code, as well as the strings for the task C and Header code.- Parameters:
model
- The model for which to generate code.- Throws:
IllegalActionException
- If thrown while generating code strings.
-
_outputInitializationCode
protected void _outputInitializationCode(TypedCompositeActor model) throws IllegalActionException
Generate initialization code for the output drivers. In Giotto, the situation that one port has several inputs is illegal. From the output ports, it is easy to trace to get receivers for output delivery.- Parameters:
model
- The model- Throws:
IllegalActionException
- If thrown while accessing ports or checking Giotto IDs.
-
_arrayVariablesAllocationCode
protected void _arrayVariablesAllocationCode(TypedCompositeActor model) throws IllegalActionException
Generate the memory allocation code for the output ports that are of type array. The order of ports in model has effect on the order of driver input parameters- Parameters:
model
- The model for which to generate code.- Throws:
IllegalActionException
- If there is a problem getting the array length of the ports or if the input port is a multiport.
-
_driversImplementationCode
protected void _driversImplementationCode(TypedCompositeActor model) throws IllegalActionException
Generate implementation code for the drivers. The order of ports in model has effect on the order of driver input parameters- Parameters:
model
- The model.- Throws:
IllegalActionException
- If there is a problem generating the input drivers or output drivers code.
-
_outputDriversImplementationCode
protected void _outputDriversImplementationCode(TypedCompositeActor model) throws IllegalActionException
Generate code which will copy the output local data to the global data. This has to generate one function for each data type present.- Parameters:
model
- The model- Throws:
IllegalActionException
- If there is a problem generating the drivers implementation code.
-
_inputDriversImplementationCode
protected void _inputDriversImplementationCode(TypedCompositeActor model) throws IllegalActionException
Generate input driver implementation code.- Parameters:
model
- The model for which to generate the input drivers code.- Throws:
IllegalActionException
- If thrown while determining if an input driver is needed, if the input port is a multiport or if thrown while getting the array length of the output port.
-
_taskCodeSkeleton
protected void _taskCodeSkeleton(TypedCompositeActor model) throws IllegalActionException
Generate code for the task.- Parameters:
model
- The model.- Throws:
IllegalActionException
- If there is a problem generating the task code.
-
-