Milestone #5: Code Generation

Due: Thursday August 10th at 11:59pm

This milestone will require you to complete the translation from AST to LLVM IR and begin native code generation.

Milestone Requirement: LLVM IR

For this milestone, your compiler will take the validated AST from semantic analysis translate it into LLVM IR. As stated in lecture, the output of LLVM IR is a .ll file that contains the original source code represented in its LLVM IR form.

You are only required to use a stack-based implementation.

Milestone Requirement: ARM Code Generation

After LLVM IR translation, you will then generate the equivalent ARM64 assembly code. As stated in lecture, the output of the ARM assembly code is a .s file that contains the original source code represented in its ARM assembly form. You are not required to complete the full ARM translation. For this milestone, we are looking for ARM translation for:

  • Global and local variable declarations for integers only

  • Integer binary expressions

  • Variable assignment updating

  • Printing of a single integer

Thus, you are not required to have any of the benchmarks working but rather programs that look like the following:

var a int;
func main () {
   var b int;
   a = 5;
   b = ((a + b) * 2) - 3;
   printf("%d\n%d\n",b,a);
}

We recommend that you complete as much of the ARM translation as possible; however, we are only looking for the above requirements.

You are only required to use a stack-based implementation.

Command-line Options Augmented

For this milestone, the must augment the compiler with the additional command line argument flags:

  • -llvm=[STRING]: Produces the LLVM IR form from the input source file. The filename must be the same as the original source filename but with the extension of .ll. The [STRING] argument is an optional argument that states the target triple string. For nowm the default target triple string must be "x86_64-linux-gnu".

  • -s: Produces the ARM64 form from the input source file. The filename must be the same as the original source filename but with the extension of .s.

Grading and What to Submit

The milestone is 6% of your grade and the exact weights for grading are:

  • 6% - 5% credit: Generation to LLVM IR is fully complete and ARM translation works for the above requirements with a few minor errors.

  • 4% credit: Generation to LLVM IR is fully complete with no ARM implementation.

  • 3-0% credit: No solution provided or none of the above requirements have been met.

Submission

Before submitting, make sure you’ve added, committed, and pushed all your code to GitHub. You must submit your final work through Gradescope (linked from our Canvas site) in the “Milestone #5” assignment page via two ways,

  1. Uploading from Github directly (recommended way): You can link your Github account to your Gradescope account and upload the correct repository based on the homework assignment. When you submit your homework, a pop window will appear. Click on “Github” and then “Connect to Github” to connect your Github account to Gradescope. Once you connect (you will only need to do this once), then you can select the repository you wish to upload and the branch (which should always be “main” or “master”) for this course.

  2. Uploading via a Zip file: You can also upload a zip file of the assignment directory.