Skip to content

caballeto/mcc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mcc

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.

Layout

  • examples/ contains sample example files and corresponding assembly generated by gcc
  • src/ contains all compiler source files
  • tests/ contains tests in form of a program and expected program output
  • LOG.md contains the working log on the project, describing some design decisions and general dev process

Install

Note that x86-64 Linux is the only supported platform for now.

git clone https://github.com/caballeto/mcc
cd mcc/
make
make install

Features

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.

Bugs & 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

Resources

  • github.com/DoctorWkt/acwj - a C compiler in C
  • https://www.cs.virginia.edu/~evans/cs216/guides/x86.html - x86 tutorial
  • Retargetable 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.

About

C compiler from scratch

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages