DOC PREVIEW
Berkeley COMPSCI 164 - MJ Code Generation and Competition

This preview shows page 1 out of 3 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

UNIVERSITY OF CALIFORNIADepartment of Electrical Engineeringand Computer SciencesComputer Science DivisionProf. R. FatemanFall, 2005CS 164 Assignment 6: MJ Code Generation and CompetitionDue: Thursday, Nov 24, 2005, 11:59PMOverall objectivesThis assignment requires you to revise your previous project, or start from the translatorwe supplied to you. Or somewhat less likely start again from the interpreter we supplied toyou. You must produce machine language code that will execute MiniJavaprograms. Theseprograms should be executable (that is, compute results, and write output), and you should,for example, be able to run Factorial.java or your sort program.To simplify this task we have supplied you with a virtual machine simulator and anassembler for it in the file simple-machine.lisp. It is open source. Feel free to look at it.We have also set up a number of helpful programs which will take care of some of the routinetasks. You are not allowed to modify the machine language of the machine you have in handin terms of the assignment, but you are welcome to modify it for your debugging purposes.In fact, we think you won’t have to do any modifications here, either. We s uggest moderationin changing the machine, since we are convinced it is actually not necessary to do so.The result of the processing should be tantamount to a binary encoding of a machine-language program. You should also be able to display convincing assembly-language code forany program that passes the type-checker, but is otherwise arbitrary MiniJava.A serious implementation of MiniJavain assembler should likely have two kinds of run-time checks: conformance to array bounds and insuring that you don’t try to follow a nilpointer from a variable of a class that hasn’t been initialized.WarningWriting the code generator should be less time-consuming than the typechecker, at leastjudging by code size.1CS 164 Assignment 6: MJ Code Generation and Competition 2Some of the code in simple-compile.fasl has been re-used from the translator. Recallthat the code for assignment 5 (typechecker) was about 650 lines, if you include the environ-ment setup. This code is about 330 lines long. We are supplying you with short-compile.lispwhich is a nearly-bare file, showing only the principal interfaces.This project will again require close attention to detail, and you should run as many testcases as you think are necessary to convince us that your program is correct. You are notexpected to produce co de from an AST that fails to pass the typechecker.Experience with this class suggests that you may find glitches in our compiler just asfor the typechecker and interpreter and possibly in the VM. It would not surprise us if yourprogram is better than ours.How to approach this taskStarting from the AST, just as you did for typechecking, you can separately code the compila-tion of each of the kinds of computational expressions you have encountered in typechecking.That is, a central comp function can check for the “atomic” cases (e.g. this generates aninstruction to put this object on the stack.) Then you enter a dispatch to produce s ec tionsof code for each MiniJavaconstruct. For example, to compile an IntegerLiteral 3 you cancall generate an instruction to put 3 on the run-time stack.You will have to generate code for each construction If, Block, While etc.What about Declarations?One ordinarily doesn’t produce any code in compiling type declarations: these are used justto help keep track of information for the rest of the code generation. There is some codegenerated for function and variable declarations, including the compilation of the initial valueexpressions for variables, but MJ doesn’t have that. The generation of code will proceed fromthe compilation of function bodies. This code is stored in some other piece of memory, tobe called when necessary. Much of the sequence of operations will look just like the type-checking, especially since you must shuffle around information about environments. In effectwhen you need to get access to a variable, you will look up where it would live at run-timein an environment, and then generate the appropriate reference instructions. You will haveto be keenly aware of the difference between lval and rval access to names or values, and howto get and set values in different environments.Does my code have to be efficient?NO. It should be correct, and it should be fairly obviously correct, at least when looked at insmall pieces.HOWEVER, we encourage you to look at optimization possibilities and supply anotherversion of your compiler that either produces more compact code, or faster-running code, orperhaps shorter AND faster. The VM instructions may take variable amounts of time forsimulations. Details later.CS 164 Assignment 6: MJ Code Generation and Competition 3You will receive extra credit for achievements in optimization as well as presenting prob-lematical MJ programs which break other teams’ optimizers. If you find bugs in our code,please tell us.Built-in FunctionsIf we had many built-in functions, we would have to systematically store these in some“precompiled” form to load up with our compiled program. Since MiniJava is so meagermaybe we can just hack up a call to execute Println as an assembler op-code.In order for optimization to make sense we need to have some input method. You willprovided such a method for integer input.Where do I get information on the virtual machine?There is more information on-line in the source files which completely define the assemblerand the VM, will be discussed in section this week as well as in the lecture notes for severalupcoming lectures numbers 19 / 20.What do I turn in?Expect to turn in one or more files comp.lisp, transcripts and tests described in README.If you have compiler optimizations, turn those in too, with further discussion. Keep your eyeon the class newsgroup for


View Full Document

Berkeley COMPSCI 164 - MJ Code Generation and Competition

Documents in this Course
Lecture 8

Lecture 8

40 pages

Load more
Download MJ Code Generation and Competition
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view MJ Code Generation and Competition and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view MJ Code Generation and Competition 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?