{"id":19528113,"url":"https://github.com/clflushopt/compiler-examples","last_synced_at":"2025-10-05T00:44:14.072Z","repository":{"id":257303962,"uuid":"831867307","full_name":"clflushopt/compiler-examples","owner":"clflushopt","description":"An implementation oriented cookbook for compiler writers.","archived":false,"fork":false,"pushed_at":"2024-09-15T20:09:51.000Z","size":102,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-26T02:31:29.147Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clflushopt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-07-21T21:00:36.000Z","updated_at":"2024-12-11T03:39:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"f4f8aa21-dcfc-47c0-ae51-ab3fa7abc52f","html_url":"https://github.com/clflushopt/compiler-examples","commit_stats":null,"previous_names":["clflushopt/compiler-examples"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/clflushopt/compiler-examples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clflushopt%2Fcompiler-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clflushopt%2Fcompiler-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clflushopt%2Fcompiler-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clflushopt%2Fcompiler-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clflushopt","download_url":"https://codeload.github.com/clflushopt/compiler-examples/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clflushopt%2Fcompiler-examples/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278395915,"owners_count":25979691,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-11T01:17:31.232Z","updated_at":"2025-10-05T00:44:14.024Z","avatar_url":"https://github.com/clflushopt.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Compiler Examples\n\nThis repo contains various reference implementations of compiler related data \nstructures and algorithms.\n\nMost of the following was initially done while working through Cornell's CS6120\n[course](https://www.cs.cornell.edu/courses/cs6120/2023fa/self-guided/) from\nthe course assignments, reading papers, LLVM's codebase and various books.\n\nThe objective is to create a sort of cookbook of reference implementations that\nfocus on clarity, simplicity and hopefully correctness. \n\nThe repository contains a complete implementation of the Bril intermediate\nlanguage with several analyses, optimizations and various compiler related\ndata structures e.g control flow graphs, SSA representation, dominance graphs...\n\nI hope you enjoy hacking on it as much as I enjoyed writing.\n\n## Usage\n\nThe repository is designed to allow you to hack on things as much as possible.\n\nThe core implementation revolves around [`bril.ir`](bril/core/ir.py) where most\nof the core intermediate language is implemented, the [tools](bril/tools/) directory\ncontains small utilities that can be used to parse and manipulate Bril programs.\n\nFor testing, a custom built tool inspired by `llvm-lit` called [`turnstile`](turnstile/turnstile.py)\nis provided. `turnstile` runs snapshot testing of input vs outputs, it's both a\ntesting framework and a library that can be used to write `expect` style tests.\n\n`turnstile` is how we test all program transformations especially when it comes\nto optimization passes and so on.\n\nIf you don't like `turnstile` which is just a lighter, basic version of `turnt`\nthen you can use `turnt` instead which supports configuration via TOML and better\nCLI integration.\n\n## Recipes\n\nThis is a non-exhaustive list of things that are currently implemented :\n\n- Various mini tools to work with the IR in [tools](bril/tools/) folder.\n- Instructions and Basic Blocks see [ir.py](bril/core/ir.py)\n- Control Flow Graph construction, predecessors and successors computation.. see [cfg.py](bril/core/cfg.py)\n- Scalar optimizations like dead code elimination, redundant store elimination, local value numbering\n  with constant propagation and constant folding see [transform.py](bril/core/transform.py).\n- Program analyses (without the data flow framework) like liveness analysis and available expressions see [analyses.py](bril/core/analyses.py) .\n- Data-flow analysis, with a data-flow framework see [df.py](bril/core/df.py)\n\n## References\n\n* [CS6120: Advanced Compilers](https://www.cs.cornell.edu/courses/cs6120/2023fa/self-guided/)\n* [LLVM Programmer's Manual](https://llvm.org/docs/ProgrammersManual.html)\n* [Engineering a Compiler 3rd Edition](https://www.sciencedirect.com/book/9780128154120/engineering-a-compiler)\n* [CSC255/455 Software Analysis and Improvement](https://www.cs.rochester.edu/~sree/courses/csc-255-455/spring-2020/schedule.html)\n* [Data flow analysis: an informal introduction](https://clang.llvm.org/docs/DataFlowAnalysisIntro.html)\n* [Notes on Graph Algorithms in Optimizing Compilers](https://www.cs.umb.edu/~offner/files/flow_graph.pdf)\n* [SSA-based Compiler Design](https://link.springer.com/book/10.1007/978-3-030-80515-9)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclflushopt%2Fcompiler-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclflushopt%2Fcompiler-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclflushopt%2Fcompiler-examples/lists"}