Title: Project Overview
1Code Generation for Ptolemy II
Ye Zhou, Man-Kit Leung, Christopher Brooks,
Edward Lee, Gang Zhou
University of California, Berkeley
- Project Overview
- Generate code in other languages such as C and
VHDL for a Ptolemy model. - Build a code generation infrastructure for
component-based and heterogeneous modeling. - Based on code generation work in Ptolemy Classic.
- Current work focuses on generating C code for
synchronous dataflow (SDF) models.
The Butterfly Example
Code Generator Architecture
- Macros and Variable Declarations
- Helper classes contain code blocks written in
pseudo language with interspersed macros. - Macros, which always begin with a , take the
places of ports and parameters to hold values. - Referenced macros will be replaced with a unique
variable in the generated code.
E.g., the helper class for the Scale actor
contains ref(output) val(factor)
ref(input) ref(output) refers to the output
port of this Scale actor. val(factor) is the
concrete value of the factor parameter of this
actor. ref(output) will be replaced in the C
code with a unique static variable
ActorFullName_output.
- The CodeGenerator is like a manager in the
Ptolemy model. It governs the overall code
generation. - A directors CodeGeneratorHelper defines the
order of code generation for actors, the way of
data exchange, etc.. It also governs time
advance, buffer management, etc.. - An actors CodeGeneratorHelper contains the basic
C code that implements the function of this actor.
- Conclusion
- We present an infrastructure for code generation
in Ptolemy II. - We have implemented a C code generator for SDF
models.
Code Structure Example
This basically follows the action methods in
Ptolemy.
/including necessary files/ include
stidio.h / variable declarations / Static
int actorFullName_input Static int
actorFullName_initial 0 main() /
generate initialize code / / generate
body code / / generate wrapup code /
- Future Work
- Helper classes for type system.
- Code generation for other domains, such as
Giotto and Finite State Machine. - Code generation for heterogeneous models.
- Code generation infrastructure for multiple
target languages.
The CodeGenerator invokes the director helper,
which will then invokes the actor helpers to
generate code. Benefit actor helper classes are
domain-independent.