Presentation is loading. Please wait.

Presentation is loading. Please wait.

Code Generation for Ptolemy II

Similar presentations


Presentation on theme: "Code Generation for Ptolemy II"— Presentation transcript:

1 Code 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 The Ptolemy Model The Code Generator GUI C Code Output Generated C Code 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. Associate A Ptolemy Model invokes 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 director’s CodeGeneratorHelper defines the order of code generation for actors, the way of data exchange, etc.. It also governs time advance, buffer management, etc.. An actor’s 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. Buffer Management Each actor helper provides an interface to maintain the buffer size and offset for each of its communication channels. The director helper determines the buffer size for each channel. The director helper updates the offset of each channel while generating the code. Handling Delays in SDF The offset of an input port is the buffer position from which tokens are read. The offset of an output port is the buffer position to which tokens are written. 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.


Download ppt "Code Generation for Ptolemy II"

Similar presentations


Ads by Google