Home

Awesome

<img align="center" padding="2" src="OlaDocs/olalogo_wide.png"/> Ola is a toy programming language with both LLVM backend and a work-in-progress custom backend.

Dependencies

Features

Structure

The project consists of the following parts:

  1. Ola Library:

    • A standard library for the Ola language, implemented in C and built as a static library to be used by the compiler. It includes essential components like:
      • olaio.h, olamath.h, olaassert.h, olastring.h, olamemory.h
  2. Ola Compiler:

    • The core of the Ola project, implemented as a static library (OlaCompiler) with the following components:
      • Lexer: Tokenizes the source code.
      • Import Processor: Processes import statements from the tokenized input.
      • Parser: A recursive descent parser that constructs an Abstract Syntax Tree (AST) from processed tokens.
      • Sema: Performs semantic analysis on the AST to ensure code correctness.
      • Backend: After frontend processing, the compilation process diverges into two backend paths:
        • LLVM:
          • LLVMIR Visitor: Transforms the AST into LLVM IR.
          • LLVMIR Pass Manager: Applies LLVM optimization passes to the IR.
          • Compilation to assembly is done using the clang -S command.
        • Custom Backend:
          • IR Visitor: Transforms the AST into Ola's custom IR.
          • IR Pass Manager: Applies custom optimizations at the IR level.
          • MachineModule: Responsible for lowering IR to MIR and finally to assembly.
  3. Ola Driver:

    • An executable (OlaDriver) that serves as the main entry point for compiling Ola code. It links to the OlaCompiler library and calls compiler's API.
  4. Ola Playground:

    • A separate executable that links to the OlaCompiler static library. It provides a development environment for experimenting with the compiler and Ola code, without directly invoking the OlaDriver.
  5. Ola Tests:

    • A set of unit tests built with GoogleTest, covering Ola language features. These tests are organized into two main folders:
      • LLVM Tests: Unit tests that use the LLVM backend of the compiler.
      • Custom Backend Tests: Unit tests that use the custom backend.
      • The tests rely on the Assert function from the std.assert import.
      • OlaDriver executable is used in the tests via system calls, allowing the tests to invoke the compiled executable to verify correct behavior.

Usage

Command line options

Visualizations

private int min(int a, int b) 
{
    int c;
    if (a < b) 
    {
        c = a;
    } 
    else
    {
        c = b;
    }
    return c;
}

public int main()
{
    return min(3,4);
}

CFG

LLVM backend

Without optimizations
<img src="OlaDocs/Images/llvm_cfg_O0.png" alt="CFG without optimizations in LLVM backend">
With optimizations
<img src="OlaDocs/Images/llvm_cfg_O1.png" alt="CFG with optimizations in LLVM backend">

Custom backend

Without optimizations
<img src="OlaDocs/Images/custom_cfg_O0.png" alt="CFG without optimizations in custom backend">
With optimizations
<img src="OlaDocs/Images/custom_cfg_O1.png" alt="CFG with optimizations in custom backend">

Dominator Tree

LLVM backend

Without optimizations
<img src="OlaDocs/Images/llvm_domtree_O0.png" alt="Dominator tree without optimizations in LLVM backend">
With optimizations
<img src="OlaDocs/Images/llvm_domtree_O1.png" alt="Dominator tree with optimizations in LLVM backend">

Custom backend

With and without optimizations
<img src="OlaDocs/Images/custom_domtree.png" alt="Dominator tree in custom backend">

Samples

Currently to see the samples you can check the test folder: OlaTests/Tests/.