Josh Hirschkorn
--:--:--
All projects

Dec 2025 · Mar 2026

High-Performance C90 Compiler

A full C90 front-to-back in C++, emitting optimised RISC-V.

  • C++
  • RISC-V
  • CMake
  • Docker
  • GitHub Actions
Repository
Lines of C++
30k+
Programs tested
300+
CI pass rate
100%

A complete C90 compiler written from scratch in C++, over 30,000 lines, taking source text all the way to RISC-V assembly.

Front end

The front end implements lexing, parsing, AST construction and full semantic analysis with type checking. The AST is polymorphic, using RAII smart pointers for ownership, std::variant for type representation, template dispatch where the shape is known at compile time, and dynamic_cast-based dispatch in code generation where it is not.

Choosing where to use static versus dynamic dispatch is most of the design work in a compiler this size: too much templating makes the tree unusable, too much virtual dispatch makes it slow and hard to extend.

Optimisation and code generation

On top of the validated AST I implemented an optimisation pipeline of constant folding, dead code elimination and branch resolution before emitting RISC-V. These passes interact: folding exposes dead branches, and resolving branches exposes more dead code, so ordering matters.

Testing

Correctness in a compiler is only meaningful if it is continuously demonstrated. I validated the compiler with a Dockerised CMake and Python testbench across more than 300 C programs, wired into a GitHub Action that runs on every push, holding a 100% pass rate. Docker matters here because a compiler that only works on one machine’s toolchain has not really been tested.