badc (performance)badc is a cross-platform optimizing C compiler, also usable as a Rust
library. From any host it builds native executables, shared libraries and
objects 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 DWARF writer, an in-process JIT and an SSA interpreter. CI runs
over 80 jobs and over 5,000 tests on every pull request and every push to
master, and fuzzing jobs run daily.
badcwas bad when the project started, and the name stuck.--dump-ssaprints each function’s SSA IR and the register allocator’s placement of each value to stderr before lowering.
demos/ builds each project below with badc and runs it as a
smoke test. demos/README.md says what each one
exercises.
qemu-system-aarch64 and
qemu-system-x86_64 boot Linux through UEFI firmware to a shell under TCG.#pragma subsystem selects its PE subsystem.make test.-O0, badc -O and the host
compiler.IMAGE_SUBSYSTEM_NATIVE program that runs on ntdll alone; and
nt_loader, which starts one through
NtCreateUserProcess.badc started as a Rust port of Robert Swierczek’s
c4, a C compiler in four functions. 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.
c4.c is a test fixture, and badc compiles it:
badc -O -o c4 tests/fixtures/c/c4.c # compile c4 to a native binary
./c4 tests/fixtures/c/c4_selfhost_hello.c # c4 compiles and runs a program
c4 also runs itself. This runs 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
c4 accepts a subset of C. For example, it rejects a local declaration with an initializer.
badc can do: a short survey of the
features.#pragma build flags,
the JIT, optimizations.-W options and pragmas that select them.--interp and --jit: running C without writing
an image, and the interpreter’s pointer checks.no_std: using badc from Rust.tools/ and scripts/.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.