This code generator is patterned after the Ptolemy Classic
code generator where actors have template files consisting
of code blocks. The code blocks are stitched together to create
the resulting file.
The adapter definitions that are shared between the procedural languages. For example, the Display adapter is at ptolemy/cg/adapter/generic/program/procedural/adapters/ptolemy/actor/lib/gui/Display.java
The adapters for actors that generate C. In general, the Java class extends the shared adapter
and contains only a constructor. There is an optional .c file that contains
C-specific blocks of code used in code generation.
For example, we have ptolemy/cg/adapter/generic/program/procedural/c/adapters/ptolemy/actor/lib/gui/Display.java
The adapters for actors that generate Java. The layout is similar to the C version, except the
.j file contains the Java template blocks. The file is named .j so that it does not get compiled.
Graphical User Interface (gui) code. If a model has a
ptolemy.cg.gui.CodeGeneratorGUIFactory attribute in it, then
double clicking on that attribute brings up the code generator gui.
Non-language specific code generation classes and language-specific
Modular code generation work and syntactic code generation
Hints about working with the tree
Because the tree is so deep, you may find it easier to use a few tools to quickly search files from the command line.
Search for files
To find all the files named Display use:
find . -name "Display"
Search all the files for a string
find . -type f | xargs grep MyString
How to add an actor
Adding code generation support for an actor is fairly complex, but
follows a pattern.
First, check to see that there is no already a code generation
version of the actor. It could be that there is one for a different
language. Also, look for code generation versions of the actors that
are similar to the actor in question.
The ptolemy/cg directory contains subdirectories that mimic the
Ptolemy II tree. So, if we are adding a code generation version of
an actor in ptolemy/actor/lib, then we will be working in similar
subdirectories in ptolemy/cg.
The code generation system reads blocks of code from a template
file and does substitution. Most of the work occurs in a file that
is shared between the procedural languages (C and Java). The directory is
The C or Java specific code is in
$PTII/ptolemy/cg/adapter/generic/program/procedural/java/adapters/ptolemy/actor/lib/ These directories contain corresponding .c or .j files that define the blocks
used in the generated code.
These directories also contain a test/auto/ directory that contains the test models.
Supporting different targets
A target is typically an architecture-specific platform. For
example, the arduino target generates C-code meant to run
on the Arduino platform.
To generate code for a target, use the -generatorPackageList command line argument to
$PTII/bin/cg. The value of the -generatorPackageList parameter i
a semicolon or * separated list of Java packages to be searched for adapters. For example