|
|
Milestone 5 : Code GenerationYour task in this milestone is to extend the StaticJava code generator to support ExtendedStaticJava programs. The differences between StaticJava and ExtendedStaticJava are highlighted in the EBNF for ExtendedStaticJava. Most of the work in this milestone requires you to override and extend the ByteCodeGenerator.Visitor visit methods in a file ExtendedByteCodeGenerator.java to implement code generation for the ESJ constructs. For extra credit, you may implement a selection of different optimizations. These can be improvements to the code generation strategies that exist in the SJ ByteCodeGenerator. They can also be implemented as transformations of the AST. For example, you could implement a visitor that transforms expressions in the AST to, e.g., perform arithmetic on operators with constant operands at compile time, to simplify arithmetic expressions based on identities or other algebraic properties. Note that these simplifications can "cascade" through a program yielding additional opportunities for optimization. You can receive up to 25 additional points for completing this extra credit. Credit will be assigned in 5 point increments for each distinct optimization that is described, implemented and demonstrated via test cases. You must submit your assignment through the course Project Upload site by 11:59pm CDT on Friday Nov. 30, 2007. SetupDownload the file myname-milestone5.zip This contains a skeletal implementation of the milestone with a JUnit testing framework for your use. In order to import the projects into your workspace, do the following: Goto the "File" menu, select "Import". Expand "General" and select "Existing Projects into Workspace". Click "Next". Select "Select archive file:" and click the "Browse" button associated with it. In the file browser, points to the milestone2.zip that you downloaded. You should see "myname-milestone5", check the box, and click "Finish". If you run Eclipse appropriately (i.e., using Java 5.0 and the right versions of plugins and by following the instructions in the course quick notes website), your workspace should be set. Make sure you rename "myname" in the project's name into your CIS username by right clicking the project, select "Refactor" -> "Rename...".
Instructions and HintsYour assignment is to implement the bytecode generator
for ESJ. You will do this by adding to the file: sjc.codegen.extended.ExtendedByteCodeGenerator to implement the byte code generation for the ESJ constructs; similar to previous phases you will use the existing SJ ByteCodeGeneratorimplementation as a basis for your implementation. The milestone skeleton contains a completely working version of the ESJ compiler up through type checking. You can tell if you are making progress by running the JUnit test
suite. This is done by highlighting the class: sjc.test.extended.ExtendedByteCodeGeneratorTest, right clicking and selecting "Run As" -> "JUnit Test". The results will be shown in total and on a per test case basis. You can see the source of the test cases in You are done when all of the test cases pass or your run out of time. It is a useful design strategy to write down a code generation template for each new construct in ESJ before implementing it. Use the templates from lecture as a guide. Then you can map your rule to an implementation following the model of the StaticJava code generator. IMPORTANT: Try to reuse as much of the StaticJava code generator as possible. You will definitely need to make some changes and perhaps add new visit methods, but there is much that can be reused and there is lots to learn from studying that code. Remember that ASM and the ASMifier are great resouces. If you are in doubt as to how to generate byte codes for a program fragment, use the ASM viewer to show the byte codes generated by the Java compiler in Eclipse. Even better you can toggle the bytecode view to use the ASMifier to show you the sequence of ASM API calls to generate the given bytecodes. What To SubmitYour solution should consist of the following :
As with all programming, I expect that you provide reasonable internal documentation describing tricky/subtle parts of your implementation. If you have any limitations in your implementation If you have any limitations in your implementation you should include documentation describing those as well, since if we find them we will assume that you did not. Your grade will be based on your solution (80%), your in code generation template documentation (15%), and the description of limitations you provide (5%). If you admit to failing a test then you will lose only half of the points associated with that test in comparison to our finding out you fail the test when we run your solution. |