Class Director

    • 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 class NamedProgramCodeGeneratorAdapter
        Returns:
        The generated code.
        Throws:
        IllegalActionException - If the adapter associated with an actor throws it while generating fire code for the actor.
      • 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.
      • 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 class NamedProgramCodeGeneratorAdapter
        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 class NamedProgramCodeGeneratorAdapter
        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 class NamedProgramCodeGeneratorAdapter
        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​(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​(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 class NamedProgramCodeGeneratorAdapter
        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 port
        isWrite - 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.
      • 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 class NamedProgramCodeGeneratorAdapter
        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 adapter
        attribute - The attribute
        channelAndOffset - 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.