Class ProceduralCodeGenerator

    • Field Detail

      • compile

        public Parameter compile
        If true, then compile the generated code. The default value is a parameter with the value true.
      • compileCommand

        public StringParameter compileCommand
        The command to use to compile the generated code if the useMake parameter is false. The initial default value is "make -f @modelName@.mk". Various '@' delimited key/value pairs will be automatically substituted. In the default case @modelName@ will be replaced with a sanitized (Java-safe) version of the model name.

        If the string "@help:all@" appears, then all the key/value pairs are echoed at run time, though this may not result in a syntactically correct command.

        If useMake is true, then the value of this parameter is ignored.

      • generateEmbeddedCode

        public Parameter generateEmbeddedCode
        If true, then generate code for that uses the reflection for Java and JNI for C and is embedded within the model The default value is false and this parameter is not usually editable by the user. This parameter is set to true when CompiledCompositeActor is run in an interpreted Ptolemy model. This parameter is set to false when a model contains one or more CompiledCompositeActors and C or Java code is being generated for the model.
      • _includes

        protected java.util.Set<java.lang.String> _includes
        Set of include command line arguments where each element is a string, for example "-I/usr/local/include".
      • _libraries

        protected java.util.List<java.lang.String> _libraries
        List of library command line arguments where each element is a string, for example "-L/usr/local/lib". This variable is a list so as to preserve the order that the library commands were added to the list of libraries matters, see the manual page for the -L option of the ld command.
      • _compileCommandDefault

        protected static final java.lang.String _compileCommandDefault
        The initial default value of the compileCommand parameter. The constructor of a derived class may compare the value of compileCommand and this variable and decide to override the value of the compileCommand parameter with a new value.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ProceduralCodeGenerator

        public ProceduralCodeGenerator​(NamedObj container,
                                       java.lang.String name,
                                       java.lang.String outputFileExtension,
                                       java.lang.String templateExtension)
                                throws IllegalActionException,
                                       NameDuplicationException
        Create a new instance of the ProceduralCodeGenerator.
        Parameters:
        container - The container.
        name - The name of the ProceduralCodeGenerator.
        outputFileExtension - The extension of the output file. (for example c in case of C and java in case of Java)
        templateExtension - The extension of the template files. (for example c in case of C and j in case of Java).
        Throws:
        IllegalActionException - If the super class throws the exception or error occurs when setting the file path.
        NameDuplicationException - If the super class throws the exception or an error occurs when setting the file path.
    • Method Detail

      • addInclude

        public void addInclude​(java.lang.String includeCommand)
        Add an include command line argument the compile command.
        Parameters:
        includeCommand - The include command, for example "-I/usr/local/include".
      • addLibrary

        public void addLibrary​(java.lang.String libraryCommand)
        Add a library command line argument the compile command.
        Parameters:
        libraryCommand - The library command, for example "-L/usr/local/lib".
        See Also:
        addLibraryIfNecessary(String)
      • addLibraryIfNecessary

        public void addLibraryIfNecessary​(java.lang.String libraryCommand)
        If the compile command does not yet containe a library, add a library command line argument the compile command.
        Parameters:
        libraryCommand - The library command, for example "-L/usr/local/lib".
        See Also:
        addLibrary(String)
      • markFunctionCalled

        public void markFunctionCalled​(java.lang.String name,
                                       ProceduralTemplateParser templateParser)
                                throws IllegalActionException
        Add called functions to the set of overloaded functions for later use. If the function starts with "Array_", add everything after the "Array_" is added to the set of token functions used.
        Parameters:
        name - The name of the function, for example "Double_equals"
        templateParser - The corresponding templateParser that contains the codeBlock.
        Throws:
        IllegalActionException - If there is a problem adding a function to the set of overloaded functions.
      • _concatenateElements

        protected java.lang.String _concatenateElements​(java.util.Collection<java.lang.String> collection)
        Given a Collection of Strings, return a string where each element of the Set is separated by a space.
        Parameters:
        collection - The Collection of Strings.
        Returns:
        A String that contains each element of the Set separated by a space.
      • _executeCommands

        protected int _executeCommands()
                                throws IllegalActionException
        Execute the compile and run commands in the codeDirectory directory.
        Overrides:
        _executeCommands in class RunnableCodeGenerator
        Returns:
        The return value of the last subprocess that was executed or -1 if no commands were executed.
        Throws:
        IllegalActionException - If there are problems reading parameters or executing the commands.
      • _writeMakefile

        protected void _writeMakefile​(CompositeEntity container,
                                      java.lang.String currentDirectory)
                               throws IllegalActionException
        Read in a template makefile, substitute variables and write the resulting makefile.

        If a .mk.in file with the name of the sanitized model name, then that file is used as a template. For example, if the model name is Foo and the file Foo.mk.in exists, then the file Foo.mk.in is used as a makefile template.

        If no .mk.in file is found, then the makefile template can be found by looking up a resource name makefile.in in the package named by the generatorPackage parameter. Thus, if the generatorPackage has the value "ptolemy.codegen.c", then we look for the resource "ptolemy.codegen.c.makefile.in", which is usually found as $PTII/ptolemy/codegen/c/makefile.in.

        The makefile is written to a directory named by the codeDirectory parameter, with a file name that is a sanitized version of the model name, and a ".mk" extension. Thus, for a model named "Foo", we might generate a makefile in "$HOME/codegen/Foo.mk".

        Under Java under Windows, your $HOME variable is set to the value of the user.homeSystem property, which is usually something like C:\Documents and Settings\yourlogin, thus for user mrptolemy the makefile would be C:\Documents and Settings\mrptolemy\codegen\Foo.mk.

        See the parent class ProgramCodeGenerator._writeMakefile(CompositeEntity, String) for variable that are substituted by the parent class.

        This class substitutes the following variables:

        @PTCGIncludes@
        The elements of the set of include command arguments that were added by calling addInclude(String), where each element is separated by a space.
        Overrides:
        _writeMakefile in class ProgramCodeGenerator
        Parameters:
        container - The composite actor for which we generate the makefile
        currentDirectory - The director in which the makefile is to be written.
        Throws:
        IllegalActionException - If there is a problem reading a parameter, if there is a problem creating the codeDirectory directory or if there is a problem writing the code to a file.