feat(mir): 增加 Lab3 AArch64 MVP 后端与 --emit-asm 支持
This commit is contained in:
67
scripts/verify_asm_with_qemu.sh
Executable file
67
scripts/verify_asm_with_qemu.sh
Executable file
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [[ $# -lt 1 || $# -gt 3 ]]; then
|
||||
echo "用法: $0 <input.sy> [output_dir] [--run]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
input=$1
|
||||
out_dir="out/asm"
|
||||
run_exec=false
|
||||
|
||||
shift
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--run)
|
||||
run_exec=true
|
||||
;;
|
||||
*)
|
||||
out_dir="$1"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ ! -f "$input" ]]; then
|
||||
echo "输入文件不存在: $input" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
compiler="./build/bin/compiler"
|
||||
if [[ ! -x "$compiler" ]]; then
|
||||
echo "未找到编译器: $compiler ,请先构建。" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then
|
||||
echo "未找到 aarch64-linux-gnu-gcc,无法汇编/链接。" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$out_dir"
|
||||
base=$(basename "$input")
|
||||
stem=${base%.sy}
|
||||
asm_file="$out_dir/$stem.s"
|
||||
exe="$out_dir/$stem.exe"
|
||||
|
||||
"$compiler" --emit-asm "$input" > "$asm_file"
|
||||
echo "汇编已生成: $asm_file"
|
||||
|
||||
aarch64-linux-gnu-gcc "$asm_file" -o "$exe"
|
||||
echo "可执行文件已生成: $exe"
|
||||
|
||||
if [[ "$run_exec" == true ]]; then
|
||||
if ! command -v qemu-aarch64 >/dev/null 2>&1; then
|
||||
echo "未找到 qemu-aarch64,无法运行生成的可执行文件。" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "运行 $exe ..."
|
||||
set +e
|
||||
qemu-aarch64 -L /usr/aarch64-linux-gnu "$exe"
|
||||
status=$?
|
||||
set -e
|
||||
echo "退出码: $status"
|
||||
fi
|
||||
Reference in New Issue
Block a user