fuhsnn / slimcc

C11 compiler with GNU extensions for x86-64 Linux, working towards C23
MIT License
54 stars 10 forks source link
c c-compiler c23 chibicc compiler

This is a fork of Rui Ueyama's chibicc with fixes and improvements, including:

If you're just looking for "chibicc-with-only-fixes-to-build-stuff" checkout widcc.

Project goal

Building & Running

What can it build?

slimcc should be able to compile most C89 to C11 projects not entagled with compiler-specific or optional features.

Real world projects including Curl, Git, PHP, Perl, Python, PostgreSQL, SQLite, Vim are successfully built and regularly tested with.

Check out widcc's list for detailed build scripts.

Can it pass csmith?

1M tests were run with --no-packed-struct flag, all issues found were fixed.

How optimized are the generated binaries?

The codegen strategy is matching AST nodes to hard-coded assembly snippets and glue them with data movements.

Some optimizations can be made with this by pattern-matching to smarter alternatives, I apply them when effective and don't mess up readability.

Compare size of chibicc binary built with several compilers:

      text       data        bss      total filename
    101611      27677        616     129904 gcc_O0_build
    109243      26622        544     136409 clang_O0_build
    124667      31913        448     157028 slimcc_build
    144896      29536        440     174872 tcc_build
    263659      41163        456     305278 chibicc_build
*gcc/clang with -O0 -fno-stack-protector -fno-asynchronous-unwind-tables -fno-pic -no-pie

Porting

musl linux and BSDs should be doable. Check hard-coded paths in main.c, and pre-defined macros in preprocessor.c.

The widcc branch is a less noisy codebase than slimcc that should be more appealing for developers to hack on.