Building a C-like Compiler and VHDL Microprocessor
As part of my coursework in Automatas & Languages and Hardware Architecture at INSA Toulouse, I embarked on an exciting project to develop a complete system that includes a compiler for a simplified C-like language and a microprocessor designed in VHDL to execute the generated machine code.
Project Overview
The project is divided into two main components:
1. Compiler
The compiler component includes both lexical and syntax analysis:
Lexical Analysis
Implemented using Flex, the lexical analyzer scans the source code to identify specific tokens such as arithmetic operators, keywords (like if
and while
), numbers, comments and brackets.
In short it breaks the source code into tokens that are then passed to the syntax analyzer for further processing.
Syntax Analysis
Utilizing Bison, the syntax analyzer processes the tokens generated by the lexical analyzer. It checks the structure of the source code against defined grammar rules, ensuring the syntactic correctness of the code. The syntax analyzer then translates the source code into corresponding assembly code, preparing it for execution by the microprocessor.
2. VHDL Microprocessor
The microprocessor, designed using VHDL, follows a RISC architecture with a 5-stage pipeline. This architecture supports essential operations such as addition, subtraction, multiplication, and data transfer. The pipeline design optimizes performance by allowing multiple instructions to be processed simultaneously at different stages. Additionally we implemented a hazard detection mechanisms to manage data, control, and structural conflicts.
View on GitHub