{"id":14991133,"url":"https://github.com/hyouteki/irl","last_synced_at":"2025-06-13T07:38:18.290Z","repository":{"id":244567343,"uuid":"815626440","full_name":"hyouteki/irl","owner":"hyouteki","description":"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\".","archived":false,"fork":false,"pushed_at":"2024-08-17T07:43:42.000Z","size":301,"stargazers_count":4,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T23:02:59.980Z","etag":null,"topics":["compiler-infrastructure","intermediate-representation","language","llvm","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hyouteki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-15T16:44:16.000Z","updated_at":"2024-08-16T02:34:08.000Z","dependencies_parsed_at":"2024-09-25T00:34:19.602Z","dependency_job_id":null,"html_url":"https://github.com/hyouteki/irl","commit_stats":{"total_commits":43,"total_committers":2,"mean_commits":21.5,"dds":0.2558139534883721,"last_synced_commit":"ca9b5ce201031592d779142b214e9620d9d9955a"},"previous_names":["hyouteki/irl"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyouteki%2Firl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyouteki%2Firl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyouteki%2Firl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyouteki%2Firl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyouteki","download_url":"https://codeload.github.com/hyouteki/irl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248511194,"owners_count":21116363,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compiler-infrastructure","intermediate-representation","language","llvm","rust"],"created_at":"2024-09-24T14:21:32.171Z","updated_at":"2025-04-12T03:25:23.239Z","avatar_url":"https://github.com/hyouteki.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Intermediate Representation Language\n\u003e 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\".\n\n### Grammar\n``` asm\nfunction L, n\narg id\nid = op\nid = op1 arith op2\nid = unary op\ngoto L\nlabel L\nif (op1 relop op2) goto L\nid = op1 relop op2\nparam op\nid = call L, n\nret op\n```\n\n### IRL Architecture\n![IRL architecture](./resources/irl-architecture.jpg)\n\nIn the IRL architecture, the initial step involves converting the source code into an [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree) (Abstract Syntax Tree) using the frontend ([`fe`](./src/fe)) module. The resulting AST then passes through a middleware ([`mw`](./src/mw)) module that invokes AST passes for correction and validation. Two default AST passes include [`validate_iden_pass`](./src/mw/validate_iden_pass.rs), which ensures all identifiers used in instructions are valid, and [`add_goto_pass`](./src/mw/add_goto_pass.rs), which inserts `goto` statements before necessary label instructions.\n\nThe corrected AST then proceeds to the optimization ([`opt`](./src/opt)) module, where it is transformed into a [CFG](https://en.wikipedia.org/wiki/Control-flow_graph) (Control Flow Graph). This module applies Compiler Passes to the CFG to optimize it, including [`reduce_pass`](./src/opt/reduce_pass.rs) for simplifying the CFG, [`constant_fold_pass`](./src/opt/constant_propagation_pass.rs) for folding constants, and `reaching_definition_pass` for eliminating redundant instructions.\n\nThe optimized CFG is then passed to the translation ([`trn`](./src/trn)) module, which translates it into assembly code tailored to the target architecture.\n\n### Supported Targets\n| flag                   | Status         | Notes                            |\n|------------------------|----------------|----------------------------------|\n| `fasm-linux-x86_64`    | ✔️ Supported   | Full functionality available     |\n| `fasm-windows-x86_64`  | ✖️ Planned     | Future support under development |\n| `wasm`                 | ✖️ Planned     | Future support under development |\n\n### Getting Started\n``` asm\nfunction fib, 1\n  arg n\n  a = 0\n  b = 1\n  i = 1\n  label begin\n    if (i == n) goto end\n    t = b\n    b = a + b\n    a = t\n    i = i + 1\n    goto begin\n  label end\n    ret b\n\nfunction main, 0\n  param 6\n  a = call fib, 1\n  param a\n  tmp = call print, 1\n  ret 0\n```\n``` console\n$ cargo run -- compile -r -f ./eg/fib.irl --cfg --fasm-linux-x86_64\n8\n$ echo $?\n0\n```\n\u003e Generated control flow graph of this example\n\u003e \n\u003e ![Control Flow Graph of example fib](./eg/fib.dot.svg)\n\n### CLI Documentation\n```md\nCompile source code to target(s)\n\nUsage: irl.exe compile [OPTIONS] --filepath \u003cfilepath\u003e\n\nOptions:\n  -f, --filepath \u003cfilepath\u003e  Source file path\n      --cfg                  Output control flow graph of the program as a svg\n  -d, --debug                Dumps debug info onto stdout\n  -v, --verbose              Sets info level to verbose\n  -r, --run                  Runs the binary after compilation\n      --wat                  Generates WAT (Web Assembly Text)\n      --wasm                 Generates WASM (Web Assembly)\n      --fasm-linux-x86_64    Generates FASM (Flat Assembly)\n  -h, --help                 Print help\n```\n\n### Examples\n- [Fibonacci](./eg/fib.irl)\n- [Constant Propagation Analysis test](./eg/constant_propagation_test.irl)\n\n### Dependencies\n- [graphviz - Graph Visualization Tools](https://graphviz.org/download/)\n- [flatassembler - tgrysztar](https://flatassembler.net/)\n- [wabt - webassembly](https://github.com/WebAssembly/wabt)\n\n### Courtesy\n- [fasm-mode - emacsattic](https://github.com/emacsattic/fasm-mode/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyouteki%2Firl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyouteki%2Firl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyouteki%2Firl/lists"}