Skip to content
/ irl Public

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".

License

Notifications You must be signed in to change notification settings

hyouteki/irl

Repository files navigation

Intermediate Representation Language

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

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

flag Status Notes
fasm-linux-x86_64 ✔️ Supported Full functionality available
fasm-windows-x86_64 ✖️ Planned Future support under development
wasm ✖️ Planned Future 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

Control Flow Graph of example fib

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

Examples

Dependencies

Courtesy

About

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".

Topics

Resources

License

Stars

Watchers

Forks