Unified · Split
| @@ -0,0 +1,40 @@ | |||
| 1 | # TinyCC (Tiny C Compiler) | ||
| 2 | |||
| 3 | ## Build & Test | ||
| 4 | |||
| 5 | ```sh | ||
| 6 | ./configure && make && make test | ||
| 7 | ``` | ||
| 8 | |||
| 9 | - `make` builds `tcc` + `libtcc.a` + `libtcc1.a`. `libtcc1.a` is built by a recursive `make -C lib`. | ||
| 10 | - `make test` runs the full test suite (`tests/`), ~2 minutes. | ||
| 11 | - Run a single tests2 test: `make tests2.37` (run) or `make tests2.37+` (update .expect). | ||
| 12 | - Run a single tests/pp test: `make testspp.17`. | ||
| 13 | - Sanitizer tests: `make sani-test`, `make sani-tests2.37`, `make sani-testspp.17`. | ||
| 14 | - Coverage tests: `make tcov-test`, `make tcov-tests2.37`, `make tcov-testspp.17`. | ||
| 15 | - Test installed tcc: `make test-install`. | ||
| 16 | |||
| 17 | ## Architecture | ||
| 18 | |||
| 19 | - **Single-file-ish compiler**: tcc compiles itself (or can be bootstrapped). `tcc.c` is the main entrypoint; `tccpp.c` handles preprocessing, `tccgen.c` handles code generation, `tccelf.c` handles ELF linking, `tccasm.c` handles inline asm, `tccrun.c` handles runtime execution, `tccdbg.c` handles debug info. | ||
| 20 | - **Backend files per architecture**: `i386-gen.c`, `x86_64-gen.c`, `arm-gen.c`, `arm64-gen.c`, `riscv64-gen.c`, `c67-gen.c`, plus corresponding asm/link files. | ||
| 21 | - **Generated file**: `include/tccdefs.h` is converted to `tccdefs_.h` by `c2str.exe` (built from `conftest.c`). Always exists after first `make`. | ||
| 22 | - **Cross-compilers**: `make cross` builds all cross-compilers; `make cross-i386`, `make cross-x86_64`, etc. for one target. `make CROSS_TARGET=i386 ONE_SOURCE=yes` for single-object cross build. | ||
| 23 | - **`ONE_SOURCE=yes`**: builds tcc as a single object file (default for cross-compilers, native uses separate objects). | ||
| 24 | |||
| 25 | ## Coding Style | ||
| 26 | |||
| 27 | - **C90** with these pre-existing non-C90 features: `long long`, `inline`, `//` comments, unnamed struct/union fields, empty macro arguments, assignment between function pointer and `void *`. | ||
| 28 | - **Indentation**: 4 spaces for most files; some files (e.g. `i386-gen.c`) use 2 spaces for deep nesting. | ||
| 29 | - **Do not reformat** existing code unless the change is the primary purpose. | ||
| 30 | - Remove tabs and trailing whitespace from modified lines. | ||
| 31 | - Check with `./configure --extra-cflags="-std=c90 -Wpedantic"`. | ||
| 32 | |||
| 33 | ## Test Quirks | ||
| 34 | |||
| 35 | - `test.ref` (reference output) is generated from `tcctest.c` using gcc: `(cd tests && gcc -I.. tcctest.c && valgrind -q ./a.out > test.ref)` then `make test TCC="valgrind -q --leak-check=full $(pwd)/tcc -B$(pwd) -I$(pwd)"`. | ||
| 36 | - VLA tests (`79_vla_continue`) produce expected invalid reads under Valgrind. | ||
| 37 | - tests2 skip list is in `tests/tests2/Makefile` (architecture- and config-specific skips). | ||
| 38 | - Some tests need special flags (see `FLAGS =` assignments in `tests/tests2/Makefile`). | ||
| 39 | - Bound-check tests (`-b` flag) are skipped when `CONFIG_bcheck=no`. | ||
| 40 | - `.expect` files are generated with gcc by default; some use TCC (flagged with `GEN-TCC`). | ||