{"id":19297280,"url":"https://github.com/hsjoihs/c-compiler","last_synced_at":"2025-04-22T09:30:30.403Z","repository":{"id":55720658,"uuid":"140148694","full_name":"hsjoihs/c-compiler","owner":"hsjoihs","description":"seccamp2018 c compiler","archived":false,"fork":false,"pushed_at":"2022-08-11T10:36:53.000Z","size":3274,"stargazers_count":53,"open_issues_count":0,"forks_count":1,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-11-09T23:02:27.639Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hsjoihs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-08T07:59:23.000Z","updated_at":"2024-07-21T15:17:42.000Z","dependencies_parsed_at":"2022-08-15T06:31:31.944Z","dependency_job_id":null,"html_url":"https://github.com/hsjoihs/c-compiler","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/hsjoihs%2Fc-compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsjoihs%2Fc-compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsjoihs%2Fc-compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hsjoihs%2Fc-compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hsjoihs","download_url":"https://codeload.github.com/hsjoihs/c-compiler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250214936,"owners_count":21393699,"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-11-09T23:01:50.238Z","updated_at":"2025-04-22T09:30:29.952Z","avatar_url":"https://github.com/hsjoihs.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# c-compiler\nseccamp2018 c compiler\n\n[日記](https://github.com/hsjoihs/c-compiler/blob/master/misc/diary.md)\n\nIn case you are also making a toy C compiler, feel free to use [my test cases](./test_cases.sh) to test yours. I also have [negative test cases](./test_compile_error.sh), a list of inputs to which a C compiler should report an error. [test_cases_that_are_compile_error_only_if_pedantic.sh](./test_cases_that_are_compile_error_only_if_pedantic.sh) contains non-ISO extensions commonly implemented in many C compilers. hsjoihs-c-compiler reports an error with respect to those cases only when `-pedantic` is passed.\n\n## Environment\n\nTested on macOS (Catalina), Ubuntu (20.04.1 LTS) and Debian (10.5).\n\n## How to run\n\nAfter cloning, run:\n\n```\n$ make\n```\n\nto compile.\n\nThe compiler can be run as \n\n```\n$ cat input.c | ./out/compiler.out -DOSX -DOVERRIDE_STD \u003e s/output.s\n```\n\nor as\n\n```\n$ ./out/compiler.out -DOSX -DOVERRIDE_STD input.c \u003e s/output.s\n```\n\nfor macOS; replace `-DOSX` with `-DLINUX` for Ubuntu. Note that, in Ubuntu, the generated assembly requires\n`-no-pie` to be passed to gcc in order for the linking to succeed.\n\n\nTo self-compile, run \n\n```\n$ make 2ndgen\n```\n\n; this will overwrite `./out/compiler.out`.\n\n## How to test\n\nRun\n\n```\n$ make test_2ndgen_compiler\n```\n\nto test the self-compiled compiler. To test some more, run \n\n```\n$ make test_all_\n```\n\n## Fun samples\n\n### Conway's game of life \n\nBased on https://gist.github.com/maekawatoshiki/8ea2f392e22698593d7ee8522aabbbd0\n\n```\n$ make game_of_life\n```\n\n### Calculating digits of pi / e \n\nBased on https://xn--w6q13e505b.jp/program/spigot.html\n```\n$ make pi\n```\n\n```\n$ make digits_of_e\n```\n\n### Donut\n\n```\n$ make donut\n```\n\nThe following is the source code, which is greatly modified from [the original](https://www.a1k0n.net/2011/07/20/donut-math.html) to avoid floating-point calculations\n\n```c\n                   int putchar();void*\n               memset();int m(int a,int b)\n            {return (a*b+5000)/10000;}void a(\n          int*c,int*s,int d,int t){int k=m(*c,d\n        )-m(*s,t);int l=m(*s,d)+m(*c,t);*c=k;*s=l\n      ;}int usleep();int printf();int main(){int z[\n     1760];char b[1760];printf(\"\\e[2J\");int s=10000;\n    int q=s;int r=0;int u=s;int v=0;for(;;a(\u0026q,\u0026r,s-8\n   ,400),a(\u0026u,\u0026v,s-2,200)){memset(b,32,1760);memset(z,\n  0,7040);int l=0;int p           =s;for(int i=0;i\u003c88;i\n  ++,a(\u0026p,\u0026l,9974+i%                 2,714)){int w=0;int\n e=s;for(int j=0;j\u003c                   314;j++,a(\u0026e,\u0026w,s-\n 2,200)){int f=p+2                     *s;int g=s*s/(m(m\n(w,f),r)+m(l,q)+5*                     s);int t=m(m(w,q),\nf)-m(l,r);int x=40                     +30*m(g,m(m(e,u),f\n )-m(t,v))/s;int y                     =12+15*m(g,m(m(e, \n v),f)+m(t,u))/s;int                   o=x+80*y;int N=8* \n  (m(m(l,r)-m(m(w,q)                ,p),u)-m(m(w,r),p)-  \n  m(l,q)-m(m(e,v),p))/s           ;if(y\u003e0\u0026\u0026g\u003ez[o]\u0026\u0026y\u003c22  \n   \u0026\u0026x\u003e0\u0026\u002680\u003ex){z[o]=g;b[o]=\".,-~:;=!*#$@\"[N\u003e=1?N:0]+0\n    ;}}}printf(\"\\e[H\");for(int k=0;k\u003c1761;k++)putchar\n     (k%80?b[k]:10);printf(\"Author: @a1k0n. Rewritt\"\n      \"en by @hsjoihs so that it works without flo\"\n        );https://github.com/hsjoihs/c-compiler/\n          printf(\"ating types.\\nNote that roun\"\n            \"ding errors gradually reduce th\"\n               \"e donut's size.\\n\");usleep\n                   (50000);}return 0;}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhsjoihs%2Fc-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhsjoihs%2Fc-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhsjoihs%2Fc-compiler/lists"}