badc (performance)

CI Release crates.io License: MIT OS Arch

If you wish to make an apple pie from scratch, you must first invent the universe.

– Carl Sagan, Cosmos (1980), p. 218

badc is a slim cross-platform optimizing C17 compiler. There is extensive support for the older standards and good support for the newer ones, as well as support for the numerous GNU C, Clang, and MSVC extensions that real-world software requires.

From any host, badc builds native images for five targets: macOS on ARM64, Linux on ARM64 and x86-64, and Windows on ARM64 and x86-64. It has its own preprocessor, assembler, linker, archiver, and debug-info writers (DWARF and PDB), as well as an in-process JIT and an SSA interpreter. CI runs more than 80 jobs and more than 5,000 tests on every pull request and every push to master, and fuzzing jobs run daily.

badc ships as a single binary. The project can also be used as a Rust library.

Contents

Demos

demos/ builds each project below with badc and runs it as a smoke test. demos/README.md says what each one exercises.

Lineage

badc started as a Rust port of Robert Swierczek’s c4, a C compiler in four functions that accepts only a subset of C. The dialect diverged enough to get its own name, c5, hence the c5 module and the C5Error type. It has since moved from a stack IR through a three-operand IR to SSA with an optimizing backend.

The venerable c4 runs itself. Here is how to run the hello program under c4, under c4, under c4 compiled by badc’s JIT:

badc -O --jit tests/fixtures/c/c4.c tests/fixtures/c/c4.c tests/fixtures/c/c4.c \
    tests/fixtures/c/c4_selfhost_hello.c
Hello 123
exit(0) cycle = 11
exit(0) cycle = 37229
exit(0) cycle = 11152710

Documentation

Disclaimer

This is a personal educational and research project. Nobody sponsored or suggested it. I am not responsible for how you use it or for what follows from that use. See LICENSE for the exact terms.

^ To the top