File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -43,10 +43,12 @@ def lower(
4343
4444 raw = textwrap .dedent (value )
4545 qasm_lowering = QASM2 (main .union ([ilist , glob , noise , parallel ]))
46- region = qasm_lowering .run (loads (raw ))
46+ region , defs = qasm_lowering .run (loads (raw ), return_defs = True )
4747 for qasm_stmt in region .blocks [0 ].stmts :
4848 qasm_stmt .detach ()
4949 state .current_frame .push (qasm_stmt )
50+
51+ state .current_frame .defs .update (defs )
5052
5153 for block in region .blocks :
5254 for qasm_stmt in block .stmts :
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ def run(
2727 lineno_offset : int = 0 ,
2828 col_offset : int = 0 ,
2929 compactify : bool = True ,
30+ return_defs : bool = False ,
3031 ) -> ir .Region :
3132 # TODO: add source info
3233 state = lowering .State (
@@ -56,14 +57,23 @@ def run(
5657 else :
5758 e .args = (hint ,)
5859 raise e
59-
60+
61+ if return_defs :
62+ defs = frame .defs .copy ()
63+
6064 region = frame .curr_region
6165
6266 if compactify :
6367 from kirin .rewrite import Walk , CFGCompactify
6468
6569 Walk (CFGCompactify ()).rewrite (region )
66- return region
70+
71+ if return_defs :
72+ # use this to update the current frame for python
73+ # lowering for inline qasm.
74+ return region , defs
75+ else :
76+ return region
6777
6878 def visit (self , state : lowering .State [ast .Node ], node : ast .Node ) -> lowering .Result :
6979 name = node .__class__ .__name__
You can’t perform that action at this time.
0 commit comments