use elf as ext
This commit is contained in:
parent
4e591092db
commit
b4dbce76cf
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,7 +1,6 @@
|
||||
build
|
||||
cov
|
||||
a.out
|
||||
*.c.out
|
||||
*.o
|
||||
*.s
|
||||
*.ans
|
||||
*.elf
|
28
README.md
28
README.md
@ -11,28 +11,14 @@
|
||||
|
||||
如果你有 RISC-V 真机,可以采用真机运行,否则可以考虑模拟运行。两者行为应当是一致的。
|
||||
|
||||
### 真机运行
|
||||
|
||||
编译运行程序,src 为本语言源代码。可以编译 demo 或 test 文件夹下的实例。
|
||||
|
||||
```sh
|
||||
$ sh run-native.sh <src>
|
||||
```
|
||||
|
||||
自举编译器,输出的文件位于 build 文件夹中。
|
||||
|
||||
```sh
|
||||
$ sh boot-native.sh
|
||||
```
|
||||
|
||||
### 模拟运行
|
||||
|
||||
安装以下依赖
|
||||
如果是模拟运行,则需要安装以下依赖:
|
||||
|
||||
```sh
|
||||
sudo apt install gcc-12-riscv64-linux-gnu qemu-user qemu-system-misc
|
||||
```
|
||||
|
||||
如果是真机运行,则可以跳过这一步。
|
||||
|
||||
编译运行程序,src 为本语言源代码。可以编译 demo 或 test 文件夹下的实例。
|
||||
|
||||
```sh
|
||||
@ -52,10 +38,10 @@ $ sh boot.sh
|
||||
|
||||
| 源代码 | 编译器 | 汇编 | 可执行 | 代号 | 命名 |
|
||||
| ------ | --------- | ------- | --------- | ---- | ---------------------- |
|
||||
| boot.c | gcc | | gcc.out | G | 自制编译器 |
|
||||
| boot.c | gcc.out | boot1.s | boot1.out | B1 | 自举自制编译器 |
|
||||
| boot.c | boot1.out | boot2.s | boot2.out | B2 | 自举自举自制编译器 |
|
||||
| boot.c | boot2.out | boot3.s | | B3 | 验证自举自举自制编译器 |
|
||||
| boot.c | gcc | | gcc.elf | G | 自制编译器 |
|
||||
| boot.c | gcc.elf | boot1.s | boot1.elf | B1 | 自举自制编译器 |
|
||||
| boot.c | boot1.elf | boot2.s | boot2.elf | B2 | 自举自举自制编译器 |
|
||||
| boot.c | boot2.elf | boot3.s | | B3 | 验证自举自举自制编译器 |
|
||||
|
||||
除了第一次编译全程由 gcc 完成之外,另外三次编译从源码到汇编由本编译器完成,从汇编到可执行文件由 gcc 完成。从汇编到可执行文件时需要将 glibc 链接进去,这对于 gcc 来说是默认的行为。
|
||||
|
||||
|
@ -1,10 +0,0 @@
|
||||
mkdir -p build && cd build &&
|
||||
gcc ../boot.c -o gcc.out &&
|
||||
./gcc.out < ../boot.c > boot1.s &&
|
||||
gcc -static boot1.s -o boot1.out &&
|
||||
./boot1.out < ../boot.c > boot2.s &&
|
||||
gcc -static boot2.s -o boot2.out &&
|
||||
./boot2.out < ../boot.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"
|
12
boot.sh
12
boot.sh
@ -1,10 +1,10 @@
|
||||
mkdir -p build && cd build &&
|
||||
gcc ../boot.c -o gcc.out &&
|
||||
./gcc.out < ../boot.c > boot1.s &&
|
||||
riscv64-linux-gnu-gcc-12 -static boot1.s -o boot1.out &&
|
||||
qemu-riscv64 boot1.out < ../boot.c > boot2.s &&
|
||||
riscv64-linux-gnu-gcc-12 -static boot2.s -o boot2.out &&
|
||||
qemu-riscv64 boot2.out < ../boot.c > boot3.s
|
||||
gcc ../boot.c -o gcc.elf &&
|
||||
./gcc.elf < ../boot.c > boot1.s &&
|
||||
riscv64-linux-gnu-gcc-12 -static boot1.s -o boot1.elf &&
|
||||
qemu-riscv64 boot1.elf < ../boot.c > boot2.s &&
|
||||
riscv64-linux-gnu-gcc-12 -static boot2.s -o boot2.elf &&
|
||||
qemu-riscv64 boot2.elf < ../boot.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"
|
||||
|
@ -1,6 +1,6 @@
|
||||
mkdir -p cov && cd cov &&
|
||||
rm *
|
||||
gcc --coverage -g -O0 ../boot.c
|
||||
./a.out < ../boot.c > /dev/null
|
||||
gcov a-boot.c
|
||||
gcc --coverage -g -O0 ../boot.c -o boot.elf
|
||||
./boot.elf < ../boot.c > /dev/null
|
||||
gcov boot.elf-boot.c
|
||||
python3 -m gcovr --html-details --html-theme github.green -o report.html -r ..
|
||||
|
@ -1,11 +1,11 @@
|
||||
mkdir -p cov && cd cov &&
|
||||
rm *
|
||||
gcc --coverage -g -O0 ../boot.c
|
||||
gcc --coverage -g -O0 ../boot.c -o boot.elf
|
||||
for i in ../test/*.c; do
|
||||
i=$(basename $i .c)
|
||||
echo "Running coverage for test '$i'"
|
||||
./a.out < ../test/$i.c > /dev/null
|
||||
gcov a-boot.c
|
||||
./boot.elf < ../test/$i.c > /dev/null
|
||||
gcov boot.elf-boot.c
|
||||
done
|
||||
|
||||
python3 -m gcovr --html-details --html-theme github.green -o report.html -r ..
|
@ -1,5 +0,0 @@
|
||||
gcc boot.c &&
|
||||
./a.out < $1 > $1.s &&
|
||||
gcc -static $1.s -o $1.out &&
|
||||
./$1.out
|
||||
echo $?
|
10
run.sh
10
run.sh
@ -1,6 +1,6 @@
|
||||
gcc boot.c &&
|
||||
./a.out < $1 > $1.s &&
|
||||
riscv64-linux-gnu-gcc-12 -static $1.s -o $1.out &&
|
||||
qemu-riscv64 $1.out
|
||||
gcc boot.c -o boot.elf &&
|
||||
./boot.elf < $1 > $1.s &&
|
||||
riscv64-linux-gnu-gcc-12 -static $1.s -o $1.elf &&
|
||||
qemu-riscv64 $1.elf
|
||||
echo $?
|
||||
rm $1.s $1.out
|
||||
rm $1.s $1.elf boot.elf
|
||||
|
10
test.sh
10
test.sh
@ -1,13 +1,13 @@
|
||||
cd test
|
||||
gcc ../boot.c
|
||||
gcc ../boot.c -o boot.elf
|
||||
all=0
|
||||
succ=0
|
||||
for i in *.c; do
|
||||
all=$((all+1))
|
||||
i=$(basename $i .c)
|
||||
./a.out < $i.c > $i.s &&
|
||||
riscv64-linux-gnu-gcc-12 -static $i.s -o $i.c.out &&
|
||||
qemu-riscv64 $i.c.out < $i.in > $i.ans
|
||||
./boot.elf < $i.c > $i.s &&
|
||||
riscv64-linux-gnu-gcc-12 -static $i.s -o $i.elf &&
|
||||
qemu-riscv64 $i.elf < $i.in > $i.ans
|
||||
echo $? >> $i.ans
|
||||
if cmp $i.out $i.ans; then
|
||||
succ=$((succ+1))
|
||||
@ -19,4 +19,4 @@ for i in *.c; do
|
||||
fi
|
||||
done
|
||||
echo "Passed $succ/$all tests"
|
||||
rm *.c.out a.out
|
||||
rm *.elf
|
||||
|
Loading…
Reference in New Issue
Block a user