This is a fork of Rui Ueyama's chibicc with fixes and improvements, including:
_Static_assert()
, over-aligned locals, _Generic
with qualifiers.constexpr
, #embed
, auto
type-inferrence, etc.defer
(as _Defer
), __VA_TAIL__
cleanup
If you're just looking for "chibicc-with-only-fixes-to-build-stuff" checkout widcc.
bash
; depending on the distro, file
and/or glibc-static
packages may be required.
git clone --depth 1 https://github.com/fuhsnn/slimcc
cd slimcc
make test-stage2 -j
Run it in base directory like CC=~/slimcc/slimcc
.
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.
csmith
?1M tests were run with --no-packed-struct
flag, all issues found were fixed.
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
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.