Julien's C Compiler
Implementation of the C compiler outlined in Writing a C Compiler by Nora Sandler
./jcc [-S][-h | --help][--lex | --parser | --tacky | --codegen] path/to/code.cLogic is separated by language in separate folders. Tacky folder only defines structure and will eventually expose optimization logic.
./src/cprocesses raw text into a C AST and emits a TACKY AST./src/tackyonly defines the AST, does not currently expose logic./src/asmturns TACKY AST into an ASM AST and emits code from an ASM AST./src/corecontains the lexer & parser engine used by the source language
Two commands cover testing for the compiler. Both are run in CI.
cargo test # runs unit & end-to-end defined in this repository
./run-tests.sh # runs author-defined test./testscontains end-to-end tests running the cli against fixtures- will be removed in favour of
run-tests.sh
- will be removed in favour of
- unit tests defined directly in the files
./run-tests.shruns the end-to-end tests defined by the book's author- testing script is defined in submodule
writing-a-c-compiler-tests
- testing script is defined in submodule
The book's test suite targets x86-64. Codegen emits macOS-specific assembly on
macOS (underscore-prefixed symbols, no .note.GNU-stack) and Linux assembly
elsewhere, so the same source builds unchanged in CI on both platforms.
On an Intel Mac, ./run-tests.sh works out of the box. On Apple
Silicon, the default toolchain targets arm64, so force x86-64 output (which
runs under Rosetta) with the helper wrapper:
PATH="$PWD/scripts/x86_64-gcc:$PATH" ./run-tests.sh