Skip to content

A toy compiler project to experiment with compilers and computer architecture

License

Notifications You must be signed in to change notification settings

camilne/toy-compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

About

A toy compiler project to experiment with compilers and computer architecture

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages