You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
5.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

============================================================
脚本优化总结2026-04
============================================================
一、架构分离
────────────────────────────────────────────────────────────
· run_baseline.sh 成为唯一负责计算 GCC -O2 基线的脚本;
其余所有脚本lab3_build_test.sh、analyze_case.sh只读
TSV不再重复运行 GCC避免重复耗时。
· 基线输出目录镜像测试用例的相对路径结构,例如:
output/baseline/test_case/functional/65_color.gcc.s
output/baseline/class_test_case/h_functional/11_BST.gcc.s
TSV 键与目录结构对齐class_test_case/h_functional/11_BST
二、SysY → C 编译兼容性修复run_baseline.sh
────────────────────────────────────────────────────────────
· const int 全局数组维度问题
C 模式下 const int N=10; int a[N]; 属于 VLA非法于文件域
用 Python3 预处理将 const int NAME=EXPR; 转换为:
#define NAME ((int)(EXPR))
同时支持多声明符写法const int A=1, B=2;
· sylib 链接方式
预编译 sylib.o-x c用 -include sylib.h 注入声明;
链接命令用 -x none 在 .o 前重置语言标志,防止 ELF 被
当作 C 源文件解析stray '\177' 错误)。
· C++ 关键字冲突
部分 SysY 测试用例用 delete/new/class 作函数名;
-x c 模式下这些不是关键字,编译正常通过。
· 枚举浮点值
enum { MAX = 1e9 }; 枚举成员必须是整数常量Python3
预处理同样将其转为 #define MAX ((int)(1e9))。
三、计时精度与准确性
────────────────────────────────────────────────────────────
· 全面弃用 /usr/bin/time非零退出时会向输出文件写入
"Command exited with non-zero status N",污染时间值。
· 改用 date +%s%N 纳秒手动计时:
_t0=$(date +%s%N)
... 运行命令 ...
_t1=$(date +%s%N)
elapsed=$(awk "BEGIN{printf \"%.5f\", $((t1-t0)) / 1e9}")
· 所有时间输出统一为 5 位小数(秒),加速比同样 5 位小数。
四、分段计时verify_asm.sh + lab3_build_test.sh
────────────────────────────────────────────────────────────
· verify_asm.sh 新增 --timing-out <file> 选项,运行结束后
向文件写入:
compile_ns=<纳秒>
run_ns=<纳秒>
· lab3_build_test.sh 读取 timing 文件,将编译耗时与运行耗时
分开显示:
PASS test_case/functional/65_color [compile=0.31416s run=0.18804s]
· 加速比只使用运行时间run_ns排除编译器启动开销。
五、性能排行榜lab3_build_test.sh
────────────────────────────────────────────────────────────
· 测试结束后输出双排序表格:
Sort 1加速比升序最需优化的用例排最前
Sort 2我方用时降序绝对耗时最高的排最前
每行格式:
<用例名> <我方时间> <GCC时间> <加速比>x
六、analyze_case.sh 修复
────────────────────────────────────────────────────────────
· 基线查找键从裸 stem65_color改为完整路径键
test_case/functional/65_color与 TSV 格式对齐,
消除 "WARNING: no baseline entry" 误报。
· run_and_time 函数的 rpt_color 输出重定向到 stderr
防止 ANSI 转义码被命令替换($())捕获后传入 awk
消除 "fatal: error: invalid character '\033'" 错误。
============================================================
脚本列表
============================================================
run_baseline.sh 计算所有用例的 GCC -O2 基线,结果存入
output/baseline/gcc_timing.tsv
用法: ./scripts/run_baseline.sh [--update]
--update 清空重算全部条目
lab3_build_test.sh 构建编译器,跑全部用例,输出加速比排行榜
用法: ./scripts/lab3_build_test.sh
verify_asm.sh 验证单个用例的汇编正确性
用法: ./scripts/verify_asm.sh <input.sy> [input.in] \
[expected.out] [timeout] [--timing-out file]
analyze_case.sh 单用例深度分析IR/ASM/计时/与基线对比)
用法: ./scripts/analyze_case.sh <input.sy> [output_dir]
clean_outputs.sh 清理 output/ 目录下的分析结果
用法: ./scripts/clean_outputs.sh
============================================================