fruits-lab / vitaminc

A simple C compiler. 🍋

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

VitaminC

CI

VitaminC 🍋 is an educational C compiler frontend written in C++. As a frontend, it generates intermediate representations (IR). The compilation phases—lexer, parser, type checker, and IR generator—are carefully designed as individual classes.

Features

Warning

This project is still under development. Many features are not yet implemented. Currently, we do not support preprocessor directives, and only the int type and its pointer, as well as object types, are supported.

The main goal of this project is to demonstrate how a compiler frontend works with the LLVM compiler infrastructure and generates LLVM IR. However, we are not yet there. Currently, we generate QBE IR manually.

We are not aiming to be a fully compliant C compiler, although we strive to be as compliant as possible with C89 and support common C99 features.

Prerequisites

  • A C++ compiler that supports C++17.
  • GNU Make: for building the project.
  • QBE: for compiling the QBE IR down to assembly.
  • cxxopts: for command-line argument parsing.
  • fmt: for modern C++ formatting.
  • (test-only) turnt: for snapshot testing.

Note

We provide installation scripts under the scripts/ directory to install some of the prerequisites. You can run the corresponding script to install the prerequisites or to see what versions we are using.

Build

To build the project, run the following command:

make

This will generate an executable named vitaminc.

If you have turnt installed, you can run the tests with:

make test

Usage

$ ./vitaminc --help
A simple C compiler.
Usage:
  ./vitaminc [options] file

  -o, --output <file>  Write output to <file> (default: a.out)
  -d, --dump           Dump the abstract syntax tree
  -t, --target [qbe]   Specify target IR (default: qbe)
  -h, --help           Display available options

License

This project is licensed under the MIT License.

About

A simple C compiler. 🍋

License:MIT License


Languages

Language:C++ 71.6%Language:Yacc 15.8%Language:C 8.2%Language:Lex 2.0%Language:Makefile 1.6%Language:Shell 0.7%