sysprog21/shecc
FreeA self-hosting and educational C optimizing compiler
About sysprog21/shecc
shecc is a self-hosting and educational C optimizing compiler built from scratch, targeting both 32-bit Arm (ARMv7-A) and RISC-V (RV32IM) architectures. It generates executable Linux ELF binaries without requiring external assemblers or linkers, and includes a minimal C standard library for basic I/O. Written in portable ANSI C, shecc employs a two-pass compilation process: the first pass checks syntax and decomposes complex statements, while the second pass translates to machine code. It features an architecture-independent static single assignment (SSA)-based middle-end for optimizations and a register allocation system compatible with RISC-style architectures. The compiler supports a substantial subset of the C language, including data types (char, int, struct, enum, typedef, pointers), control flow (if, while, for, do-while, switch, etc.), all arithmetic/logical/bitwise operators with compound assignments, arrays (including multi-dimensional), functions (including variadic with pointer arithmetic), full pointer arithmetic, preprocessor directives (#define, #ifdef, #include, etc.), and function-like macros with VA_ARGS. shecc is verified on Raspberry Pi 3 (ARM) and via QEMU (RISC-V), and its bootstrapping process ensures the compiler can compile its own source code identically across stages.
Key Features
Pros & Cons
- Open source with a permissive license, hosted on GitHub
- Self-hosting capability demonstrates compiler correctness and completeness
- Educational value: well-structured codebase suitable for study and modification
- Supports two modern 32-bit architectures (ARM and RISC-V)
- Includes basic optimization techniques via SSA middle-end
- No dependencies on external assemblers or linkers for binary generation
- Minimal standard library reduces complexity while enabling real programs
- Active community and contributions from sysprog21 organization
- Only supports a subset of the C language (not fully standard-compliant)
- Targets only 32-bit architectures; no 64-bit or x86 support
- Minimal standard library may lack features needed for complex programs
- Bootstrapping requires QEMU or physical ARM/RISC-V hardware for full verification
- Not intended for production use; primarily educational and experimental
- Limited documentation beyond the README and repository files