A6: LLVM LLVM dragon

Due: Tuesday, 4/19

Static Single Assignment RTL to LLVM

Your job

in this assignment: translate SSA RTL programs to LLVM, for compilation by the LLVM compiler.

Download the entire set of A6 files here. You won't rely very heavily on the Grumpy language specification for this assignment but we link to it just in case.

Triple Programming

On this assignment, you may triple-program with up to two other people. If you do so, write the names of your collaborators in a comment at the top of your llvm.ml. For example:
  (* NAME: Your name
     OUID: Ohio University ID

     I worked with ... on this assignment. *)
Each student should individually turn in llvm.ml on Blackboard, regardless whether you worked with someone else. Triple programming does not mean each student does a third of the assignment. Instead, it means the three of you construct llvm.ml collaboratively, while all sitting at the same computer screen.

0. Install clang 3.6.0

This assignment requires clang version 3.6.0. Get it by downloading and installing the appropriate binary from http://llvm.org/releases/download.html.

1. Download the assignment files

First, download the assignment files and unzip the resulting gzipped tarfile into a new directory.
  $ tar xzvf a6.tgz
In the resulting directory src you'll find the following file structure:
  src/               -- compiler source files
    Makefile         -- the project Makefile
    _tags            -- the tags file for ocamlbuild
    AST.mli          -- language-independent abstract syntax stuff
    AST.ml           -- associated helper functions
    exp.mli          -- the definition of Grumpy's abstract syntax
    exp.ml           -- associated functions
    lexer.mll        -- ocamllex source file (stub)
    parser.mly       -- Menhir source file (stub)
    tycheck.mli      -- The type-checker interface
    tycheck.ml       -- The type-checker (stub)
    ssa.mli          -- Defines the RTL intermediate language
    ssa.ml           -- ssa translation (stub)
    config.ml        -- the LLVM target triple (described below)
    llvm.mli         -- commented interface to the LLVM language
    llvm.ml          -- (Part II)
    grumpy.ml        -- the toplevel compiler program    
    tests/           -- test cases
To build the project, type
  $ make
You'll see a bunch of warnings at this point because many of the files above are stubs. Stick your own working versions in their place.

If your SSA translation doesn't work quite right, you can request a working version from Sam or from me. Just shoot one of us an email. We only ask that you don't share this file with others or post it on the internet.


Run the tests by doing

  $ make test
or by typing ./run.sh from within the tests directory.

For this assignment, the *.expected files in the tests directory contain the values we expect each Grumpy program to return. Building the test target does the following:

The last three files are most relevant to this assignment. To pass a test case, X.gpy.ll must compile to X.gpl.out without error and X.gpl.expected and X.gpl.produced must contain the same result.

When you run test cases, you may notice warnings of the form
warning: overriding the module target triple with x86_64-pc-linux-gnu
To disable this warning, edit src/config.ml to set target_triple to equal the triple suggested for your machine. For example, on my machine, I change config.ml from:
  let target_triple = ref "i386-pc-linux-gnu"
  let target_triple = ref "x86_64-pc-linux-gnu"
because I have a 64-bit platform.

2. llvm.ml

Your job in this part is to implement the compilation functions sketched out as stubs in src/llvm.ml. The top-level compilation function

  val llvm_of_prog : (ty, instr list) prog -> (lty, linstr list) prog
maps SSA programs to LLVM programs.

To complete this part, first open llvm.ml and read the general instructions (number 0). Then, complete the four numbered functions 1-4, leading up to llvm_of_prog (number 4).

3. Submit

Submit your llvm.ml on or before the due date, via Blackboard.

4. Piazza

Finally: if any of these instructions are unclear, ask for clarification early and often on Piazza. I want everyone to succeed (and have fun!) on this assignment.