{"id":13621046,"url":"https://github.com/rui314/9cc","last_synced_at":"2025-05-16T04:00:19.772Z","repository":{"id":38360082,"uuid":"143569178","full_name":"rui314/9cc","owner":"rui314","description":"A Small C Compiler","archived":false,"fork":false,"pushed_at":"2020-11-28T05:05:20.000Z","size":280,"stargazers_count":1872,"open_issues_count":13,"forks_count":158,"subscribers_count":80,"default_branch":"master","last_synced_at":"2025-05-15T06:16:25.363Z","etag":null,"topics":[],"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/rui314.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}},"created_at":"2018-08-04T23:15:52.000Z","updated_at":"2025-05-14T23:08:12.000Z","dependencies_parsed_at":"2022-07-18T01:30:45.606Z","dependency_job_id":null,"html_url":"https://github.com/rui314/9cc","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/rui314%2F9cc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rui314%2F9cc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rui314%2F9cc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rui314%2F9cc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rui314","download_url":"https://codeload.github.com/rui314/9cc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254464890,"owners_count":22075570,"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":[],"created_at":"2024-08-01T21:01:02.041Z","updated_at":"2025-05-16T04:00:19.694Z","avatar_url":"https://github.com/rui314.png","language":"C","funding_links":[],"categories":["C","Programming Languages"],"sub_categories":[],"readme":"9cc C compiler\n==============\n\nNote: 9cc is no longer an active project, and the successor is\n[chibicc](https://github.com/rui314/chibicc).\n\n9cc is a successor of my [8cc](https://github.com/rui314/8cc) C compiler.\nIn this new project, I'm trying to write code that can be understood\nextremely easily while creating a compiler that generates reasonably\nefficient assembly.\n\n9cc has more stages than 8cc. Here is an overview of the internals:\n\n 1. Compiles an input string to abstract syntax trees.\n 2. Runs a semantic analyzer on the trees to add a type to each tree node.\n 3. Converts the trees to intermediate code (IR), which in some degree\n    resembles x86-64 instructions but has an infinite number of registers.\n 4. Maps an infinite number of registers to a finite number of registers.\n 5. Generates x86-64 instructions from the IR.\n\nThere are a few important design choices that I made to keep the code as\nsimple as I can get:\n\n - Like 8cc, no memory management is the memory management policy in 9cc.\n   We allocate memory using malloc() but never call free().\n   I know that people find the policy odd, but this is actually a\n   reasonable design choice for short-lived programs such as compilers.\n   This policy greatly simplifies code and also eliminates use-after-free\n   bugs entirely.\n\n - 9cc's parser is a hand-written recursive descendent parser, so that the\n   compiler doesn't have any blackbox such as lex/yacc.\n\n - I stick with plain old tools such as Make or shell script so that you\n   don't need to learn about new stuff other than the compiler source code\n   itself.\n\n - We use brute force if it makes code simpler. We don't try too hard to\n   implement sophisticated data structures to make the compiler run faster.\n   If the performance becomes a problem, we can fix it at that moment.\n\n - Entire contents are loaded into memory at once if it makes code simpler.\n   We don't use character IO to read from an input file; instead, we read\n   an entire file to a char array in a batch. Likewise, we tokenize a\n   whole file in a batch rather than doing it concurrently with the parser.\n\nOverall, 9cc is still in its very early stage. I hope to continue\nimproving it to the point where 9cc can compile real-world C programs such\nas Linux kernel. That is an ambitious goal, but I believe it's achievable,\nso stay tuned!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frui314%2F9cc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frui314%2F9cc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frui314%2F9cc/lists"}