The Oberon programming language was proposed in 1987 by Niklaus Wirth as a successor to Pascal and Modula-2. Due to this lineage, Oberon is an ALGOL-like language with strong (static and dynamic) typing discipline. The programming paradigm of Oberon can be classified as imperative, structured, modular, and object-oriented.
This project provides the skeleton of a compiler for the Oberon-0 programming language, a subset of the full Oberon programming language, as described in Niklaus Wirth's book "Compiler Construction" (Chapter 6, pp. 30-32). The skeleton is written in C++ and serves as the starting point of the programming project that accompanies the M.Sc. course "Compiler Construction" at the University of Konstanz. The goal of this project is for students to design and develop a parser and intermediate representation for the Oberon-0 programming language. In order to generate executable code, they will transform their high-level intermediate representation into the low-level intermediate representation of the LLVM Compiler Infrastructure.
The provided C++ sourcecode can be compiled on different operating systems and with different toolchains. Currently, the sourcecode only depends on Boost and LLVM. As of March 2022, the following configurations are tested and known to work.
| macOS | Windows | Linux (Ubuntu) | |
|---|---|---|---|
| Boost | 1.74.0 | 1.74.0 | 1.74.0 |
| LLVM | 13.0.0 | 13.0.0 | 13.0.0 |
| CMake | 3.21.1 | 3.19.2 | 3.22.2 |
| IDE | CLion 2021.3.3 | Visual Studio 17.1.0 | CLion 2021.3.3 |
| CXX | Apple Clang 13.0.0 | CL 19.31.31104 | GCC 11.2.0 |
In order to build the compiler for the Oberon-0 programming language, Boost and LLVM have to be installed. Step-by-step installation instructions for macOS, Linux, and Windows are given below.
Using Homebrew, Boost and LLVM can be installed as follows.
> brew install boost
> brew install llvm
Using the Advanced Package Tool (APT), Boost and LLVM can be installed as follows.
> sudo apt install boost
> sudo apt install llvm
It is recommended to use Microsoft's vcpkg C++ Library Manager for Windows in order to install Boost and LLVM.
- Install vcpkg by following the steps below.
> git clone https://github.com/microsoft/vcpkg.git > cd vcpkg > .\bootstrap-vcpkg.bat - Configure automatic, user-wide integration of libraries managed by vcpkg with Visual Studio.
> .\vcpkg integrate install - Use vcpkg to install the following Boost libraries:
system,convert,filesystem, andprogram_options.> .\vcpkg install boost-system:x64-windows > .\vcpkg install boost-convert:x64-windows > .\vcpkg install boost-filesystem:x64-windows > .\vcpkg install boost-program-options:x64-windows - Using the Microsoft C++ Library Manager is also the simplest way to install LLVM on Windows (x64). Assuming that you
already followed the steps described above to install Boost using vcpkg, LLVM can be compiled and installed with the
following command.
There are, however, some drawbacks to installing LLVM using the Microsoft C++ Library Manager. First, vcpkg will compile and install both the release and the debug version of LLVM, which requires 70-80 GB of free hard-disk space during installation. Second, it typically takes a while before a new release of LLVM is integrated into the vcpkg distribution. Should any of these two factors present a problem, please refer to the instructions on how to build LLVM from the sources in the LLVM Demo project.
> .\vcpkg install llvm:x64-windows
In order to clone the repository from GitLab, use the following command.
> git clone https://gitlab.inf.uni-konstanz.de/dbis/education/oberon0c.git
This will create a new directory oberon0c in the current directory. This new directory is referred to as the root
directory of the project.
For macOS and Linux, CLion is recommended as a development environment. For Windows, the recommended development environment is Visual Studio. Alternatively, CMake can be used directly on the command line to build the project.
In order to build the compiler for the Oberon-0 programming language using CLion, follow the steps below.
- Start CLion and select
Openin the welcome dialog. - Navigate to the root directory of the project, e.g.,
oberon0c, to which you cloned the project repository and clickOpen. - Once the project is open, build it using the
Build→Build Projectmenu.
Note Under macOS on Apple Silicon (e.g., M1), it may be required to pass the command line argument
-DCMAKE_OSX_ARCHITECTURES=arm64 to CMake to ensure that an ARM64 binary is built.
Once the build successfully terminates, the oberon0c executable can be found in the oberon0c/cmake-build-debug or
oberon0c/cmake-build-release subdirectory.
In order to build the compiler for the Oberon-0 programming language using Visual Studio, follow the steps below.
- Start Visual Studio and select
File→Open→Folder...from the menu or pressCtrl+Shift+Alt+O. - Navigate to the root directory of the project, e.g.,
oberon0c, to which you cloned the project repository and clickSelect Folder. - Visual Studio will now run CMake to set up the project. Make sure that the build configuration in the toolbar of
Visual Studio matches the build type specified earlier. For example, if LLVM was compiled in
Releasemode, Visual Studio's build configuration has to bex64-Release. - Start the build using the
Build→Build Allmenu or pressCtrl+Shift+B.
Once the build successfully terminates, the oberon0c.exe executable can be found in the
oberon0c\out\build\x64-Debug or oberon0c\out\build\x64-Release directory.
In order to build the compiler for the Oberon-0 programming language using CMake, follow the steps below.
- On the command line, navigate to the root directory of the project, e.g.,
oberon0c. The root directory of the project is the directory that was created when you cloned the GitLab repository. - Create a build directory.
> mkdir build - Navigate to the build directory and run CMake to configure the project and generate a native build system.
> cd build > cmake .. - Call the build system to compile and link the project.
> cmake --build .
Once the build successfully terminates, the executable of the compiler for the Oberon-0 programming language can be
found in the build directory.