UP | HOME

Code Generation III (codegen3) Project
COP-3402

Table of Contents

1. Overview

In this project you will compile arithmetic and branching statements.

2. Preparing and submitting your project

2.1. git setup

Be sure to complete the git exercise before attempting this project.

Create a new local repository, following the directions in the git exercise (including the git --set-upstream last step) and set the local and remote repository URLs to be the following locations:

Local repository ~/cop3402spring25/codegen3
Remote repository gitolite3@eustis3.eecs.ucf.edu:cop3402/$USER/codegen3

Commands to setup your repo

These steps only setup the repo, do not submit your code, and assume you have already completed the git exercise. Consult that exercise for specifics on validating each step and submitting your code.

mkdir -p ~/cop3402spring25/codegen3
cd ~/cop3402spring25/codegen3
git init
echo "codegen3 project" > README.md
git add README.md
git commit README.md
# Enter a commit message in the editor that pops up
git remote add submission gitolite3@eustis3.eecs.ucf.edu:cop3402/$USER/codegen3
git push --set-upstream submission master

2.2. Downloading the project template

Download and untar the project template. The template has only been created and tested for use on eustis. You will create a new git repo and start it with a fresh copy of template for each separate codegen project.

cd ~/cop3402spring25/codegen3
wget https://www.cs.ucf.edu/~gazzillo/teaching/cop3402spring25/files/compiler-project.tar
tar -xvf compiler-project.tar
mv CodeGen.template.cpp CodeGen.cpp

Be sure that you include all files from the project template in your repo.

2.3. Building your project

The following will build your compiler (tested on eustis):

cd ~/cop3402spring25/codegen3
make

The result is a program called CodeGen.

Included are also a number of files prefixed with SimpleIR which includes the grammar (SimpleIR.g4) and generated parser files.

Again, be sure that you include all files from the project template in your repo so that it builds with make.

You can make a fresh clone of your repo to test that it builds properly.

You can sanity check your empty CodeGen template by giving it a SimpleIR program, e.g.,

./CodeGen << EOT
function main
return 0
end function
EOT

You should see no output or errors.

2.4. Adding required project files

Add, commit, and push CodeGen.cpp along with all other files included in the project template. Don't forget to commit and push changes to CodeGen.cpp as you complete the project.

Here is a quick way to add all the required files:

git add CodeGen.cpp $(tar -tf compiler-project.tar | grep -v 'CodeGen.template.cpp')

Be sure to commit and push them as well.

2.5. Self-check

See the hello project for instructions on cloning a project from the grading server.

In brief, you can sanity check your repo on the grading server with the following:

git clone gitolite3@eustis3.eecs.ucf.edu:cop3402/$USER/codegen3 ~/tmp/codegen3_selfcheck
cd ~/tmp/codegen3_selfcheck
make
./CodeGen << EOT
function main
return 0
end function
EOT

If any of these steps fail, then your project is likely not submitted correctly and will fail grading. Keep in mind that while necessary, passing the above steps is not sufficient for demonstrating a correctly-working compiler. See the descriptions of the test cases and grading criteria below for more information.

3. Project requirements

See the Code Generation Project Handbook for implementation details and examples.

In this project, you will be implementing the following listener methods for your compiler. These correspond to the constructs that generate function definitions and calls as well as listeners given to you to enable having a complete, testable assembly program.

Listener Instructions
enterUnit Given to you
enterLocalVariables Given to you
enterAssign Given to you
enterFunction Hard-coded
enterEnd Hard-coded
enterParameters Hard-coded
enterReturnStatement Hard-coded
enterCall Hard-coded
enterDereference Implement on your own
enterReference Implement on your own
enterAssignDereference Implement on your own

4. Grading

The test cases used to grade the project are listed below. Scripts to run the the odd-numbered test cases are provided publicly, while the even-numbered test cases are private.

To use the automated tests, first download them, e.g.,

cd ~/cop3402spring25/codegen3
wget https://www.cs.ucf.edu/~gazzillo/teaching/cop3402spring25/files/codegen3_public_tests.tar -O codegen3_public_tests.tar
tar -xvf codegen3_public_tests.tar

To run a test case, e.g., tests/01.sh, use the following bash command from the root of your local repository directory:

bash codegen3-tests/01.sh $(realpath CodeGen)
echo $?

This runs the bash script, passing in the absolute path to your program, which is what realpath finds for you. The result of echo $? should be 0 which indicates the test was succesful.

To see what commands the test case is running exactly, use bash -x instead of just bash:

bash -x codegen3-tests/01.sh $(realpath CodeGen)
echo $?

Here is a bash for-loop that goes through all tests:

for i in codegen3-tests/*.sh; do  # loop over all test scripts
  bash $i $(realpath CodeGen)  # run the test
  echo $?  # emit the exit code
  echo ""  # give some extra space
done  # end the loop

4.1. Test cases

All test cases use this SimpleIR template. Be sure to follow the project requirements to hard-code the function-related listeners for this template.

function main # DO NOT CHANGE
localVariables a b c d e f g result retval # DO NOT CHANGE
# add your code to try out here
retval := call print_int result # DO NOT CHANGE
return 0 # DO NOT CHANGE
end function # DO NOT CHANGE
# Short Name Description
1 ref-correct-address Use gdb to check that address of a is 16 bytes away from rbp
2 ref-not-zero Check that the reference address is not 0
3 ref-deref Take a reference and print via deref
4 ref-deref-change Take a reference and change the referenced variable
5 ref-deref-copy Take a reference and copy its value via the ref
6 ref-assignderef Take a reference and do a deref assignment
7 ref-deref-assignderef Do all three pointer operations

5. Grading schema

Criterion Points
The git repo exists 1
The program is written, builds, and runs as described here 1
Tests pass, prorated by the number of test cases passing 6
TOTAL 8

Author: Paul Gazzillo

Created: 2025-04-21 Mon 07:20

Validate