https://github.com/gifnksm/gifcc
Tiny c compiler
https://github.com/gifnksm/gifcc
c compiler self-hosted toy-project
Last synced: about 2 months ago
JSON representation
Tiny c compiler
- Host: GitHub
- URL: https://github.com/gifnksm/gifcc
- Owner: gifnksm
- License: mit
- Created: 2019-01-07T06:58:41.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-09-14T00:34:40.000Z (almost 6 years ago)
- Last Synced: 2024-11-09T23:02:26.444Z (7 months ago)
- Topics: c, compiler, self-hosted, toy-project
- Language: C
- Size: 913 KB
- Stars: 58
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- AwesomeCompiler - gifcc
README
# gifcc [](https://circleci.com/gh/gifnksm/gifcc) [](https://codecov.io/gh/gifnksm/gifcc)
"gifcc" is a self-hosted C compiler written by gifnksm.
## Features
* emit x86_64 assembly (AT&T syntax or Intel syntax)
* self-hosted
* Many C11 features
* Some GNU syntax extension## Compiler Stages
gifcc build process has 3 stages.
* stage1: gifcc binary built with system's C compiler (gcc)
* stage2: gifcc binary built with stage1 gifcc
* stage3: gifcc binary built with stage2 gifccIf gifcc compiles C source code correctly, stage2 binary and stage3 binary will be identical.
## Requirements
* C development tools (gcc, GNU Make, ...)
* python3
* [TMSU](https://github.com/oniony/TMSU) (for running c-testsuite)## Operations
* Build stage1, 2, 3 compiler
```console
$ make stage1
...
$ make stage2
...
$ make stage3
...
```* Run basic tests for each stages
```console
$ make stage1-test
...
$ make stage2-test
...
$ make stage3-test
...
```* Run all tests for each stages
```console
$ make stage1-test-full
...
$ make stage2-test-full
...
$ make stage3-test-full
...
```## Special Thanks
* [低レイヤを知りたい人のためのCコンパイラ作成入門](https://www.sigbus.info/compilerbook)
* [できる! コンパイラ作成の資料まとめ](https://anqou.net/poc/2019/01/03/post-2650/)
* [Compiler Explorer](https://godbolt.org/)
* [Wandbox](https://wandbox.org/)
* [Dave Prosser's C Preprocessing Algorithm](https://www.spinellis.gr/blog/20060626/)
* [c-testsuite](https://github.com/c-testsuite/c-testsuite)## References
* [Programming languages — C](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf)
* [x86 and amd64 instruction reference](https://www.felixcloutier.com/x86/index.html)
* [System V Application Binary Interface](https://www.uclibc.org/docs/psABI-x86_64.pdf)
* [GNU as](https://sourceware.org/binutils/docs/as/)