Class 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
    1. Generates the Giotto code for the model and stores it in "selected_directory/model_name/model_name.giotto".
    2. 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)
    • 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 generated
        directory - 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 opened
        NameDuplicationException - 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 generated
        directory - The directory into which the generated files are to be written
        Throws:
        IllegalActionException - If any of the files cannot be opened
        NameDuplicationException - If any actor name coincides with the name of another actor already in the model.
      • _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.