Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/peng1999/sysy-rs
https://github.com/peng1999/sysy-rs
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/peng1999/sysy-rs
- Owner: peng1999
- Created: 2021-04-04T08:46:49.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-12-19T05:16:25.000Z (about 1 year ago)
- Last Synced: 2023-12-19T10:04:25.847Z (about 1 year ago)
- Language: Rust
- Size: 329 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 一个类 C 语言编译器(用 Rust 实现)
## 语法
实现了C++语法的一个子集,包括
- 函数
- 函数声明
- 数组
- `int` `bool` 变量
- `if` `while` 控制流函数默认为外部链接性,不支持重载,没有mangle。
## 示例
输入文件 `code.cpp`
```cpp
int putchar(int a);int main() {
putchar(48);
putchar(49);
return 0;
}
```利用LLVM后端进行编译:
```console
$ # 编译
$ cargo run -- -o code.o code.cpp
$ # 链接
$ gcc -o main code.o
$ ./main
01
```利用RISC-V后端进行编译:
```console
$ # 生成 RV32 汇编
$ cargo run -- --emit=riscv -o code.s code.cpp
$ # 编译链接
$ riscv32-unknown-elf-gcc -o main code.s$ qemu-riscv32 ./main
01
```