tinycc-mirror-repository: TinyCC: The One-Pass Miracle
How Fabrice Bellard turned the world's most formidable systems language into a 100KB scripting engine.
- TCC enables C to function as a scripting language by executing source files directly from the command line.
- The compiler uses a one-pass architecture that emits machine code instantly without building an intermediate syntax tree.
- Developers can embed TCC as a library to generate and execute C code dynamically within their own applications.
- The engine prioritizes compilation speed over binary optimization to achieve performance ten times faster than GCC.
C as a Scripting Language
C is a compiled language. You write, you build, you link, and eventually, you run. The Tiny C Compiler shatters this cycle.
#!/usr/local/bin/tcc -run
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
C script supported : just add '#!/usr/local/bin/tcc -run' at the first line of your C source, and execute it directly from the command line.
With a simple shebang, TCC executes C source files as if they were Python or bash scripts. There is no perceivable lag. The edit-compile-run loop becomes instantaneous.
The Streaming Compiler
Modern compilers like GCC and Clang are behemoths. They parse code into massive Abstract Syntax Trees, run dozens of optimization passes, and eventually emit assembly. TCC treats compilation as a streaming problem.
It uses a one-pass architecture. As the lexer reads tokens, the generator immediately emits machine code. There is no AST. There are no heavy intermediate representations.
Libtcc: The JIT in Your Pocket
TCC is not just a standalone executable. It is a library.
It's not just a tiny C compiler - it's a compiler you can use as a static library that can compile your C code directly to memory. And then you can call into it, if you dare.
Developers embed libtcc to give their C programs a Just-In-Time compiler. You can generate code strings dynamically, compile them into memory, and execute them on the fly.
The Efficiency Frontier
TCC does not optimize code. The resulting binaries execute slower than those produced by GCC with heavy optimization. But the compilation speed is unmatched.
Compiles and links about 10 times faster than 'gcc -O0'.
| Compiler | Architecture | Compilation Speed | Optimization |
|---|---|---|---|
| TCC | One-Pass, No AST | Extremely Fast (~10x GCC) | Minimal |
| GCC | Multi-Pass, Heavy AST | Baseline | Extensive (O1-O3) |
| Chibicc | Educational, Incremental | Moderate | None |
The Bootstrapping Anchor
Because of its tiny footprint, TCC is a favorite tool for bootstrapping systems from source. It can compile the Linux kernel in seconds.
TCC can of course compile itself.
This self-hosting capability makes it a crucial link in creating fully auditable software stacks. It proves that a complete, capable C compiler can fit inside a 100KB executable.