feat(peephole): reuse shared _asm_parser and harden match guards (topic13 track A) - #43
Conversation
Topic 13 track A follow-up on PR ScratchV-Compiler#39: drop duplicate asm parser, normalize x0/zero aliases, guard short-operand mv swap checks, and add design/dev docs plus regression tests. Co-authored-by: Cursor <cursoragent@cursor.com>
🤖 AI Code Review
📁
|
|
基于pr39, 新增了parser的复用以及相关测试用例, 看上去工作量其实并不大, 我们希望在第一轮提交文档阶段能够进行一些计划性的东西, 因为后续还有一些时间来实现, 所以希望能够增加一些关于ci方面的工作量。 真正能测 guard 的畸形输入应该是第二条短(走 len(window[1].operands) 检查),例如 mv a, b; mv c——但实测这个输入会被约束检查 src_op >= len 拦下(L292),同样不崩,且不会生成错误代码。而测试用的第一条短才是暴露 mv t1, x0 的路径。 |
Summary
scratchv/backend/_asm_parser.pyinsideasm_peephole(remove duplicate parser)redundant mv eliminationswap check (operand length guards)x0/zeroaliases in register constraint matching.globl main+ intent commentsBaseline
Based on PR #39 (
docs/topic13-peephole/d62acdf). This branch includes that tip plus track-A follow-ups. Please review in relation to #39.Test plan
pytest tests/test_asm_peephole*.py→ 88 passed