Skip to content

Latest commit

 

History

History
61 lines (41 loc) · 2.48 KB

README.md

File metadata and controls

61 lines (41 loc) · 2.48 KB

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. Currently, this compiler can generate QBE IR and LLVM IR.

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 QBE IR to assembly.
  • LLVM-18: for generating LLVM IR and compiling it 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|llvm]  Specify target IR (default: qbe)
  -h, --help               Display available options

License

This project is licensed under the MIT License.