Compiler design and implementation in OCaml with LLVM framework
Nguyen, Anh (2019)
Nguyen, Anh
2019
Julkaisun pysyvä osoite on
https://urn.fi/URN:NBN:fi:amk-201904084600
https://urn.fi/URN:NBN:fi:amk-201904084600
Tiivistelmä
The past several decades constantly witnessed the noticeable growth in the quantity as well as the performance of compilers for high-level programming languages due to the high demand for increasingly intricate computer programs. The objective of this thesis is to explore the feasibility of adopting Low Level Virtual Machine (LLVM) framework which is a set of well-optimised, reusable tools for constructing modern compilers. Specifically, the thesis focuses on employing LLVM framework as the Intermediate Representation (IR) code generator and as the back-end compiler infrastructure to rapidly construct compilers. Along the way, this thesis depicts the fundamental structure of a modern compiler as well as the techniques to apply compiler theoretical concepts into practice. In order to achieve the goal of demonstrating those concepts, practices and the effectiveness of LLVM framework, the thesis project was to design and implement a compiler for a simple, imperative programming language known as Tiger. During the process of developing this compiler, several commonly used libraries for building compiler including Lex, Yacc were leveraged to solve domain specific problems. The final outcome of the project is a compiler written in a strongly-typed, general purpose, functional programming language known as Objective Categorical Abstract Machine Language (OCaml). This compiler can translate the Tiger programming language to LLVM IR and subsequently to any architecture-dependent native code supported by LLVM. As a result, the project analyses and emphasizes the robustness and effectiveness of LLVM framework in the process of constructing compilers. Additionally, the operational compiler serves as concrete examples as well as proofs for the correctness of the theories and skills discussed in this thesis.