Milestone #4: Front-End Completion

Due: Thursday July 27th at 11:59pm

This milestone will require you to complete the front-end of the compiler along with beginning the back-end generation with producing LLVM code.

Getting started

You will not be creating a new repository for every milestone. Continue to work out of the same repository as Milestone #2 for all remaining milestones and the final submission of the compiler.

Language Overview: GoLite

Please make sure you read over the document that describes the language we will be implementing this quarter: Language Overview

Milestone Requirement: Semantic Analysis

After constructing the AST, the final phase of the front-end must validate the AST to ensure that the program conforms to the static semantics of the language. Your validity checks must include those mentioned in the description of the Language Overview. The semantic analysis phase must report an error if an appropriate main function is not defined. You must check to ensure that if a function returns a type that all control-flow paths have a return statement. This will require a bit of bookkeeping that you will need to think about. For example,

//Standard Case
func foo (num int) int {
  return num;
}

//Control-flow case
func bar (num int) int {
   if (num == 0) {
     return 1;
   } else {
     if (num >= 1) {
       return 1;
     }else {
       return -1;
     }
   }
}

If any of these return statements are removed then an error should be thrown.

We will verify the correctness/completeness of this requirement by writing test-cases based on the Language semantics specified in the Language Overview document. We recommend you write a few test case for each bullet point specified in the Language Semantics section in the Language Overview document to ensure your semantic analysis implementation is working correctly.

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.

We will verify the correctness/completeness of this requirement by running the golite-benchmarks on the provided input and ensures it matches the expected output (also provided).

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

Command-line Options Augmented

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

  • -ast: Produces a print out of the AST generated by the compiler after parsing. We are not requiring a specific printing format. You are free to print the AST as you wish. However, you must define String() methods for each AST node to print out its representation as string.

  • -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".

Grading and What to Submit

You must provide the following to get full credit for this milestone:

  1. You must include additional test programs that would produce an error in the semantic analysis phase but not in the parsing phase. Place these in the benchmarks/sa directory in your repository.

  2. A README file that states how to read the printing of your -ast and -llvm command line options.

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

  • 6%-5% credit: Semantic Analysis is fully implemented and works correctly, and LLVM IR work has started.

  • 4% credit: Semantic Analysis is mostly completed but needs more work. LLVM IR has not been completed.

  • 3%-0% credit: Semantic Analysis is partially completed or No solution.

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 #4” 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.