Published 09/2025
Updated 10/2025

C Compiler

# Building a Cross-Platform C Compiler: A Journey with Hexanôme 4221 Over the past few months, I had the chance to be part of something truly exciting. Alongside seven brilliant teammates, I helped de

Developer
02/2025 — 04/2025
C Compiler

Over the past few months, I had the chance to be part of something truly exciting. Alongside seven brilliant teammates, I helped develop a C compiler from scratch—something I never imagined doing when I first dipped my toes into programming. This project was part of the Compiler Design (PLD-COMP) course at INSA, and it turned out to be one of the most rewarding technical experiences I've had so far.

Together with seven fellow students at INSA, we formed Hexanôme 4221, and together, we pulled it off.

What We Built

Our compiler, nicknamed ifcc, takes simplified C source code and translates it into assembly code targeting both x86-64 and ARM64 architectures. In other words, the same .c file can be compiled into working machine code for both Windows and macOS (Apple Silicon).

We didn’t try to support the entire C language. Instead, we focused on building a solid and extensible foundation, with support for:

  • Basic types: int, float, char, void
  • Arithmetic and logical operations
  • Variable declarations and scoping
  • Functions and control structures (if, while, for)
  • Arrays, strings (char[]), and even preliminary support for struct

Compiler Architecture

Our workflow followed the classic compiler pipeline, but seeing it come to life was still fascinating:

  1. Lexing & Parsing – We used ANTLR4 with a custom grammar to generate an Abstract Syntax Tree (AST).
  2. Intermediate Representation (IR) – The AST is processed by our CodeGenVisitor to produce a high-level IR.
  3. Code Generation – Finally, the IR is translated into architecture-specific assembly using dedicated modules for x86-64 and ARM64.

What’s especially exciting is how cleanly we structured the architecture—each layer is modular, reusable, and easy to extend. Want to add support for a new target like RISC-V? Totally doable.

Tools We Used

To build ifcc, we relied on a few key tools:

  • C++: The primary language used for compiler development, providing the performance and flexibility needed for low-level operations.
  • ANTLR4: A powerful parser generator for creating the grammar and parsing source code into an Abstract Syntax Tree (AST).
  • Git: Used for version control, enabling collaboration, tracking changes, and managing our source code efficiently.

Testing

Testing was a key part of our development process. We created a Python script that automatically compares the behavior of compiled code from our compiler with the output of GCC. If both executables behave identically, the test passes. Simple—but incredibly effective.

We also implemented both unit tests and functional tests throughout development.

How We Worked Together

This project was also a crash course in Agile development, with a light touch of Scrum. We divided the compiler into logical modules and distributed tasks based on individual strengths and interests. Here's a snapshot of the team structure:

  • Team 1: Language basics, IR generation, block management, arithmetic
  • Team 2: Unary/bitwise operations, arrays, logical expressions
  • Team 3: Type checking, global variables, floating-point support, constant folding, multi-platform targeting

Each work session, we’d gather to discuss any blockers or bugs, brainstorm solutions as a team, and move forward once we had consensus. If we couldn’t resolve an issue internally, we weren't afraid to reach out to our teacher for guidance.

What I Took Away

This project wasn’t just about building a compiler—it was about understanding how compilers think, analyze, and generate. From syntax trees and type systems to memory alignment and register allocation, every step revealed something new and challenging.

But above all, what made this project unforgettable was the team. We learned, failed, debugged, and iterated—until we shipped something we’re truly proud of.


Thanks for reading! If you’re curious about how specific parts of the compiler work, or you’re thinking of building your own, feel free to reach out. I’d love to talk compilers.