Skip to content
JLambertazzoPublic

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

JCC

Julien's C Compiler

Implementation of the C compiler outlined in Writing a C Compiler by Nora Sandler

Usage

./jcc [-S][-h | --help][--lex | --parser | --tacky | --codegen] path/to/code.c

Project Structure

Logic is separated by language in separate folders. Tacky folder only defines structure and will eventually expose optimization logic.

  • ./src/c processes raw text into a C AST and emits a TACKY AST
  • ./src/tacky only defines the AST, does not currently expose logic
  • ./src/asm turns TACKY AST into an ASM AST and emits code from an ASM AST
  • ./src/core contains the lexer & parser engine used by the source language

Testing Structure

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
  • ./tests contains end-to-end tests running the cli against fixtures
    • will be removed in favour of run-tests.sh
  • unit tests defined directly in the files
  • ./run-tests.sh runs the end-to-end tests defined by the book's author
    • testing script is defined in submodule writing-a-c-compiler-tests

Running on macOS

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

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages