{"id":14110199,"url":"https://github.com/PhilippRados/wrecc","last_synced_at":"2025-08-01T09:33:18.844Z","repository":{"id":165330826,"uuid":"529920506","full_name":"PhilippRados/wrecc","owner":"PhilippRados","description":"A x86_64 C99 compiler written in Rust from scratch","archived":false,"fork":false,"pushed_at":"2024-06-11T21:30:18.000Z","size":1424,"stargazers_count":390,"open_issues_count":2,"forks_count":13,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-17T11:11:55.222Z","etag":null,"topics":["c","codegen","compiler","from-scratch","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/PhilippRados.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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":"2022-08-28T16:42:22.000Z","updated_at":"2024-11-16T11:06:54.000Z","dependencies_parsed_at":"2023-11-19T23:21:00.081Z","dependency_job_id":"def3abad-e272-4372-b41e-4d3e6d1d7b0b","html_url":"https://github.com/PhilippRados/wrecc","commit_stats":null,"previous_names":["philipprados/wrecc"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhilippRados%2Fwrecc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhilippRados%2Fwrecc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhilippRados%2Fwrecc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PhilippRados%2Fwrecc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PhilippRados","download_url":"https://codeload.github.com/PhilippRados/wrecc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228360655,"owners_count":17907950,"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","codegen","compiler","from-scratch","rust"],"created_at":"2024-08-14T10:02:42.921Z","updated_at":"2025-08-01T09:33:18.829Z","avatar_url":"https://github.com/PhilippRados.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"\u003cdiv\u003e\n  \u003cp align=\"left\"\u003e\n    \u003cimg src=\"https://i.ibb.co/1bfxpbb/wreckage-mj.jpg\" width=\"800\"\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n[![Test](https://github.com/PhilippRados/wrecc/actions/workflows/test.yml/badge.svg)](https://github.com/PhilippRados/wrecc/actions/workflows/test.yml)\n![](https://img.shields.io/github/license/PhilippRados/wrecc)\n![](https://img.shields.io/badge/made_for-UNIX-lightgrey)\n![](https://img.shields.io/badge/Architecture-x86--64-blue)\n\n`wrecc` is a small,lean x86-64 C99 compiler written from scratch. The name is a play on the word _wreck_ which describes a rusting ship on the sea floor. \nThe compiler emits [x86-64](https://en.wikipedia.org/wiki/X86-64) assembly in [AT\u0026T syntax](https://staffwww.fullcoll.edu/aclifton/courses/cs241/syntax.html), it adheres to the [System V ABI](https://wiki.osdev.org/System_V_ABI) which I could only test for Ubuntu and Macos. There are no dependencies you only need your assembler and linker which the compiler then invokes to create the final binary.\n\n### Table of contents\n* [Installation](#installation)\n  + [Pre-built binaries](#binaries)\n  + [Cargo](#cargo)\n* [Features](#features)\n  + [Preprocessor](#preprocessor)\n  + [Compiler](#compiler)\n    + [Supported keywords](#keywords)\n    + [Unimplemented features](#unimplemented)\n  + [Error messages](#errors)\n  + [Ast pretty-printer](#ast)\n* [Testing](#testing)\n* [Troubleshooting](#troubleshooting) \n* [Contribution](#contribution)\n* [Project goals](#goals)\n* [Resources](#resources)\n\n\n## Installation\n### Pre-built binaries \u003ca name=\"binaries\"\u003e\u003c/a\u003e\nIf you don't have the rust toolchain installed on your system you can install the latest binary (MacOs, Linux) from the releases directly:\n```\ncurl --proto '=https' --tlsv1.2 -LsSf https://github.com/PhilippRados/wrecc/releases/download/v0.2.0/wrecc-installer.sh | sh\n```\n### Cargo\nUsing `cargo binstall`\n```\ncargo binstall wrecc\n```\nor building from source\n```\ncargo install wrecc\n```\n\n## Features\nSince not all keywords are currently implemented wrecc uses [custom standard-headers](https://github.com/PhilippRados/wrecc/tree/master/include) which are built directly into the binary\n### Preprocessor\nThe preprocessor implements all [C99 preprocessor directives](https://en.cppreference.com/w/c/keyword), except `#line` and `#pragma`. Most prominently it currently also misses function-like macros which are on the agenda though.\n\n### Compiler\n#### Supported Keywords \u003ca name=\"keywords\"\u003e\u003c/a\u003e\n\u003cimg width=\"481\" alt=\"keywords\" src=\"https://github.com/PhilippRados/wrecc/assets/60818062/492cdf56-ee83-4333-9084-02fcd8a08356\"\u003e\n\n#### Other than that it even supports:\n\u003cdetails\u003e\n  \u003csummary\u003eAggregate initialization with designated initializers\u003c/summary\u003e\n  \n  ```C\n  struct {\n    union {\n      int foo;\n      long baz;\n    } nested;\n    int array[16];\n  } bar = { .nested.foo = 3, .array[6] = 1};\n  ```\n\n\u003c/details\u003e\n\u003cdetails\u003e\n  \u003csummary\u003eFunction pointers\u003c/summary\u003e\n\n  ```C\n  #include \u003cstdio.h\u003e\n  \n  typedef int (*BinaryOperation)(int, int);\n  typedef struct {\n    BinaryOperation add;\n    BinaryOperation subtract;\n  } Calculator;\n  \n  int add(int a, int b) { return a + b; }\n  int subtract(int a, int b) { return a - b; }\n  \n  int main() {\n    Calculator calc = {add, subtract};\n  \n    printf(\"Result of addition: %d\\n\", calc.add(10, 5));\n    printf(\"Result of subtraction: %d\\n\", calc.subtract(10, 5));\n  }\n\n  ```\n\n\u003c/details\u003e\n\u003cdetails\u003e\n  \u003csummary\u003eConstant folding\u003c/summary\u003e\n  \n  ```C\n  char **string_offset = (char **)\u0026\"hello\" + (int)(3 * 1);\n  int array[(long)3 * 2 - 1];\n  ```\n\n\u003c/details\u003e\n\n#### Unimplemented Features \u003ca name=\"unimplemented\"\u003e\u003c/a\u003e\nAside from the missing keywords these are the main missing features:\n- [x] Arrays with unspecified size\n- [x] Compiling multiple files at once\n- [ ] Raw structs/unions as function argument-/return-types\n- [ ] Floating point types\u003cbr\u003e\n\nHere is a list of all the stuff still missing: [todo](https://placid-eris-c19.notion.site/check-all-errors-from-c-testsuite-6f3fa2a3c24a4711b5e89f45354db540?pvs=4)\n\n### Error messages \u003ca name=\"errors\"\u003e\u003c/a\u003e\nWrecc also has nice looking messages. Error reporting doesn't stop after the first error. Using the `--no-color` option you can switch off color-highlighting in errors. Currently there are only errors and no warnings.\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003eC code\u003c/th\u003e\n    \u003cth\u003eErrors\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n  \u003ctd\u003e\n    \n  ```C\n  int foo(void);\n  int main() {\n    int a = foo(1);\n    long *p = a;\n  \n    return p * 2;\n  }\n  ```\n  \u003c/td\u003e\n  \u003ctd\u003e\n    \u003cimg width=\"535\" alt=\"error\" src=\"https://github.com/PhilippRados/wrecc/assets/60818062/0b0e0c9f-3600-460c-9da5-1705ef0f83d9\"\u003e\n  \u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n### Ast pretty-printer \u003ca name=\"ast\"\u003e\u003c/a\u003e\nWhen compiling using the `--dump-ast` option it prints the parse-tree\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003eC code\u003c/th\u003e\n    \u003cth\u003eAST\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n  \u003ctd\u003e\n    \n  ```C\n  #define SIZE 16\n  void foo(char);\n  int main() {\n    int arr[SIZE] = {1, 2};\n    char p = (char)(*arr + 3);\n  \n    switch (p) {\n    case 'c':\n      foo(p);\n    }\n  }\n  ```\n  \u003c/td\u003e\n  \u003ctd\u003e\n  \n  ```\n  Declaration:\n  -Decl: 'foo'\n  FuncDef: 'main'\n  -Declaration:\n  --Init: 'arr'\n  ---Aggregate:\n  ----Scalar:\n  -----Literal: 1\n  ----Scalar:\n  -----Literal: 2\n  -Declaration:\n  --Init: 'p'\n  ---Scalar:\n  ----Cast: 'char'\n  -----Grouping:\n  ------Binary: '+'\n  -------Unary: '*'\n  --------Ident: 'arr'\n  -------Literal: 3\n  -Switch:\n  --Ident: 'p'\n  --Block:\n  ---Case:\n  ----Literal: 99\n  ----Expr:\n  -----FuncCall:\n  ------Ident: 'foo'\n  ------Ident: 'p'\n```\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n#### Inspect all options by running `wrecc --help`\n\n## Testing\nRun different types of tests with `make \u003ctarget\u003e`. Available targets can be inspected using `make help` as shown below.\n```console\n$ make help\nUsage:\n  make \u003ctarget\u003e\n  help             Display this help\n  unit-tests       Run rust unit-tests\n  snapshot-tests   Run snapshot-tests located in tests/\n  c-testsuite      Requires c-testsuite (https://github.com/c-testsuite/c-testsuite) and env-var C_TESTSUITE set to its path\n  fuzzer           Launch afl.rs fuzzer\n```\n\n## Troubleshooting\nReasons for `wrecc` not working properly on your machine:\n- Unsupported architecture/OS\n- Cannot find libc in standard library search paths (can be fixed by passing custom search path using `-L \u003cpath\u003e` option)\n- If it's not mentioned in the [unimplemented features](#unimplemented) section then please raise an issue\n\n## Contribution\nIf you want to help me with this compiler I would really welcome it. The easiest place to start is probably by implementing one of the missing keywords/types mentioned in the [unimplemented features](#unimplemented) section. Make sure all tests still pass and implement your own if it's something new that is not already being tested.\u003cbr\u003e\nHave a look at the [documentation](https://docs.rs/wrecc_compiler/latest/wrecc_compiler/) to get a high level overview of the compiler pipeline.\n\n## Project goals \u003ca name=\"goals\"\u003e\u003c/a\u003e\n- Not relying on custom headers\n- Passing all C99 tests in [c-testsuite](https://github.com/c-testsuite/c-testsuite)\n- Compiling real-world C projects like [Git](https://github.com/git/git/tree/master)\n\n## Resources\nThe following resources helped me in building this compiler:\n- [Crafting Interpreters](https://craftinginterpreters.com/)\n- Engineering a Compiler (Book)\n- [acwj](https://github.com/DoctorWkt/acwj)\n- [saltwater](https://github.com/jyn514/saltwater)\n- [chibicc](https://github.com/rui314/chibicc)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPhilippRados%2Fwrecc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FPhilippRados%2Fwrecc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPhilippRados%2Fwrecc/lists"}