CS252r: Advanced Functional Language Compilation

Fall 2012: Maxwell Dworkin 323, Mon-Wed-Fri 3-4pm

Greg Morrisett

Homework 3: Due Friday Oct 19

There are two tasks for this homework:

Translation to LLVM

You will want to download and install LLVM if you haven't already. I'm working with the current release version (3.1) of the tools. You can find the documentation here.

I have provided some preliminary definitions for LLVM abstract syntax in the repository, though undoubtedly, there are bugs and problems with it. Feel free to fix such bugs and push them back.

You can assume that the input to your code generator is a version of CPS where all of the function definitions have been lifted to the top-level. Your code generator should produce an LLVM function for each of these functions, plus a function coq_main that kicks off evaluation.

For each function, you should have two arguments corresponding to the allocation pointer and the limit pointer. These extra arguments will be passed to each function or continuation when it is invoked. You can assume that coq_main will be passed appropriate initial values for these two variables. To allocate something of size n bytes, you simply need to make sure that the difference between the limit and alloc pointers is at least n and then increment the allocptr by n.

For now, we will ignore the issue of garbage collection and simply die when we run out of space. You can die by simply calling the exit function.

Throughout the translation, you'll have to be careful to convert to/from a universal type (typically i8* or char* in C-speak) as discussed in class.

Project Proposal

For the rest of the class, we're going to break up into groups and work on more advanced optimizations, analyses, or transformations. There are many potential topics to work on, and I suggest that you team up with at least one other person (but larger teams are encouraged.)

In no particular order, here are some things that you might consider:

Some of these are relatively simple (e.g., break recursive functions into strongly-connected components) while others are major research problems. Pick something that you find interesting and challenging, but that you think you can pull off this semester.

Moving forward, you will be held responsible for finding the key background material for your topic, presenting the major ideas in class, and coordinating with the other groups.