{"id":19297171,"url":"https://github.com/jserv/amacc","last_synced_at":"2025-05-14T19:07:58.214Z","repository":{"id":37549446,"uuid":"50844155","full_name":"jserv/amacc","owner":"jserv","description":"Small C Compiler generating ELF executable Arm architecture, supporting JIT execution","archived":false,"fork":false,"pushed_at":"2024-12-27T04:21:12.000Z","size":404,"stargazers_count":1036,"open_issues_count":8,"forks_count":161,"subscribers_count":55,"default_branch":"master","last_synced_at":"2025-05-14T19:07:51.127Z","etag":null,"topics":["arm","armv7a","c","compiler","dynamic-linking","jit-compiler","linux","self-hosting"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jserv.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":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-02-01T14:20:05.000Z","updated_at":"2025-05-12T02:00:46.000Z","dependencies_parsed_at":"2022-07-20T12:32:29.907Z","dependency_job_id":"d90c61a5-1a6e-403b-ab76-17440421ddc5","html_url":"https://github.com/jserv/amacc","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/jserv%2Famacc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jserv%2Famacc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jserv%2Famacc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jserv%2Famacc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jserv","download_url":"https://codeload.github.com/jserv/amacc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254209859,"owners_count":22032897,"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":["arm","armv7a","c","compiler","dynamic-linking","jit-compiler","linux","self-hosting"],"created_at":"2024-11-09T23:01:46.227Z","updated_at":"2025-05-14T19:07:57.470Z","avatar_url":"https://github.com/jserv.png","language":"C","readme":"# AMaCC = Arguably Minimalist Arm C Compiler\n\n## Introduction\nAMaCC is a 32-bit Arm architecture compiler built from scratch.\nIt serves as a stripped-down version of C, designed as a pedagogical tool for\nlearning about compilers, linkers, and loaders.\n\nThere are two execution modes AMaCC implements:\n* Just-in-Time (JIT) compiler for Arm backend.\n* Generation of valid GNU/Linux executables using the Executable and Linkable Format (ELF).\n\nIt is worth mentioning that AMaCC is designed to compile a subset of C necessary\nto self-host with the above execution modes. For instance, it supports global\nvariables, particularly global arrays.\n\nA simple stack-based Abstract Syntax Tree (AST) is generated through cooperative\n`stmt()` and `expr()` parsing functions, both fed by a token-generating function.\nThe `expr()` function performs some literal constant optimizations. The AST is\ntransformed into a stack-based VM Intermediate Representation (IR) using the\n`gen()` function. The IR can be examined via a command-line option. Finally, the\n`codegen()` function generates Arm32 instructions from the IR, which can be\nexecuted via either `jit()` or `elf32()` executable generation\n\nAMaCC combines classical recursive descent and operator precedence parsing. An\noperator precedence parser proves to be considerably faster than a recursive\ndescent parser (RDP) for expressions when operator precedence is defined using\ngrammar productions that would otherwise be turned into methods.\n\n## Compatibility\nAMaCC is capable of compiling C source files written in the following\nsyntax:\n\n* support for all C89 statements except typedef.\n* support for all C89 expression operators.\n* data types: char, int, enum, struct, union, and multi-level pointers\n    - type modifiers, qualifiers, and storage class specifiers are\n      currently unsupported, though many keywords of this nature\n      are not routinely used, and can be easily worked around with\n      simple alternative constructs.\n    - struct/union assignments are not supported at the language level\n      in AMaCC, e.g. s1 = s2.  This also applies to function return\n      values and parameters. Passing and returning pointers is recommended.\n      Use memcpy if you want to copy a full struct, e.g.\n      memcpy(\u0026s1, \u0026s2, sizeof(struct xxx));\n* global/local variable initializations for supported data types\n    - e.g., `int i = [expr]`\n    - New variables are allowed to be declared within functions anywhere.\n    - item-by-item array initialization is supported\n    - but aggregate array declaration and initialization is yet to be supported\n      e.g., `int foo[2][2] = { { 1, 0 }, { 0, 1 } };`\n\nThe architecture support targets armv7hf with Linux ABI, and it has been verified\non Raspberry Pi 2/3/4 with GNU/Linux.\n\n## Prerequisites\n* Code generator in AMaCC relies on several GNU/Linux behaviors, and it\n  is necessary to have Arm/Linux installed in your build environment.\n* Install [GNU Toolchain for the A-profile Architecture](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads)\n    - Select `arm-linux-none-gnueabihf` (AArch32 target with hard float)\n\n* Install QEMU for Arm user emulation\n```shell\nsudo apt-get install qemu-user\n```\n\n## Running AMaCC\nRun `make check` and you should see this:\n```\n[ C to IR translation          ] Passed\n[ JIT compilation + execution  ] Passed\n[ ELF generation               ] Passed\n[ nested/self compilation      ] Passed\n[ Compatibility with GCC/Arm   ] ........................................\n----------------------------------------------------------------------\nRan 52 tests in 8.842s\n\nOK\n```\n\nCheck the messages generated by `make help` to learn more.\n\n## Benchmark\nAMaCC is able to generate machine code really fast and provides 70% of the performance of `gcc -O0`.\n\nTest environment:\n* Raspberry Pi 4B (SoC: bcm2711, ARMv8-A architecture)\n* Raspbian GNU/Linux, kernel 5.10.17-v7l+, gcc 8.3.0 (armv7l userland)\n\nInput source file: `amacc.c`\n\n| compiler driver                    | binary size (KiB) | compile time (s) |\n| ---------------------------------- | ----------------- | ---------------- |\n| gcc with `-O0 -ldl` (compile+link) | 56                |  0.5683          |\n| gcc with `-O0 -c` (compile only)   | 56                |  0.4884          |\n| AMaCC                              | 100               |  0.0217          |\n\n\n## Internals\nCheck [Intermediate Representation (IR) for AMaCC Compilation](docs/IR.md).\n\n## Acknowledgements\nAMaCC is based on the infrastructure of [c4](https://github.com/rswier/c4).\n\n## Related Materials\n* [Curated list of awesome resources on Compilers, Interpreters and Runtimes](http://aalhour.com/awesome-compilers/)\n* [Hacker News discussions](https://news.ycombinator.com/item?id=11411124)\n* [A Compiler Writing Journey](https://github.com/DoctorWkt/acwj) by Warren Toomey.\n","funding_links":[],"categories":["C","Compilers and Interpreters"],"sub_categories":["Educational and Toy Projects"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjserv%2Famacc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjserv%2Famacc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjserv%2Famacc/lists"}