Compilation to RISC-V - tinylang
A lightweight, educational programming language and compiler designed to introduce students to the principles of compiler construction and assert the feasability of RISC-V as compilation target.
Initial situation
The design and implementation of programming languages are pivotal educational tools in computer science, offering insights into how abstract computational ideas are transformed into a practical, executable form. A programming language provides a structured way to express algorithms and data manipulations, while its compiler illustrates the intricate process of translating high-level code into machine-readable instructions. Learning to create a programming language and its compiler involves understanding linguistic design, computational theory and the underlying architecture of computers, making it an essential exercise in mastering the principles of software and systems development.
Problem statement / Project goal
In order to illustrate and provide the ability to gain a substantial understanding in programming language design, compiler design and their implementation, a newly created programminglanguage is implemented along with its compiler. The project aims to answer the following questions:
- Is a subset of the RISC-V instruction set architecture appropriate to use as a target architecture in a compiler developed for educational purposes?
- What features of programming languages are considered relevant and worthy of implementation within the given educational context in regards to their complexity?
- What tools support development, testing and provide insight into the relevant topics at hand?
Bubblesort Example
An implementation of the well-known bubble sort algorithm in the created programming language.
Program Execution
The bubblesort program running on an emulated RISC-V linux based system. The built-in functionality levearages GNU libc for I/O related operations such as print by being able to link with it.
Compiler Architecture
The compiler stages from source code to assembly including the output produced at each stage.
Solution developed and its benefits
The developed compiler has shown that the chosen target architecture is great for the given educational context. This is due to various intrinsic aspects of the architecture. Especially, its modularity and RISC-V being a RISC architecture which inherently makes it simpler compared to other architectures.
The language includes the following features:
- built-in datatypes including booleans, integers, strings and arrays
- variables and constants
ifstatementsforandwhileloops- function declarations and calls
- limited I/O capabilities through built-in functions such as
print
The implementation of the aforementioned features in the created language has shown to be sufficiently effective in providing insight into various commonly established language features and their mechanisms related to the underlying architecture.
Furthermore, the implementation is divided into multiple well-defined steps which represent specific theoretical concepts (e.g. lexing, parsing, type-checking and more). All functionality is available through the compilers CLI, including running intermediate steps of the compiler for a given input. In addition to the compiler native commands, CPU simulators were great companion tools in the learning and testing process. They provide features such as live inspection of CPU registers and memory, debugging with breakpoints and much more.
Key terms
- CompilerA compiler is a program that translates high-level source code into machine code or an intermediate form executable by a computer.
- RISC-VRISC-V is an open-standard instruction set architecture (ISA) based on a reduced instruction set computer (RISC) design.
- CLIA command line interface is a text-based interface where users type commands to interact with a computer system or software.
- GNU libcThe standard C library implementation used in GNU/Linux systems, providing essential system call and runtime functionality.
Team
Lorenzo Baldassarri
Advisors
Daniel Kröni
Markus Knecht