Awesome
miniC->MIPS Compiler Project
This is a toy compiler that I am working on. It is written in C++. It uses the following libraries:
- flex (lexer)
- bison (parser)
- CMake (build system)
- Catch2 (unit testing)
The goal of this project is to turn a toy C-like language (miniC) into MIPS32 assembly. The output will then be assembled (with an assembler written by me) into machine code. This machine code can then run on a virtual machine (also created by me). It is an exercise with compilers and computer architecture.
Compilation
To build the project, run the following command from the root directory:
mkdir build && cd build && cmake .. && make
This will generate an executable called compiler which accepts a program as an argument and outputs the compiled code to an assembly file (default is a.asm
).
The compiler currently supports a few command line options:
Flag | Name | Argument(s) | Description |
---|---|---|---|
<none> | [files] | specifies input files (max of one supported at the moment) | |
-v | verbose | <none> | enables comments to be generated in the output file |
-o | output | <file> | specifies an output file |
Testing
To generate tests, run the following command from inside the build directory:
cmake .. -Dtests=ON && make
Then, run the generated compiler_tests executable to run unit tests.
Documentation
You can generate documentation by running doxygen Doxyfile
from the root directory. This will generate a docs folder with the documentation inside.
Structure
The compiler is split up into several folders (generated folders are starred).
folder | content |
---|---|
docs* | documentation generated by doxygen |
examples | example miniC code |
include | hpp, ih |
lang | language specification for flex/bison |
src | cpp |
test | tests |
:octocat: