Compiler · C++

ExecEngine

A C90 to RISC-V compiler, built from the lexer up.

ExecEngine compiler
Sample of the compiler source code Test suite output
2ndin the cohort on hidden tests
80%of seen and unseen tests passed
2engineers, with Sohailul Alvi

The problem

Imperial's second-year compilers coursework asks for a compiler that turns ANSI C (C90) into working RISC-V assembly. It's graded against a hidden test suite covering functions, data types, pointers and structs.

What we built

  • A lexer and parser that produce an abstract syntax tree for C90.
  • Code generation from the AST straight to RISC-V assembly.
  • Register allocation, stack-frame management and memory layout for locals, arrays, pointers and structs.

Result

Our compiler passed 80% of all seen and unseen tests, ranking second in the cohort. According to the course TA, we were the only team to pass every seen test case.

The repository also works as a practical introduction to compiler design if you're learning the topic. Questions and suggestions are welcome.