Go to file
Keyvan Kambakhsh ee9891518a fix: Fix switch.c warns 2024-12-09 00:57:40 +03:30
.github/workflows Setup nasm in workflow 2024-11-25 22:51:47 +03:30
codegen feat: 30cc can now compile itself 2024-12-03 14:08:15 +03:30
examples test: Testcases should all return 0 2024-12-08 02:37:45 +03:30
parser fix: Fix switch.c warns 2024-12-09 00:57:40 +03:30
preprocess fix: Fix some 30cc self-compile errors 2024-12-03 12:44:23 +03:30
scripts test: Add inp_vararg.c test 2024-12-08 02:39:17 +03:30
tests/output fix: Fix asm block debug func 2024-12-08 02:41:10 +03:30
.gitignore feat: Use Makefile instead of python build script 2024-12-07 03:04:35 +03:30
Makefile test: Update run outputs on examples 2024-12-08 02:28:44 +03:30
README.md Update README.md 2024-12-07 03:10:06 +03:30
lexer.c fix: Escape tab chars 2024-12-03 23:34:37 +03:30
lexer.h fix: Fix continue; statement bug 2024-12-03 23:11:30 +03:30
libc.h feat: Put all of the external functions in a single header file (#64) 2024-12-03 12:11:37 +03:30
linked_list.c feat: Put all of the external functions in a single header file (#64) 2024-12-03 12:11:37 +03:30
linked_list.h Remove node_param and embed name in types 2024-11-01 21:43:26 +03:30
main.c feat: Report if compiler is compiled with 30cc 2024-12-03 14:43:28 +03:30
vec.c feat: Put all of the external functions in a single header file (#64) 2024-12-03 12:11:37 +03:30
vec.h feat: Put all of the external functions in a single header file (#64) 2024-12-03 12:11:37 +03:30

README.md

30 C Compiler!

30cc (Pronounced as CCC, because in the Persian language, the number 30 is pronounced as C) is a toy C compiler written in C, which is strong enough to compile itself 🤝 This was my first attempt in writing a self-hosting software! What is a self-hosting software?

  • Imagine 30cc gets strong enough to be able to compile itself.
  • I will first compile 30cc with gcc to get the 30cc compiler's binary.
  • I will then use the gcc-generated 30cc binary file to compile the 30cc again.
  • I now have a 30cc-compiled version of 30cc, which I can use for further developing the compiler!
  • I can forget about gcc, as if it never existed! Beautiful hah? 30cc is now all alive by itself!

30cc emits x86-64 assembly as its output. The outputs are totally unoptimized, but that's fine, the project aims to be educational.

Usage

Bootstrap the compiler by running make. This will generate 3 different versions of 30cc compiler:

  1. 30cc_gcc which is the bootstrapped gcc-compiled version of 30cc
  2. 30cc_30cc which is the output of gcc-compiled 30cc compiler, compiling the 30cc compiler
  3. 30cc which is the output of 30cc-compiled 30cc compiler, compiling the 30cc compiler

Running independent source-files through make:

make run program=./examples/inp.c arguments=something

Contribute

Tests

To run tests use

python scripts/test.py update

Then check the output of the tests.

If you are on mac use ./scripts/test_mac.sh to run the tests in docker.