Compiling a Functional Language to LLVM IR using Trieste
Widén, Richard · Uppsala University Publications (Uppsala University) · 2025
Creating a compiler is a necessary step in the development of a new programming language. Trieste is a domain-specific language capable of efficient transformations of abstract syntax trees, designed for programming language development. This thesis explores Trieste's suitability for development of compiler backends by implementing backend passes for an existing frontend for the small functional programming language MiniML. The implementation focuses on code generation by emitting LLVM IR, an intermediate representation used by the industry standard compiler toolchain LLVM. Targeting LLVM enables the use of its established optimization and code generation infrastructure. The resulting compiler is evaluated both quantitatively, by measuring compile time and scalability, and qualitatively, by reflecting on the development experience with Trieste. The evaluations reveal that Trieste's feature set is well-suited for many backend tasks but that certain implementation decisions can lead to pitfalls and performance issues. Overall, the results affirm Trieste's potential for compiler backend development and code generation tasks, with the implemented compiler serving as a proof-of-concept. While the compiler leaves many potential improvements open for future work, its code generation stage lays a foundation for targeting LLVM, potentially reusable by other Trieste projects.