Compilers: Programming Assignment 6a

Basic blocks

Due date: ASAP (see below)

This phase of the final project deals with basic blocks and traces. (You should review the reading on blocks and traces, handed out a few weeks ago.) It is intended to be a short project en route to the more daunting task of code generation which lies ahead. There is no specific due date, but you should aim to complete it as soon as possible.

A basic block is a maximal sequence of instructions that must be executed sequentially. That is it has only one point of entrance and one point of exit in terms of control flow. The concept of a basic blocks can be applied to both intermediate representation and assembly language. In the latter, it can be used to produce more efficient dataflow analysis and for other optimizations. We use it here, at the IR level, to allow us to reorder IR instructions so that every conditional statement is followed by its else block.

The task required for this phase of the compiler is split into two:

  1. For each list of IR instructions corresponding to a function body, generate a list of basic blocks.
  2. For each of those lists of basic blocks, we reorder the blocks - using traces so that: (This second half, generating traces, has been implemented for you.)

You only need work in BasicBlocks (in the basic_blocks package) though you may want to uncomment a line or two in BlockTraceTest (in the main package) to test your work. A correctly working program should produce Cflat code that compiles and executes as it did with the previous phase of the project.

Although you only need to modify one file, it is useful to dowload the entire project since there have been several changes since we last left off.

The places to work are marked with comments with "..." in them - the comments explain the task at hand. Read them carefully.


Submission

You need not submit this portion of the assignment; it will just be very useful to make the next phase - code generation - work correctly.