This repository contains my implementation of a compiler for a subset of C language. The compiler is written in C++, it accepts C files and generates X86-64 assembly output.
examples/
contains sample example files and corresponding assembly generated by gccsrc/
contains all compiler source filestests/
contains tests in form of a program and expected program outputLOG.md
contains the working log on the project, describing some design decisions and general dev process
Note that x86-64 Linux is the only supported platform for now.
git clone https://github.com/caballeto/mcc
cd mcc/
make
make install
The compiler functionality is mainly finished, at least the part I was aiming at. It supports operators, function calls, register spilling, struct, union, enum, typedef, pointers, pointer arithmetic, arrays, and more.
These are some bugs I intend to fix, once I will have some time for that.
- call inside arguments reassigns
%rdi
(param) registers - implement better conditional expression generation
- rewrite register allocation algorithm
- would be good to extend fully integer types (signed/unsigned/long long int, etc.) and be able to use gcc headers
github.com/DoctorWkt/acwj
- a C compiler in Chttps://www.cs.virginia.edu/~evans/cs216/guides/x86.html
- x86 tutorialRetargetable C compiler
- implementation of a small production C compiler (lcc
)
Ideas and some parts of the code have been taken from Tommy Warren's github.com/DoctorWkt/acwj
.