https://github.com/r7kamura/r8cc
A toy C compiler written in Rust.
https://github.com/r7kamura/r8cc
c-compiler
Last synced: over 1 year ago
JSON representation
A toy C compiler written in Rust.
- Host: GitHub
- URL: https://github.com/r7kamura/r8cc
- Owner: r7kamura
- License: mit
- Created: 2020-04-15T12:01:21.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-26T20:59:01.000Z (about 6 years ago)
- Last Synced: 2025-03-29T05:41:31.326Z (over 1 year ago)
- Topics: c-compiler
- Language: Rust
- Size: 55.7 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# r8cc
A toy C compiler written in Rust.
## Usage
`cargo run` takes a program and outputs assembly code that returns the calculated result.
```console
$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/r8cc`
Usage: r8cc
```
Compile given C-like code to assembly code:
```console
$ cargo run -- "int main() { return 1; }"
Compiling r8cc v0.1.0 (/Users/r7kamura/src/github.com/r7kamura/r8cc)
Finished dev [unoptimized + debuginfo] target(s) in 0.47s
Running `target/debug/r8cc 'int main() { return 1; }'`
.intel_syntax noprefix
.data
.global main
main:
push rbp
mov rbp, rsp
push 1
pop rax
mov rsp, rbp
pop rbp
ret
```
Assemble output by `cc`:
```console
$ cargo run -- "int main() { return 1; }" > tmp.s
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Running `target/debug/r8cc 'int main() { return 1; }'`
$ docker-compose run --rm base cc -o tmp tmp.s
$ docker-compose run --rm base ./tmp
$ echo $?
1
```
## Naming
*r8cc* is a successor of my [r7cc](https://github.com/r7kamura/r7cc).