{"id":23885987,"url":"https://github.com/arctic-marmoset/codegen","last_synced_at":"2025-02-23T03:27:56.185Z","repository":{"id":56755104,"uuid":"524602727","full_name":"arctic-marmoset/codegen","owner":"arctic-marmoset","description":"A repo for experimenting with AOT and JIT code generation, including IR transformations for optimisation.","archived":false,"fork":false,"pushed_at":"2022-08-16T07:20:24.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"trunk","last_synced_at":"2025-01-04T05:56:12.807Z","etag":null,"topics":["code-generation","cpp","cpp23","dataflow-analysis","intermediate-representation","optimizing-compilers"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arctic-marmoset.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-14T07:29:00.000Z","updated_at":"2022-08-14T09:28:39.000Z","dependencies_parsed_at":"2022-08-16T01:50:11.190Z","dependency_job_id":null,"html_url":"https://github.com/arctic-marmoset/codegen","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arctic-marmoset%2Fcodegen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arctic-marmoset%2Fcodegen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arctic-marmoset%2Fcodegen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arctic-marmoset%2Fcodegen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arctic-marmoset","download_url":"https://codeload.github.com/arctic-marmoset/codegen/tar.gz/refs/heads/trunk","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240265406,"owners_count":19774069,"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":["code-generation","cpp","cpp23","dataflow-analysis","intermediate-representation","optimizing-compilers"],"created_at":"2025-01-04T05:56:17.438Z","updated_at":"2025-02-23T03:27:56.159Z","avatar_url":"https://github.com/arctic-marmoset.png","language":"C++","readme":"# Codegen\n\nAn experiment on AOT and JIT code generation, including IR transformations for\noptimisation.\n\nThe goal of this project is not only to learn how to implement optimisations by\nputting into practice data-flow analysis theory, but also to design and\nstructure the code as clearly as possible such that it is easy for others to\nread, and thus learn from. This project currently focusses on the back-end, so\nfront-end operations such as lexing and parsing are omitted.\n\nThe project will take an incremental approach of first compiling a tiny subset\nof the source language all the way down to the target language or machine code,\nwhich at the moment is x64, then gradually increasing the size of the\nsubset\u0026mdash;a method inspired by \nAbdulaziz Ghuloum's [_An Incremental Approach to Compiler Construction_](https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.88.170\u0026rep=rep1\u0026type=pdf),\nand Nora Sandler's [_Writing a C Compiler_](https://norasandler.com/2017/11/29/Write-a-Compiler.html).\n\n# Current Progress\n\nThe program is currently capable of transforming, _without optimisations_, an\nAST representing a C-like compound statement containing multiple return\nstatements with optional return values (either add expressions of depth 1, or\nunsigned 32-bit integers), to x64 assembly, then executing it dynamically. An\nexample is as follows:\n\nInput AST:\n\n```\ncompound_statement\n|-return_statement\n| `-additive_expression '+'\n|   |-integer_literal 3735928549U # 0xDEADBEE5\n|   `-integer_literal 10U # 0xA\n|-return_statement\n`-return_statement\n  `-integer_literal 0U # 0x0\n```\n\nIR:\n\n```\n0000 basic_block {\n    $0 = add 3735928549U, 10U\n    return $0\n    return ()\n    return 0U\n}\n```\n\nGenerated bytes:\n\n```\n            00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n0x00000000: B8 E5 BE AD DE 05 0A 00 00 00 C3 C3 B8 00 00 00  ................\n0x00000010: 00 C3                                            ..\n```\n\nDisassembly:\n\n```asm\n0x00000000: mov     eax, 0xDEADBEE5\n0x00000005: add     eax, 0xA\n0x0000000A: ret\n0x0000000B: ret\n0x0000000C: mov     eax, 0\n0x00000011: ret\n```\n\nExecution:\n\n```\nfunction() = 0xDEADBEEF\n```\n\n# Building\n\n| Requirement                             | Minimum Version |\n|-----------------------------------------|-----------------|\n| [CMake](https://cmake.org/)             | 3.23            |\n| [Ninja](https://ninja-build.org/)       | -               |\n| [vcpkg](https://vcpkg.io/en/index.html) | -               |\n| C++ Compiler                            | C++23 support   |\n\nCMake and Ninja are available through your system package manager.\n\nAlthough not advised, libraries that are used can be found in\n[vcpkg.json](/vcpkg.json), and can alternatively be installed manually using\nyour system package manager as well.\n\nBuild using the following commands:\n\n```\ncmake --preset \u003cpreset\u003e .\ncmake --build ./build/\u003cpreset\u003e\n```\n\nWhere `\u003cpreset\u003e` is one of the non-hidden presets in\n[CMakePresets.json](/CMakePresets.json). The `/build` directory will contain the\nexecutable.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farctic-marmoset%2Fcodegen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farctic-marmoset%2Fcodegen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farctic-marmoset%2Fcodegen/lists"}