Download Compiler construction Project description

Transcript
Indexing uses the getelementptr instruction, which is discussed in detail in the lectures.
In contrast to JVM, the LLVM does not include a runtime system with garbage collection. Thus,
this extension should really include some means for reclaiming heap memory that is no longer
needed. The simplest would be to add a statement form free(a), where a is an array variable.
This would be straightforward to implement, but is not necessary to get the credit.
More challenging would be to add automatic garbage collection. LLVM offers some support
for this. If you are interested in doing this, we are willing to give further credits for that task.
7.2. Multidimensional arrays
We emphasize again that this and the following extensions only give credit in the LLVM submission.
This extension involves more work than the previous one. In particular, you must understand
the getelementpointer instruction fully and you must generate code to iteratively allocate
heap memory for subarrays.
7.3. Structures and object-orientation.
Techniques to do these extensions are discussed in the lectures.
From an implementation point of view, we recommend that you start with the extension with
pointers and structures. You can then reuse much of the machinery developed to implement
also the first OO extension. In fact, one attractive way to implement the object extension is by
doing a source language translation to Javalette with pointers and structures.
The full OO extension requires more sophisticated techniques, to properly deal with dynamic
dispatch.
7.4. Native code generation
The starting point for this extension could be your LLVM code, but you could also start directly
from the abstract syntax. Of course, within the scope of this course you will not be able to
produce a code generator that can compete with llc, but it may anyhow be rewarding to do also
this final piece of the compiler yourself.
One major addition here is to handle function calls properly. Unlike JVM and LLVM, which
both provide some support for function calls, you will now have to handle all the machinery
with activation records, calling conventions, and jumping to the proper code before and after
the call.
There are several assemblers for x86 available and even different syntax versions. We recommend that you use the NASM assembler and that you read Paul Carter’s PC assembly tutorial
(linked from course web site) before you start the project, unless you are already familiar with
x86 architecture. We do not have strong requirements on code quality for your code generator;
straightforward code generation is acceptable. In particular, you do not need to implement register allocation to improve your code. This will also have serious negative consequences for the
performance of your code. Indeed, a preferrable way to get native code is to use a framework
like LLVM, which provides an extensive infrastructure for code manipulation.
An introduction to x86 assembler will be given in the lectures.
8. Collaboration and academic honesty
As mentioned before, you work individually or in groups of two in this project. You must
develop your own code, and you are not allowed to share your code with other students or to get,
or even look at, code developed by them. On the other hand, we encourage discussions among
21