This software, written in C++, serves two functions:
- It can compile an input C90 (ANSI) program to MIPS1 assembly
- It can also translate this program to the Python3 equivalent.
It conforms to this spec. All specified features are covered.
Also included are bash scripts to run the compiler against sets of test programs for both functionalities (these test cases are also included).
The compiler is intended to run on a Linux OS e.g. Ubuntu.
-
First build:
make bin/c_compiler
Build will take a little bit of time. -
Then you may compile:
bin/c_compiler -S filename.c -o output_file.s
-
Or translate:
bin/c_compiler --translate filename.c -o output_file.py
-
To output translation to terminal window instead of to a file, use '-k' flag instead of '-o' and do not put a file name after the flag e.g.
bin/c_compiler -S filename.c -k
-
Finally, to test the compiler, run the bash script:
./compiler_test.sh
-
And to test translator:
./c_translator_formative.sh
This project was done as part of a college assessment in a group of 2 - co-authored with Shafir360. It conforms to this spec, but the implementation is original work of the authors.
Around 80% of the test cases are provided by John Wickerson, and were of great help in compiler verification. The authors added more complicated tests on top of these.
We are very grateful to johnwickerson, m8pple, ymerklotz and tobhil98 for their guidance in building the compiler, which we did our best to follow.