From: David H. <sd...@ep...> - 2008-06-05 19:47:31
|
Hello, as a part of a bachelor's thesis in computer science, I've been experimenting with creating a different frontend for SDCC. In short, I've split SDCC in half, removing the AST stuff, and created new functions for creating iCode instructions, operands and sym_links (the SDCC equivalent of types). Then this library version of SDCC was merged with an existing Java frontend, so SDCC iCode could be generated from Java source code. As the Java frontend was written in Java, the interface to SDCC is JNI (Java Native Interface). Sounds interesting? Bear in mind though, that this is just a prototype so far, and far from alpha, as only a small subset of the Java language is supported (everything must be static, new operator is not supported, no arrays, no exceptions, etc). I've also, for simplicity, commented out every backend architecture except pic14 - bringing them back online shouldn't be much work though. Nevertheless, I think my work could be a good starting point for anyone who is thinking of doing something similar, or is trying to understand the internals of SDCC iCode. (Presuming I've done at least approximately right when interfacing the SDCC code! ;-) ) The SDCC code was taken from a daily build some day in February, 2008. Unfortunately, I don't have the time to continue working on this project (unless someone would be willing to pay me for doing so). But SDCC is GPL, the Java frontend is a mix of GPL and BSD licensed code, and I'm also willing to share my code under GPL, if anyone would be interested in continuing my work, or use it for study. Then I also think I have to write some documentation of how to get things up and running, specifically as the Java frontend requires some extra tools to make it work properly. If I should do this - let me know. As a demo, below is some example Java code that works in my prototype, and plays a melody on the PWM output (if you connect a speaker to it). import piclibrary.Pic; public class PWM { public static void init() { Pic.setTRISB((byte) (Pic.getTRISB() & 0xF7)); Pic.setPORTB((byte) (Pic.getPORTB() & 0xF7)); Pic.setCCP1CON((byte) 0x0C); } public static void start(int period, int dutycycle) { Pic.setPR2((byte) period); Pic.setCCPR1L((byte) dutycycle); Pic.setT2CON((byte) 0x7); } public static void stop() { Pic.setT2CON((byte) 0x0); } } public class SoundMain { public static void delay(int delms) { for (int i=0; i < delms; i++) for (int j=0; j < 35; j++) Pic.getPORTB(); } public static void play(int period, int delayms) { PWM.start(period+period, period); delay(delayms); } public static void quiet(int delayms) { PWM.stop(); delay(delayms); } public static void main() { PWM.init(); while (true) { play(110, 100); play(85, 100); play(65, 100); play(55, 100); quiet(100); play(65, 100); play(55, 100); quiet(300); } } } |