Compare commits

...

2 Commits

Author SHA1 Message Date
1b98d599a1 coverage 2024-12-06 21:13:33 +08:00
bf7061a7df new head desc 2024-12-06 21:13:19 +08:00
4 changed files with 23 additions and 7 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
build build
cov
*.out *.out
*.o *.o
*.s *.s

View File

@ -1,10 +1,11 @@
# RVBTCC # RVBTCC
- 约 1900 行的轻量级自举编译器。 不到 2000 行的轻量级自举编译器。
- 编译器和自举编译器行为一致。
- 旨在展示如何迅速编写一个自举编译器。
- 语法类似 C输出 RISC-V 汇编。 - 语法类似 C输出 RISC-V 汇编。
- 依赖几个 libc 函数用于输入输出。 - 依赖几个 glibc 函数用于输入输出。
- 不使用动态内存分配,嵌入式友好 - 仅作学习用途,请勿在生产环境中使用
## 用法 ## 用法

15
boot.c
View File

@ -1,3 +1,14 @@
/*
* RVBTCC By Yaossg
* A lightweight bootstrapping compiler in less than 2000 lines.
*
* It aims to demonstrate how to write a bootstrapping compiler in no time.
* Syntax is similar to C, output is RISC-V assembly.
* Only dependent on some glibc functions for I/O.
* Purely for educational purposes. Do not use in production.
*
*/
// libc dependency // libc dependency
extern void* stdin; extern void* stdin;
@ -1140,9 +1151,7 @@ int parse_function_call(int id) {
int parse_primary_expr() { int parse_primary_expr() {
next_token(); next_token();
if (token_type == TOKEN_EOF) { if (token_type == TOKEN_NUMBER) {
exit(1);
} else if (token_type == TOKEN_NUMBER) {
return load_imm(token_data); return load_imm(token_data);
} else if (token_type == TOKEN_ID) { } else if (token_type == TOKEN_ID) {
next_token(); next_token();

5
cov.sh Normal file
View File

@ -0,0 +1,5 @@
mkdir -p cov && cd cov &&
rm *
gcc --coverage -g -O0 ../boot.c
./a.out < ../boot.c > /dev/null
gcov a-boot.c