[EMAIL PROTECTED] writes: > Hi all, > > What is the status of the java code generation in Ptolemy ? >
Hi Vincent, I updated the Ptolemy II FAQ with some info: http://ptolemy.eecs.berkeley.edu/ptolemyII/ptIIfaq.htm#CodeGen says: --start-- 5.8 What about Code Generation? Ptolemy II include a code generator developed by Stephen Neuendorffer that reads non-hierarchical SDF models and generates Java .class files. This code generator is called Copernicus. We call this the deep code generator. The code that is produced by deep codegen uses very little of the Ptolemy infrastructure. The ptolemy.math package is used sometimes. In addition, Copernicus can read in models from other domains and generate a .class file that uses much more of the Ptolemy infrastructure. We call this the shallow code generator. Copernicus can also read in models and generate applets. To generate an applet within the Ptolemy II tree, try cd $PTII/ptolemy/domains/sdf/demo mkdir ButterflyTest cp Butterfly/Butterfly.xml ButterflyTest/ButterFlyTest.xml $PTII/bin/copernicus -codeGenerator applet -targetPath ptolemy/domains/sdf/demo/ButterflyTest ButterflyTest.xml The Copernicus deep and shallow codegenerators can use treeshaking to run the model, make a list of the classes that are used and create a jar file that contains only those class files. We can also use the Jode obfuscator to reduce jar file size. We've had limited success using the deep and shallow code generators with the GNU gcj compiler to create small standalone binaries. Another Copernicus effort is the C code generator, which was created by Ankush Varma and Professor Shuvra S. Bhattacharyya of the University of Maryland, The Copernicus C code generator generates C files for certain SDF models. This C code generator is still very experimental. For more information about the Copernicus code generator, see http://ptolemy.eecs.berkeley.edu/ptolemyII/ptIIlatest/ptII/doc/codegen.htm and Stephen Neuendorffer, Actor-Oriented Metaprogramming, PhD Thesis, University of California, Berkeley, December 21, 2004. http://ptolemy.eecs.berkeley.edu/publications/papers/04/StevesThesis and Ankush Varma, "Retargetable Optimizing Java-to-C Compiler for Embedded Systems," Master's Report, Department of Electrical and Computer Engineering, University of Maryland, College Park, MD, 2003. http://ptolemy.eecs.berkeley.edu/publications/papers/03/java-2-C As of Ptolemy II 4.0, no further development is occuring in Copernicus. However, the Ptolemy group is developing a Ptolemy Classic style code generator that uses template files to build C files. This code generator is not available in Ptolemy II 5.0. --end-- -------- > I've read that shallow code generation was about transforming the > MoML file into a main java file. Yep, you can do something run the shallow code generator to create a .class file. Do: cd $PTII $PTII/bin/copernicus ptolemy/actor/lib/test/auto/IIR.xml -codeGenerator shallow This will create the $PTII/ptolemy/copernicus/shallow/cg/IIR directory. That directory will contain the IIR/CGIIR.class file. To run the model, do: cd $PTII/ptolemy/copernicus/shallow/cg/IIR java -classpath ".:$PTII" ptolemy.actor.gui.CompositeActorApplication -class IIR.CGIIR > Is there a process to generate a java application with only the > classes needed to run the model ? Treeshaking is where we run the model, note what classes were loaded and then create a jar file with just those classes. The shallow code generator does not include a rule to run the treeshaker, but you can run it by hand: cd $PTII/ptolemy/copernicus/shallow/cg/IIR jar -cf IIR.jar IIR $PTII/util/testsuite/treeshake /usr/bin/jar IIR.jar -main IIR.CGIIR java -classpath ".:$PTII" ptolemy.actor.gui.CompositeActorApplication -class IIR.CGIIR The resulting jar file is 783k. It could be reduced by using Jode to obfuscate the class or by creating a jar file that contains only the methods that were actually loaded. To run the jar file, do: java -classpath IIR.jar ptolemy.actor.gui.CompositeActorApplication -class IIR.CGIIR See $PTII/ptolemy/copernicus/java/makefile.in for rules that will run the obfuscator etc. I've had some success running the treeshaker and then trying to compile with GNU gcj and adding class files to the jar file until gcj will produce a native .exe file. This is hard to do automatically, but can be done by hand in short order. > How do we activate the code generator GUI ? I pulled the code generator UI because it was basically unusable. I suggest using $PTII/bin/copernicus instead. To renable GUI, try editing $PTII/ptolemy/configs/defaultFullConfiguration.xml and change <!-- property name="factory2" class="ptolemy.actor.gui.PtolemyTableauFactory" --> <!-- property name="Code Generator" class="ptolemy.copernicus.gui.GeneratorTableau$Factory"/--> <!--/property--> to <property name="factory2" class="ptolemy.actor.gui.PtolemyTableauFactory"> <!property name="Code Generator" class="ptolemy.copernicus.gui.GeneratorTableau$Factory"/> </property> I'm not sure if the GUI will work or not. Let me know if you have any further questions. Copernicus has its limitations, but I use it to generate applets all the time. Currently the shallow code generator successfully generates code on 392 of 424 test models in the tree, which is a pretty good ratio. We could probably fix some of the 32 failures (it is on my list). _Christopher > Regards, > > Vincent ---------------------------------------------------------------------------- Posted to the ptolemy-hackers mailing list. Please send administrative mail for this list to: [EMAIL PROTECTED]