irl - Intermediate Representation Language

⚠ Disclaimer(s)

Work in progress…

Planned to be a simpler version of what LLVM is at its core; “An optimizer and transpiler of its very own LLVM IR to various architecture’s ISA”.

Grammar

function L, n
arg id
id = op
id = op1 arith op2
id = unary op
goto L
label L
if (op1 relop op2) goto L
id = op1 relop op2
param op
id = call L, n
ret op

IRL Architecture

In the IRL architecture, the initial step involves converting the source code into an AST (Abstract Syntax Tree) using the frontend (fe) module. The resulting AST then passes through a middleware (mw) module that invokes AST passes for correction and validation. Two default AST passes include validate_iden_pass, which ensures all identifiers used in instructions are valid, and add_goto_pass, which inserts goto statements before necessary label instructions.

The corrected AST then proceeds to the optimization (opt) module, where it is transformed into a CFG (Control Flow Graph). This module applies Compiler Passes to the CFG to optimize it, including reduce_pass for simplifying the CFG, constant_fold_pass for folding constants, and reaching_definition_pass for eliminating redundant instructions.

The optimized CFG is then passed to the translation (trn) module, which translates it into assembly code tailored to the target architecture.

Supported Targets

flagStatusNotes
fasm-linux-x86_64✔️ SupportedFull functionality available
fasm-windows-x86_64✖️ PlannedFuture support under development
wasm✖️ PlannedFuture support under development

Getting Started

function fib, 1
  arg n
  a = 0
  b = 1
  i = 1
  label begin
    if (i == n) goto end
    t = b
    b = a + b
    a = t
    i = i + 1
    goto begin
  label end
    ret b

function main, 0
  param 6
  a = call fib, 1
  param a
  tmp = call print, 1
  ret 0
$ cargo run -- compile -r -f ./eg/fib.irl --cfg --fasm-linux-x86_64
8
$ echo $?
0

Generated control flow graph of this example

CLI Documentation

Compile source code to target(s)

Usage: irl.exe compile [OPTIONS] --filepath <filepath>

Options:
  -f, --filepath <filepath>  Source file path
      --cfg                  Output control flow graph of the program as a svg
  -d, --debug                Dumps debug info onto stdout
  -v, --verbose              Sets info level to verbose
  -r, --run                  Runs the binary after compilation
      --wat                  Generates WAT (Web Assembly Text)
      --wasm                 Generates WASM (Web Assembly)
      --fasm-linux-x86_64    Generates FASM (Flat Assembly)
  -h, --help                 Print help

Emacs mode

Examples

Dependencies

Courtesy


RepositoryLicense GPL-3.0

Go to top File an issue