@@ -82,125 +82,8 @@ def debug(s):
8282_Instruction = namedtuple ("_Instruction" , "opname, opcode, starts_line, argval, is_jump_target, offset, argrepr" )
8383
8484
85- def _iter_as_bytecode_as_instructions_py2 (co ):
86- code = co .co_code
87- op_offset_to_line = dict (dis .findlinestarts (co ))
88- labels = set (dis .findlabels (code ))
89- bytecode_len = len (code )
90- i = 0
91- extended_arg = 0
92- free = None
93-
94- op_to_name = opname
95-
96- while i < bytecode_len :
97- c = code [i ]
98- op = ord (c )
99- is_jump_target = i in labels
100-
101- curr_op_name = op_to_name [op ]
102- initial_bytecode_offset = i
103-
104- i = i + 1
105- if op < HAVE_ARGUMENT :
106- yield _Instruction (
107- curr_op_name ,
108- op ,
109- _get_line (op_offset_to_line , initial_bytecode_offset , 0 ),
110- None ,
111- is_jump_target ,
112- initial_bytecode_offset ,
113- "" ,
114- )
115-
116- else :
117- oparg = ord (code [i ]) + ord (code [i + 1 ]) * 256 + extended_arg
118-
119- extended_arg = 0
120- i = i + 2
121- if op == EXTENDED_ARG :
122- extended_arg = oparg * 65536
123-
124- if op in hasconst :
125- yield _Instruction (
126- curr_op_name ,
127- op ,
128- _get_line (op_offset_to_line , initial_bytecode_offset , 0 ),
129- co .co_consts [oparg ],
130- is_jump_target ,
131- initial_bytecode_offset ,
132- repr (co .co_consts [oparg ]),
133- )
134- elif op in hasname :
135- yield _Instruction (
136- curr_op_name ,
137- op ,
138- _get_line (op_offset_to_line , initial_bytecode_offset , 0 ),
139- co .co_names [oparg ],
140- is_jump_target ,
141- initial_bytecode_offset ,
142- str (co .co_names [oparg ]),
143- )
144- elif op in hasjrel :
145- argval = i + oparg
146- yield _Instruction (
147- curr_op_name ,
148- op ,
149- _get_line (op_offset_to_line , initial_bytecode_offset , 0 ),
150- argval ,
151- is_jump_target ,
152- initial_bytecode_offset ,
153- "to " + repr (argval ),
154- )
155- elif op in haslocal :
156- yield _Instruction (
157- curr_op_name ,
158- op ,
159- _get_line (op_offset_to_line , initial_bytecode_offset , 0 ),
160- co .co_varnames [oparg ],
161- is_jump_target ,
162- initial_bytecode_offset ,
163- str (co .co_varnames [oparg ]),
164- )
165- elif op in hascompare :
166- yield _Instruction (
167- curr_op_name ,
168- op ,
169- _get_line (op_offset_to_line , initial_bytecode_offset , 0 ),
170- cmp_op [oparg ],
171- is_jump_target ,
172- initial_bytecode_offset ,
173- cmp_op [oparg ],
174- )
175- elif op in hasfree :
176- if free is None :
177- free = co .co_cellvars + co .co_freevars
178- yield _Instruction (
179- curr_op_name ,
180- op ,
181- _get_line (op_offset_to_line , initial_bytecode_offset , 0 ),
182- free [oparg ],
183- is_jump_target ,
184- initial_bytecode_offset ,
185- str (free [oparg ]),
186- )
187- else :
188- yield _Instruction (
189- curr_op_name ,
190- op ,
191- _get_line (op_offset_to_line , initial_bytecode_offset , 0 ),
192- oparg ,
193- is_jump_target ,
194- initial_bytecode_offset ,
195- str (oparg ),
196- )
197-
198-
19985def iter_instructions (co ):
200- if sys .version_info [0 ] < 3 :
201- iter_in = _iter_as_bytecode_as_instructions_py2 (co )
202- else :
203- iter_in = dis .Bytecode (co )
86+ iter_in = dis .Bytecode (co )
20487 iter_in = list (iter_in )
20588
20689 bytecode_to_instruction = {}
@@ -327,7 +210,7 @@ def collect_try_except_info(co, use_func_first_line=False):
327210
328211 try_except_info_lst = []
329212
330- op_offset_to_line = dict (dis .findlinestarts (co ))
213+ op_offset_to_line = dict (entry for entry in dis .findlinestarts (co ) if entry [ 1 ] is not None )
331214
332215 offset_to_instruction_idx = {}
333216
@@ -445,7 +328,7 @@ def collect_try_except_info(co, use_func_first_line=False):
445328
446329 try_except_info_lst = []
447330
448- op_offset_to_line = dict (dis .findlinestarts (co ))
331+ op_offset_to_line = dict (entry for entry in dis .findlinestarts (co ) if entry [ 1 ] is not None )
449332
450333 offset_to_instruction_idx = {}
451334
@@ -645,7 +528,7 @@ def __init__(self, co, firstlineno, level=0):
645528 self .firstlineno = firstlineno
646529 self .level = level
647530 self .instructions = list (iter_instructions (co ))
648- op_offset_to_line = self .op_offset_to_line = dict (dis .findlinestarts (co ))
531+ op_offset_to_line = self .op_offset_to_line = dict (entry for entry in dis .findlinestarts (co ) if entry [ 1 ] is not None )
649532
650533 # Update offsets so that all offsets have the line index (and update it based on
651534 # the passed firstlineno).
0 commit comments