Abstract

A compiler is a program that translates source code written in a particular language into another language. Internally, the whole process is typically split into multiple stages that handle one particular aspect of this translation. One of these consists of translating the high-level representation of the program, typically an abstract syntax tree, into a simpler form that is suitable for analysis, optimizations, and code generation. This tutorial paper focuses on this process, and uses LLVM to compile programs into optimized machine code. LLVM is a language-agnostic compiler toolchain that handles program optimization and code generation. It is based on its own internal representation, called LLVM IR, which is then transformed into machine code. We give a brief introduction to LLVM IR, and describe a few patterns to translate high-level language constructs expressed as abstract syntax trees. We implement these patterns in a compiler for a toy programming language, named Cocodol, which supports dynamic typing, unbounded loops, and higher-order functions.

Full Text
Published version (Free)

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call