real machine script
This commit is contained in:
parent
78bbc32779
commit
cf582a0e74
45
README.md
45
README.md
@ -8,7 +8,37 @@
|
||||
|
||||
## 用法
|
||||
|
||||
目前没提供在 RISC-V 真机上运行和自举的脚本。下面是在其它平台设备上模拟的方案。
|
||||
如果你有 RISC-V 真机,可以采用真机运行,否则可以考虑模拟运行。两者行为应当是一致的。
|
||||
|
||||
### 真机运行
|
||||
|
||||
|
||||
编译运行程序,src 为本语言源代码。可以编译 demo 文件夹下的实例。
|
||||
|
||||
```sh
|
||||
$ sh run-native.sh <src>
|
||||
```
|
||||
|
||||
自举编译器,输出的文件位于 build 文件夹中。
|
||||
|
||||
```sh
|
||||
$ sh boot-native.sh
|
||||
```
|
||||
|
||||
输出六个文件:
|
||||
|
||||
| 源代码 | 编译器 | 汇编 | 可执行 | 命名 |
|
||||
| ----------------- | --------- | ------- | --------- | ---------------------- |
|
||||
| boot.c boot-lib.c | gcc | | gcc.out | 自制编译器 |
|
||||
| boot.c boot-lib.h | gcc.out | boot1.s | boot1.out | 自举自制编译器 |
|
||||
| boot.c boot-lib.h | boot1.out | boot2.s | boot2.out | 自举自举自制编译器 |
|
||||
| boot.c boot-lib.h | boot2.out | boot3.s | | 验证自举自举自制编译器 |
|
||||
|
||||
后三次编译时,boot-lib.h 的内容被手动导入 boot.c 开头进行编译,boot-lib.c 提供的库通过链接引入。
|
||||
|
||||
自举的目标为 boot1.s == boot2.s == boot3.s
|
||||
|
||||
### 模拟运行
|
||||
|
||||
安装以下依赖
|
||||
|
||||
@ -28,19 +58,6 @@ $ sh run.sh <src>
|
||||
$ sh boot.sh
|
||||
```
|
||||
|
||||
输出六个文件:
|
||||
|
||||
| 源代码 | 编译器 | 汇编 | 可执行 | 命名 |
|
||||
| ----------------- | --------- | ------- | --------- | ---------------------- |
|
||||
| boot.c boot-lib.c | gcc | | gcc.out | 自制编译器 |
|
||||
| boot.c boot-lib.h | gcc.out | boot1.s | boot1.out | 自举自制编译器 |
|
||||
| boot.c boot-lib.h | boot1.out | boot2.s | boot2.out | 自举自举自制编译器 |
|
||||
| boot.c boot-lib.h | boot2.out | boot3.s | | 验证自举自举自制编译器 |
|
||||
|
||||
后三次编译时,boot-lib.h 的内容被手动导入 boot.c 开头进行编译,boot-lib.c 提供的库通过链接引入。
|
||||
|
||||
自举的目标为 boot1.s == boot2.s == boot3.s
|
||||
|
||||
## 语言文档
|
||||
|
||||
### 关键字
|
||||
|
12
boot-native.sh
Normal file
12
boot-native.sh
Normal file
@ -0,0 +1,12 @@
|
||||
mkdir -p build && cd build &&
|
||||
cat ../boot-lib.h ../boot.c | sed '/^#/d' > boot-all.c &&
|
||||
gcc ../boot.c ../boot-lib.c -o gcc.out &&
|
||||
./gcc.out < boot-all.c > boot1.s &&
|
||||
gcc -static boot1.s ../boot-lib.c -o boot1.out &&
|
||||
./boot1.out < boot-all.c > boot2.s &&
|
||||
gcc -static boot2.s ../boot-lib.c -o boot2.out &&
|
||||
./boot2.out < boot-all.c > boot3.s &&
|
||||
cmp --silent boot1.s boot2.s && echo "boot1.s == boot2.s" || echo "boot1.s != boot2.s"
|
||||
cmp --silent boot2.s boot3.s && echo "boot2.s == boot3.s" || echo "boot2.s != boot3.s"
|
||||
cmp --silent boot1.s boot3.s && echo "boot1.s == boot3.s" || echo "boot1.s != boot3.s"
|
||||
rm boot-all.c
|
5
run-native.sh
Normal file
5
run-native.sh
Normal file
@ -0,0 +1,5 @@
|
||||
gcc boot.c boot-lib.c &&
|
||||
./a.out < $1 > $1.s &&
|
||||
gcc -static $1.s boot-lib.c -o $1.out &&
|
||||
./$1.out
|
||||
echo $?
|
Loading…
Reference in New Issue
Block a user