TMCC (Trying to Make C Compiler) should be a minimalistic C compiler written for educational purposes. Initial goal of the project is to be able to compile the compiler itself.
The aim is to significantly boost my skills in C programming, compiler design and understanding, assembly and formal standard comprehension.
Constraints and Requirements
- Compiler should fully follow one of C standards, probably ANSI C and provide fully-working standard library.
- Target platform is x86-64 Linux with theoretical support for other platforms in the future. My development platform is Mac OS, so I will run it in QEMU or just in a VM.
- Compiler should produce NASM assembly code, which is then assembled and linked using NASM.
- Ideal goal - self-hosting compiler.
- No LLVM! LLVM is great, but what's the fun then if all the backend will be done by it?
Base compiler parts:
- Tokenizer
- Base parser / AST
- Semantic analyzer
- Code generator
- Assembler / linker stage
- Simple AST optimizer
- Standard library implementation
- Command-line flags
- Preprocessor
- Self-hosting compiler
- Primitive register allocation
- Arena based allocation of AST nodes, types and symbols
Language features:
- Primitive types (int, char, float, double)
- Arithmetic binary operators (+, -, *, /)
- Bitwise binary operators (&, |, ^, <<, >>)
- Logical binary operators (&&, ||)
- Unary operators (+, -, !, ~)
- Comparison operators (==, !=, <, >, <=, >=)
- Variable declarations
- Variable initializations
- Pointers
- Arrays
- Structs
- Unions
- Enums
- Functions declarations
- if / else
- while
- for
- do / while
- switch / case
- goto / labels
- break / continue
- return
- sizeof
- Type qualifiers (const, volatile, restrict)
- Storage class specifiers (static, extern)
- Global variables
- Custom typedefs
- Dereference and address-of operators (*, &)
- Function pointers
- Variadic arguments
- Preprocessor directives (#include, #define, #ifdef, #endif)
- Comments
- Support for multiple source files
- Support for header files
- Attributes (__attribute__((...)))