@@ -24,7 +24,7 @@ def emit_func(
2424 ):
2525 from bloqade .qasm2 .dialects import glob , noise , parallel
2626
27- emit .run_ssacfg_region (frame , stmt .body )
27+ emit .run_ssacfg_region (frame , stmt .body , () )
2828 if emit .dialects .data .intersection (
2929 (parallel .dialect , glob .dialect , noise .dialect )
3030 ):
@@ -51,12 +51,14 @@ def emit_conditional_branch(
5151 self , emit : EmitQASM2Main , frame : EmitQASM2Frame , stmt : cf .ConditionalBranch
5252 ):
5353 cond = emit .assert_node (ast .Cmp , frame .get (stmt .cond ))
54- body_frame = emit .new_frame (stmt )
55- body_frame .entries .update (frame .entries )
56- body_frame .set_values (
57- stmt .then_successor .args , frame .get_values (stmt .then_arguments )
58- )
59- emit .emit_block (body_frame , stmt .then_successor )
54+
55+ with emit .new_frame (stmt ) as body_frame :
56+ body_frame .entries .update (frame .entries )
57+ body_frame .set_values (
58+ stmt .then_successor .args , frame .get_values (stmt .then_arguments )
59+ )
60+ emit .emit_block (body_frame , stmt .then_successor )
61+
6062 frame .body .append (
6163 ast .IfStmt (
6264 cond ,
@@ -91,15 +93,17 @@ def emit_if_else(
9193 )
9294
9395 cond = emit .assert_node (ast .Cmp , frame .get (stmt .cond ))
94- then_frame = emit .new_frame (stmt )
95- then_frame .entries .update (frame .entries )
96- emit .emit_block (then_frame , stmt .then_body .blocks [0 ])
97- frame .body .append (
98- ast .IfStmt (
99- cond ,
100- body = then_frame .body , # type: ignore
96+
97+ with emit .new_frame (stmt ) as then_frame :
98+ then_frame .entries .update (frame .entries )
99+ emit .emit_block (then_frame , stmt .then_body .blocks [0 ])
100+ frame .body .append (
101+ ast .IfStmt (
102+ cond ,
103+ body = then_frame .body , # type: ignore
104+ )
101105 )
102- )
106+
103107 term = stmt .then_body .blocks [0 ].last_stmt
104108 if isinstance (term , scf .Yield ):
105109 return then_frame .get_values (term .values )
0 commit comments