{"id":13632190,"url":"https://github.com/ShivamSarodia/ShivyC","last_synced_at":"2025-04-18T02:32:01.574Z","repository":{"id":44411439,"uuid":"63022542","full_name":"ShivamSarodia/ShivyC","owner":"ShivamSarodia","description":"C compiler created in Python.","archived":false,"fork":false,"pushed_at":"2023-05-23T06:44:15.000Z","size":629,"stargazers_count":1041,"open_issues_count":25,"forks_count":78,"subscribers_count":33,"default_branch":"master","last_synced_at":"2024-10-29T17:41:07.281Z","etag":null,"topics":["c","compiler","python"],"latest_commit_sha":null,"homepage":"","language":"Python","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/ShivamSarodia.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}},"created_at":"2016-07-10T23:16:02.000Z","updated_at":"2024-10-28T02:27:00.000Z","dependencies_parsed_at":"2024-01-14T07:02:02.384Z","dependency_job_id":"54ec6246-d8b0-4281-a52a-99e0ce0136c6","html_url":"https://github.com/ShivamSarodia/ShivyC","commit_stats":{"total_commits":437,"total_committers":11,"mean_commits":39.72727272727273,"dds":"0.16704805491990848","last_synced_commit":"376df50e820c5c0bcbf2e482b1b2f96f6cf0bbe7"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShivamSarodia%2FShivyC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShivamSarodia%2FShivyC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShivamSarodia%2FShivyC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ShivamSarodia%2FShivyC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ShivamSarodia","download_url":"https://codeload.github.com/ShivamSarodia/ShivyC/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249414253,"owners_count":21267724,"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":["c","compiler","python"],"created_at":"2024-08-01T22:02:55.570Z","updated_at":"2025-04-18T02:32:01.020Z","avatar_url":"https://github.com/ShivamSarodia.png","language":"Python","funding_links":[],"categories":["Python","Compiler"],"sub_categories":[],"readme":"# ShivyC [![Build Status](https://travis-ci.org/ShivamSarodia/ShivyC.svg?branch=master)](https://travis-ci.org/ShivamSarodia/ShivyC) [![Code Coverage](https://codecov.io/gh/ShivamSarodia/ShivyC/branch/master/graph/badge.svg)](https://codecov.io/gh/ShivamSarodia/ShivyC)\n\n### A hobby C compiler created in Python.\n\n![ShivyC demo GIF.](https://raw.githubusercontent.com/ShivamSarodia/ShivyC/master/demo.gif)\n\n---\n\nShivyC is a hobby C compiler written in Python 3 that supports a subset of the C11 standard and generates reasonably efficient binaries, including some optimizations. ShivyC also generates helpful compile-time error messages.\n\nThis [implementation of a trie](tests/general_tests/trie/trie.c) is an example of what ShivyC can compile today. For a more comprehensive list of features, see the [feature test directory](tests/feature_tests).\n\n## Quickstart\n\n### x86-64 Linux\nShivyC requires only Python 3.6 or later to compile C code. Assembling and linking are done using the GNU binutils and glibc, which you almost certainly already have installed.\n\nTo install ShivyC:\n```\npip3 install shivyc\n```\nTo create, compile, and run an example program:\n```c\n$ vim hello.c\n$ cat hello.c\n\n#include \u003cstdio.h\u003e\nint main() {\n  printf(\"hello, world!\\n\");\n}\n\n$ shivyc hello.c\n$ ./out\nhello, world!\n```\nTo run the tests:\n```\ngit clone https://github.com/ShivamSarodia/ShivyC.git\ncd ShivyC\npython3 -m unittest discover\n```\n\n### Other Architectures\nFor the convenience of those not running Linux, the [`docker/`](docker/) directory provides a Dockerfile that sets up an x86-64 Linux Ubuntu environment with everything necessary for ShivyC. To use this, run:\n```\ngit clone https://github.com/ShivamSarodia/ShivyC.git\ncd ShivyC\ndocker build -t shivyc docker/\ndocker/shell\n```\nThis will open up a shell in an environment with ShivyC installed and ready to use with\n```\nshivyc any_c_file.c           # to compile a file\npython3 -m unittest discover  # to run tests\n```\nThe Docker ShivyC executable will update live with any changes made in your local ShivyC directory.\n\n## Implementation Overview\n#### Preprocessor\nShivyC today has a very limited preprocessor that parses out comments and expands `#include` directives. These features are implemented between [`lexer.py`](shivyc/lexer.py) and [`preproc.py`](shivyc/lexer.py).\n\n#### Lexer\nThe ShivyC lexer is implemented primarily in [`lexer.py`](shivyc/lexer.py). Additionally, [`tokens.py`](shivyc/tokens.py) contains definitions of the token classes used in the lexer and [`token_kinds.py`](shivyc/token_kinds.py) contains instances of recognized keyword and symbol tokens.\n\n#### Parser\nThe ShivyC parser uses recursive descent techniques for all parsing. It is implemented in [`parser/*.py`](shivyc/parser/) and creates a parse tree of nodes defined in [`tree/nodes.py`](shivyc/tree/nodes.py) and [`tree/expr_nodes.py`](shivyc/tree/expr_nodes.py).\n\n#### IL generation\nShivyC traverses the parse tree to generate a flat custom IL (intermediate language). The commands for this IL are in [`il_cmds/*.py`](shivyc/il_cmds/) . Objects used for IL generation are in [`il_gen.py`](shivyc/il_gen.py) , but most of the IL generating code is in the `make_code` function of each tree node in [`tree/*.py`](shivyc/tree/).\n\n#### ASM generation\nShivyC sequentially reads the IL commands, converting each into Intel-format x86-64 assembly code. ShivyC performs register allocation using George and Appel’s iterated register coalescing algorithm (see References below). The general ASM generation functionality is in [`asm_gen.py`](shivyc/asm_gen.py) , but much of the ASM generating code is in the `make_asm` function of each IL command in [`il_cmds/*.py`](shivyc/il_cmds/).\n\n## Contributing\nPull requests to ShivyC are very welcome. A good place to start is the [Issues page](https://github.com/ShivamSarodia/ShivyC/issues). All [issues labeled \"feature\"](https://github.com/ShivamSarodia/ShivyC/issues?q=is%3Aopen+is%3Aissue+label%3Afeature) are TODO tasks. [Issues labeled \"bug\"](https://github.com/ShivamSarodia/ShivyC/issues?q=is%3Aopen+is%3Aissue+label%3Abug) are individual miscompilations in ShivyC. If you have any questions, please feel free to ask in the comments of the relevant issue or create a new issue labeled \"question\". Of course, please add test(s) for all new functionality.\n\nMany thanks to our current and past contributers:\n* [ShivamSarodia](https://github.com/ShivamSarodia)\n* [cclauss](https://github.com/cclauss)\n* [TBladen](https://github.com/tbladen)\n* [christian-stephen](https://github.com/christian-stephen)\n* [jubnzv](https://github.com/jubnzv)\n* [eriols](https://github.com/eriols)\n\n## References\n- [ShivC](https://github.com/ShivamSarodia/ShivC) - ShivyC is a rewrite from scratch of my old C compiler, ShivC, with much more emphasis on feature completeness and code quality. See the ShivC README for more details.\n- C11 Specification - http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf\n- x86_64 ABI - https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdf\n- Iterated Register Coalescing (George and Appel) - https://www.cs.purdue.edu/homes/hosking/502/george.pdf\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShivamSarodia%2FShivyC","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FShivamSarodia%2FShivyC","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FShivamSarodia%2FShivyC/lists"}