Overlap with raise Exc fix + helper method

This commit is contained in:
Xinlong Hu
2025-07-07 12:59:46 -05:00
parent d5a859e8b9
commit c7ac2dc18c
2 changed files with 14 additions and 2 deletions
@@ -1,5 +1,5 @@
from ..cft import ControlFlowTemplate, EdgeKind, register_template
from ..utils import T, N, defer_source_to, run_is, with_instructions, starting_instructions, to_indented_source, make_try_match, without_top_level_instructions
from ..utils import T, N, defer_source_to, run_is, with_instructions, has_instval, starting_instructions, to_indented_source, make_try_match, without_top_level_instructions
@register_template(1, 40)
@@ -46,7 +46,7 @@ class IfThen(ControlFlowTemplate):
class Assertion(ControlFlowTemplate):
template = T(
assertion=~N("fail", "tail"),
fail=+N().with_cond(starting_instructions("LOAD_ASSERTION_ERROR"), with_instructions("LOAD_GLOBAL", "RAISE_VARARGS")),
fail=+N().with_cond(starting_instructions("LOAD_ASSERTION_ERROR"), has_instval("LOAD_GLOBAL", argval = "AssertionError")),
tail=N.tail(),
)
@@ -118,6 +118,18 @@ def has_incoming_edge_of_categories(*categories: str):
return False
return check
def has_instval(opname: str, argval : Any):
def check_instructions(cfg: CFG, node: ControlFlowTemplate | None) -> bool:
ops = {x.opname : x.argval for x in node.get_instructions()}
for op in ops:
if ops[op] == argval:
return True
return False
return check_instructions
def run_is(n: int):
def check_run(cfg: CFG, node: ControlFlowTemplate | None) -> bool:
return cfg.run == n