COS 320 - Assignment 7

Compiling Techniques, Spring 2012, Princeton University.      Due date: Monday 9 April.

Code Generation

Translate the Fun abstract syntax into MIPS assembly with virtual registers.
  1. Create a directory as7 for this assignment. Copy all your as4 files into it, as well as mips.sig and mips.sml from as6. Unpack as7.zip, giving you codegen.sml and compile.sml. Update sources.cm by adding mips.sig, mips.sml, codegen.sml.
  2. Read and understand codegen.sml; you'll notice that it is similar to the fibx.sml from Assignment 6.
  3. Implement the function gen_func.
    Do NOT be worried about all the extra Move instructions you're generating; almost all of these will be removed by a good register allocator.
  4. Implement the function gen_exp.
  5. Test by Compile.compile "test.fun"; This will generate test.fun.noregalloc.s, which will be assembly language that doesn't work because:
  6. After you have gotten it working, read through the output ".noregalloc.s" files to make sure it looks sane--because that's about the only way to debug this assignment without having a register allocator.
  7. After you're convinced that it's sane, improve the quality of the generated code by adding 3 or 4 "munches" that match larger patterns. Don't go overboard with this, because most optimizations should really be done in later phases of the compiler, and it's not always appropriate to prematurely optimize here.
  8. Submit README and codegen.sml to dropbox here. In the README, explain your extra 3 or 4 munches.

Note: Your code generator should not explicitly save and restore caller-save or callee-save registers--not even the return address! It is not the case that the caller must save all the caller-save registers before calling a function. The caller must save all the caller-save registers that are live after the call. However, the codegen module doesn't know what's live. So it should not save or restore anything. A later module (spilling) will fix this up.


Back to COS 320 front page