Skip to content
Michael Grossniklaus edited this page Dec 18, 2020 · 7 revisions

Welcome!

Welcome to the project wiki of the LLVM frontend for the Oberon programming language. This sentiment is, however, better expressed in terms of a HelloWorld program in Oberon itself.

MODULE HelloWorld;

CONST Message = "Hoi Niklaus!\n";

(* Import `printf` function from C <stdio.h> library. *)
PROCEDURE printf(format: STRING; ...): INTEGER; EXTERN;

(* Writes a string value to standard out. *)
PROCEDURE Write(str: STRING);
BEGIN
    printf(str)
END Write;

BEGIN
    Write(Message)
END HelloWorld.

On this wiki, you will find information specific to this project such as the documentation of the dialect of Oberon supported by the compiler as well as tutorials on how to build and use the compiler. General information about the Oberon programming language and its history can be found at the following locations.

Overview

This project follows the approach of implementing a language-specific frontend for the LLVM Compiler Infrastructure. Recently, this approach has been taken by many major compiler projects as, for example, C/C++ (clang), Rust, Go, and Haskell. In this approach, optimization and code generation are handled by the LLVM backend and tools. The interface between the frontend and backend is the LLVM IR (intermediate representation). As a consequence, the LLVM frontend for the Oberon programming language consists of the following components.

  • Scanner scans the input character by character and returns a stream of tokens
  • Parser checks whether the stream of tokens returned by the Scanner conforms to the grammar of the Oberon programming language and returns an abstract syntax tree
  • Analyzer checks whether the abstract syntax tree returned by the Parser conforms to the language semantics of the Oberon programming language
  • Compiler translates the abstract syntax tree into the intermediate representation used by the LLVM Compiler Infrastructure

Since the LLVM frontend for Oberon relies on the LLVM Compiler Infrastructure, it simply generates a file containing the serialized LLVM IR. Using LLVM tools such as the LLVM optimizer opt and the LLVM compiler llc, this returned filed can be translated into an object file, which finally can be linked using the operating systems compiler toolchain to obtain an executable binary file.

Clone this wiki locally