{"id":13503004,"url":"https://github.com/jyn514/saltwater","last_synced_at":"2025-10-21T04:46:47.048Z","repository":{"id":53073358,"uuid":"190940981","full_name":"jyn514/saltwater","owner":"jyn514","description":"A C compiler written in Rust, with a focus on good error messages.","archived":true,"fork":false,"pushed_at":"2021-06-03T02:53:48.000Z","size":2786,"stargazers_count":281,"open_issues_count":88,"forks_count":28,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-05-01T12:29:08.908Z","etag":null,"topics":["c","compiler","parser","rust","saltwater"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jyn514.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-08T22:26:45.000Z","updated_at":"2024-04-18T15:40:37.000Z","dependencies_parsed_at":"2022-09-11T15:41:16.769Z","dependency_job_id":null,"html_url":"https://github.com/jyn514/saltwater","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jyn514%2Fsaltwater","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jyn514%2Fsaltwater/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jyn514%2Fsaltwater/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jyn514%2Fsaltwater/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jyn514","download_url":"https://codeload.github.com/jyn514/saltwater/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246190168,"owners_count":20737985,"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","parser","rust","saltwater"],"created_at":"2024-07-31T22:02:33.170Z","updated_at":"2025-10-21T04:46:41.549Z","avatar_url":"https://github.com/jyn514.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# Saltwater\n\n[![Build Status](https://travis-ci.org/jyn514/rcc.svg?branch=master)](https://travis-ci.org/jyn514/rcc)\n[Join us on Discord](https://discord.gg/BPER7PF)\n\nsaltwater: the part of the sea causing lots of rust\n\nA C compiler written in Rust, with a focus on good error messages.\n\n---\n\n_**This project is no longer maintained.**_\n\n---\n\n## Running\n\n`swcc` reads from standard in by default, so you can type in code directly.\nIt's not interactive though, you have to hit Ctrl+D to indicate end of file (Ctrl+Z on Windows).\n\nUse `swcc --help` for all options (or see [below](#all-options)).\n\n### Running on Windows\n\nYou need to have `cc` on your PATH. You can either install mingw + gcc or MSVC.\nOther than that, it should work exactly the same as on Linux.\n\n### Homebrew\n\n```\nbrew install saltwater\n```\n\n## Unimplemented features\n\n- Defining functions taking variadic arguments. Note that calling variadic functions (like `printf`) is already supported.\n- Variable-length arrays (`int a[n]`)\n- Multiple translation units (files)\n- Bitfields\n- Compiling on non-x86 platforms\n- Cross-compilation\n\n## Examples\n\n```c\n$ cat tests/runner-tests/readme.c\n// output: j is 6\nint printf(const char *, ...);\n\ntypedef struct s *sp;\n\nint i = 1;\nint a[3] = {1, 2, 3};\nfloat f = 2.5;\n\nstruct s {\n  int outer;\n} my_struct;\n\nint g(int);\n\nint main(void) {\n  sp my_struct_pointer = \u0026my_struct;\n  const int c = my_struct_pointer-\u003eouter = 4;\n  // should return 6\n  int j = i + f*a[2] - c/g(1);\n  printf(\"j is %d\\n\", j);\n  return j;\n}\n\nint g(int i) {\n  if (i \u003c 0 || i \u003e= 3) {\n    return 0;\n  }\n  return a[i];\n}\n$ swcc tests/runner-tests/readme.c\n$️ ./a.out\nj is 6\n```\n\n### Debug output\n\n```c\n$ cat tests/runner-tests/cpp/if/defined.c\n// code: 2\n\n#define a\n#define b\n\n#if defined(a)\nint i = 2;\n#endif\n\n#ifndef b\nsyntax error\n#endif\n\n# if defined b \u0026\u0026 defined(a)\n    int main() { return i; }\n#endif\n$ swcc -E tests/runner-tests/cpp/if/defined.c\nint i = 2 ; int main ( ) { return i ; }\n```\n\n```c\n$ echo 'int i = 1 + 2 ^ 3 % 5 / 2 \u0026 1; int main(){}' | swcc --debug-ast\nast: int i = ((1) + (2)) ^ ((((3) % (5)) / (2)) \u0026 (1));\nast: int main(){\n}\n```\n\n```c\n$ cat tests/runner-tests/hello_world.c\n#include\u003cstdio.h\u003e\nint main() {\n    puts(\"Hello, world!\");\n}\n$ swcc --debug-ir tests/runner-tests/hello_world.c\nfunction u0:0() -\u003e i32 system_v {\n    gv0 = symbol colocated u1:3\n    sig0 = (i64) -\u003e i32 system_v\n    fn0 = u0:26 sig0\n\nblock0:\n    v0 = global_value.i64 gv0\n    v1 = call fn0(v0)\n    v2 = iconst.i32 0\n    return v2\n}\n$ ./a.out\nHello, world!\n```\n\n### All options\n\n```txt\n$ swcc --help\nswcc 0.9.0\nJynn Nelson \u003cgithub@jyn.dev\u003e\nA C compiler written in Rust, with a focus on good error messages.\nHomepage: https://github.com/jyn514/rcc/\n\nusage: swcc [FLAGS] [OPTIONS] [\u003cfile\u003e]\n\nFLAGS:\n        --debug-ast        If set, print the parsed abstract syntax tree (AST) in addition to compiling.\n                            The AST does no type checking or validation, it only parses.\n        --debug-hir        If set, print the high intermediate representation (HIR) in addition to compiling.\n                            This does type checking and validation and also desugars various expressions.\n        --debug-ir         If set, print the intermediate representation (IR) of the program in addition to compiling.\n        --debug-lex        If set, print all tokens found by the lexer in addition to compiling.\n        --jit              If set, will use JIT compilation for C code and instantly run compiled code (No files produced).\n                            NOTE: this option only works if swcc was compiled with the `jit` feature.\n    -h, --help             Prints help information\n    -c, --no-link          If set, compile and assemble but do not link. Object file is machine-dependent.\n    -E, --preprocess-only  If set, preprocess only, but do not do anything else.\n                            Note that preprocessing discards whitespace and comments.\n                            There is not currently a way to disable this behavior.\n    -V, --version          Prints version information\n\nOPTIONS:\n        --color \u003cwhen\u003e       When to use color. May be \"never\", \"auto\", or \"always\". [default: auto]\n    -o, --output \u003coutput\u003e    The output file to use. [default: a.out]\n        --max-errors \u003cmax\u003e   The maximum number of errors to allow before giving up.\n                             Use 0 to allow unlimited errors. [default: 10]\n    -I, --include \u003cdir\u003e      Add a directory to the local include path (`#include \"file.h\"`).\n                              Can be specified multiple times to add multiple directories.\n    -D, --define \u003cid[=val]\u003e  Define an object-like macro.\n                              Can be specified multiple times to add multiple macros.\n                              `val` defaults to `1`.\n\nARGS:\n    \u003cfile\u003e    The file to read C source from. \"-\" means stdin (use ./- to read a file called '-').\n              Only one file at a time is currently accepted. [default: -]\n```\n\n## Testing\n\n```sh\ncargo test\n# optionally, you can fuzz the compiler\n# it may be more helpful to just `grep -R unimplemented src`, though\n\n# libFuzzer/AFL\ntests/fuzz.sh\n\n# Honggfuzz:\n# Running Honggfuzz locally requires some parameters to use it at its full potential,\n# so it is probably a good idea to have a look here: https://github.com/rust-fuzz/honggfuzz-rs/blob/master/README.md\n# and here: https://github.com/google/honggfuzz/blob/master/docs/USAGE.md\n# we suggest the following:\nHFUZZ_RUN_ARGS=\"--tmout_sigvtalrm --exit_upon_crash\" tests/hfuzz.sh\n```\n\n## FAQ\n\nSee [FAQ.md](FAQ.md)\n\n## Implementation Defined Behavior\n\nSee [IMPLEMENTATION\\_DEFINED.md](IMPLEMENTATION_DEFINED.md)\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md).\nThis also includes reporting bugs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjyn514%2Fsaltwater","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjyn514%2Fsaltwater","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjyn514%2Fsaltwater/lists"}