Phoenix as an Instruction tool
As I mentioned in my previous blog, why use Phoenix as an instruction tool? Before getting in to that, let us see what is needed to teach compilers.
Typically one learns up to Intermediate Code generation in an Introductory Compiler class and learns about the 'real' code generation aspects in an Advanced Compiler course. In an introductory class, most of the time is spent in building lexers and parsers or in learning how to use Lex/ Yacc kind of tools. By now half of the semester is gone, and most of the students would have realized that they can't make an A. Their faulty/ incomplete lexer/ parser is going to haunt them till the end. The rest of the semester is spent building an AST or an Intermediate code generator. By the end of the semester, one would have lost many nights of sleep, developed a deep hatred toward compilers and cribbed enough about making the compilers course an elective. On the other hand, a handful of students would have reveled in the challenges they had to face in building a compiler. Even those handful, unless they choose to delve further in to an Advanced Compiler course or Compiler research, are probably not going to see what happens between the IR and the binary. Thus, for most of the computer science students, compiler continues to remain a dark art!
In an Advanced Compiler Course, much time is spent in hacking gcc/lcc kind of compilers to implement a phase of the compiler or in learning SUIF/Trimaran kind of infrastructures. What is ideal for compiler instruction would be:
1) A complete framework that is easier to learn
2) Adding compiler phases/ passes to the framework should be easier. One only needs to worry about the pass/ phase that is needed
3) One that provides a way to build a compiler for real languages (including Object oriented languages)
4) One that provides a rich Intermediate Language that one can play with
5) Easily retargetable
SUIF and Trimaran are widely used in compiler research around the world. Each has its own pros and cons. With due respect to these suites, I personally think they are not suitable for compiler instruction for the following reasons:
1) It needs a lot of effort to implement a phase in Trimaran
2) SUIF is more suitable for functional languages than Object oriented languages (there is OSUIF that tries to fill in this gap, but that is not complete.
This is where Phoenix fits in. Most attractive feature of Phoenix is that one can add a phase by writing a 'plugin' and pass it to the compiler. No changes to the Phoenix source code! Pheonix supports C,C++, C# - you name it (more on this later). If you have half an hour, play with the Phoenix RDK to see how easy it is build a plug-inPhoenix. Blogging on IR needs to be more involved. I will reserve it for later. Thus, one can easily see that Phoenix is a great instruction tool. While it has features that makes it enticing to be used as an instruction tool, there are more things that need to be done.
While I was a graduate student, we used COOL compiler i. Most attractive feature of COOL is it is modular. One can replace the compiler's module with one's own. Say I screwed up my lexer, but when we got to the parse stage, I got the hang of it and implemented it correctly. I don't have to lose points because of my faulty lexer, because I can use the compiler's lexer. This way I don't get penalized for my earlier mistakes. However, COOL had a steep learning curve too. Also, one has to 'learn' the COOL language to implement the COOL compiler.
I am thinking of an instruction kit in the lines of COOL using Phoenix to teach Advanced Compilers. The kit should server two purposes - instruction and assignments. It should provide ability to be used by the instructor in the class to explain/ show visually the IR transformations/ graphs/ trees. Typical assignments could be implementation various phases of the compiler as plug-ins. Real plug-inschallenge would be to devise programming assignments that require a good grasp of back-end optimizations and to design test cases. As an instructor, one also needs to take care of plagiarism etc. But let us not talk about that now...