Code Monkey home page Code Monkey logo

cci's Introduction

CCI: C11 Compiler Infrastructure

Build Status Codecov

โš ๏ธ This project is discontinued, and is getting rewritten in Rust at feroldi/atlas. The reason for that is that I don't feel like writing C++ code as a hobby anymore.

This is an experimental project of a C compiler written in C++20. The implementation follows the ISO/IEC 9899:2011 standard, i.e., C11. The main purpose of this project is to teach myself compiler data structures, language design and optimization techniques.

Building

Use cmake to build the project. The following sequence of commands builds the library, tools and unit tests:

mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build .

You may also specify a toolchain when generating build files by defining CMAKE_TOOLCHAIN_FILE to one of the supported toolchains in cmake/toolchains/. Both Clang and GCC are able to compile this project. So, for example, if you're going to build with GCC, you may specify the GCC toolchain like so:

mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/gcc.cmake
cmake --build .

The same goes for Clang. Just replace the gcc in -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/gcc.cmake with clang.

Usage

This is still a work in progress project. Usage is to be done.

Running tests

This project makes use of GoogleTest for unit tests, so you'll need to install it beforehand. After installing GoogleTest, go to the build/ directory we created, and run ctest. For example:

cd build
ctest --output-on-failure

If you're not going to run unit tests, it's possible to disable them by specifying BUILD_TESTING=NO at the build generation step like so:

mkdir build && cd build
cmake -DBUILD_TESTING=NO -DCMAKE_BUILD_TYPE=Release ..
cmake --build .

Compiler design

This document is an attempt to describe the API and project design.

Summary:

  • General
    • Meaning of "Infrastructure" in CCI
    • Project's directory structure

General

There are a few non-obvious choices and terminologies used in this project, so this section is intended to explain them.

Meaning of "Infrastructure" in CCI

CCI stands for C11 Compiler Infrastructure. That means this is not just a tool you can use to compile C code. CCI has an API, which you can use to manipulate C code. The goal is for it to allow you to scan code, generate and traverse a parse tree, generate an IR, produce an executable, write a back-end for it, and so on.

Project's directory structure

  • include/: Exposes the CCI's API you can use to write your own applications. There are functions for scanning, parsing, diagnosing, analysing, generating IRs etc.
  • lib/: This is where most of CCI's code base lives. APIs are implemented here.
  • src/: This is where some CCI tools live, where each directory is a separate project.
    • For example, the CCI compiler tool lives under src/cci/.
  • unittest/: Contains unit tests.
  • doc/: Documentation and manuals.
  • cmake/: Contains some modules used across the build system.

Almost all directories have a README.md file explaining their structure and purpose, what they do and solve etc.

Why C11?

C11 is a great, challenging language to make a compiler for. It's also true that one can learn a lot by writing a compiler. That being so, C11 seems to be an option that gets the most out of the experience.

License

This project is licensed under the MIT license. See LICENSE.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.