A full C compiler, written in pure C. No 3rd party dependencies or parser generators
See the codeJCC is designed to be a pure C11 (no dependencies) C11/C18/C23 compiler.
No dependencies = no dependencies outside of libc and some basic OS calls needed to e.g read directories
| OS | AArch64 (Arm64) | x64 | RISC-V (32) |
|---|---|---|---|
| Ubuntu | |||
| macOS |
If tests are failing, ignore it! Development is very active (and pushes sometimes break things)
Aims:
No, it is text based
I just wanted to write a C compiler. It happens to be an easily buildable, easily runnable compiler that is still a grokkable size, It is probably too large to be considered a toy compiler, but the core architecture is much more accessible than the the shoggoth of Clang/GCC.
Compiler can fully bootstrap itself and passes the full C std test suite (which is not as large as it sounds).
AArch64, x64, and RISC-V 32 are supported, although some of the x64 ABI is not yet fully implemented and RISC-V 32 64 bit integers are WIP. Working with RISC-V requires installing a RISC-V linker.
va_arg outside of macOS arm64stdatomic.h)setjmp/longjmpnullptr_t, which I will get round to soon, static in compound literals, u8 strings, and the inbuilt attributes)git, curl, or wget for downloading sourcesjcc.sh commands to make for a more pleasant experience, but are not needed. These include bat (for syntax-highlighting), fd, and rgTo directly install jcc for playing around with (tested on macOS & various Linux distros):
curl -sSL https://jcc.johnk.dev/install.sh | sh
The above URL is just a direct fetch of ./scripts/install.sh which you can verify by visiting it. It is NOT a redirect, it forwards the content itself. If you prefer, you can directly curl the script from raw.githubusercontent.com/john-h-k/jcc/refs/heads/main/scripts/install.sh
wget can also be used, or you can clone the repository and run ./scripts/install.sh if you somehow have git but not curl or wget(???).
To install for development (which is realistically what you should do!):
bash and cmake installed./jcc.sh for helpThe jcc.sh script can be used for common workflows. A key subset of the commands can be seen here (run ./jcc.sh for all commands):
jcc.sh COMMAND
COMMANDS:
help Show help
run Build, then run JCC with provided arguments
debug Build, then run JCC under LLDB/GDB with provided arguments
test Run tests
test-all Run tests with all optimisation levels
format Format codebase
For the test script, run jcc.sh test help.
ir folderir/ir.h and ir/ir.cir/prettyprint.h and ir/prettyprint.c
ir/build.h and ir/build.cmem2reg)br.switchs are converted into a series of if-elses, and load.glb/store.glb operations are transformed to addr GLB + load.addr/store.addr% instr, so x = a % b is converted to c = a / b; x = a - (src/c * b)1,402 commits
C
97.1%
Shell
1.9%
A full C compiler, written in pure C. No 3rd party dependencies or parser generators
See the codeJCC is designed to be a pure C11 (no dependencies) C11/C18/C23 compiler.
No dependencies = no dependencies outside of libc and some basic OS calls needed to e.g read directories
| OS | AArch64 (Arm64) | x64 | RISC-V (32) |
|---|---|---|---|
| Ubuntu | |||
| macOS |
If tests are failing, ignore it! Development is very active (and pushes sometimes break things)
Aims:
No, it is text based
I just wanted to write a C compiler. It happens to be an easily buildable, easily runnable compiler that is still a grokkable size, It is probably too large to be considered a toy compiler, but the core architecture is much more accessible than the the shoggoth of Clang/GCC.
Compiler can fully bootstrap itself and passes the full C std test suite (which is not as large as it sounds).
AArch64, x64, and RISC-V 32 are supported, although some of the x64 ABI is not yet fully implemented and RISC-V 32 64 bit integers are WIP. Working with RISC-V requires installing a RISC-V linker.
va_arg outside of macOS arm64stdatomic.h)setjmp/longjmpnullptr_t, which I will get round to soon, static in compound literals, u8 strings, and the inbuilt attributes)git, curl, or wget for downloading sourcesjcc.sh commands to make for a more pleasant experience, but are not needed. These include bat (for syntax-highlighting), fd, and rgTo directly install jcc for playing around with (tested on macOS & various Linux distros):
curl -sSL https://jcc.johnk.dev/install.sh | sh
The above URL is just a direct fetch of ./scripts/install.sh which you can verify by visiting it. It is NOT a redirect, it forwards the content itself. If you prefer, you can directly curl the script from raw.githubusercontent.com/john-h-k/jcc/refs/heads/main/scripts/install.sh
wget can also be used, or you can clone the repository and run ./scripts/install.sh if you somehow have git but not curl or wget(???).
To install for development (which is realistically what you should do!):
bash and cmake installed./jcc.sh for helpThe jcc.sh script can be used for common workflows. A key subset of the commands can be seen here (run ./jcc.sh for all commands):
jcc.sh COMMAND
COMMANDS:
help Show help
run Build, then run JCC with provided arguments
debug Build, then run JCC under LLDB/GDB with provided arguments
test Run tests
test-all Run tests with all optimisation levels
format Format codebase
For the test script, run jcc.sh test help.
ir folderir/ir.h and ir/ir.cir/prettyprint.h and ir/prettyprint.c
ir/build.h and ir/build.cmem2reg)br.switchs are converted into a series of if-elses, and load.glb/store.glb operations are transformed to addr GLB + load.addr/store.addr% instr, so x = a % b is converted to c = a / b; x = a - (src/c * b)1,402 commits
C
97.1%
Shell
1.9%