docs: add CFG 开发和设计文档 (Topic 11) - #41
Conversation
🤖 AI Code Review
📁
|
| 遇到 BR / BR_IF / RETURN → 结束当前块 | ||
| ``` | ||
|
|
||
| **边界情况**: 空函数返回空 CFG;连续 label 产生空块(保留);BR 后无 label 则自动命名 `b0`, `b1`...。 |
There was a problem hiding this comment.
CFG_Dev.md:96: "空指令列表返回含空 entry 块的 CFG(CFGNode(name=entry_name, instructions=[]))"
但是这里说返回空CFG。这两条不变量互相冲突,实现者无法同时满足。
|
|
||
| --- | ||
|
|
||
| ## 5. 接口契约 |
There was a problem hiding this comment.
函数式 API(partition_basic_blocks_with_names、build_cfg_from_instructions、cfg.successors…)与已跟踪旧实现 analysis/cfg_builder.py:205 的 CFGBuilder 类式 API(builder.build()、builder.compute_dominators(cfg))完全不同
|
|
||
| ### 4.1 基本块划分 | ||
|
|
||
| **输入**: `list[Instruction]` **输出**: `list[tuple[name, list[Instruction]]]` |
There was a problem hiding this comment.
文档假设:CFG_Design.md:189-199(§4.1)"输入 list[Instruction],遇到 LABEL → 结束当前块",CFG_Dev.md:86-91 签名 build_cfg_from_instructions(instructions: list[Instruction], ...)
仓库现实:
- types.py:143-166 Function.blocks: list[BasicBlock],已是结构化块,自带 name + instructions
- dsl_extended.py:180-246 用 new_block(then_label) 直接创建 BasicBlock,L186-191 发 BR_IF——全程无 LABEL 指令
- builder.py:139-146 br()/br_if() 直接以块名作 target,同样无 LABEL
- types.py:35 虽有 OpCode.LABEL,但前端从不生成它(grep 确认 dsl_parser/dsl_extended 无 LABEL 生成路径)
建议再确认一下
| outer.children.append(inner.header) | ||
| ``` | ||
|
|
||
| ### 4.5 边构建规则 |
There was a problem hiding this comment.
只覆盖:RETURN / BR / BR_IF / 无终止符,无 FOR/ENDFOR 行, 建议补充
sorry to rushing to hit the ddl qwq