MCPcopy
hub / github.com/rocky/python-uncompyle6 / first_instr

Method first_instr

uncompyle6/scanner.py:338–370  ·  view source on GitHub ↗

Find the first in the block from start to end. is any python bytecode instruction or a list of opcodes If is an opcode with a target (like a jump), a target destination can be specified which must match precisely if exact is True, or i

(self, start: int, end: int, instr, target=None, exact=True)

Source from the content-addressed store, hash-verified

336 return xdis.next_offset(op, self.opc, offset)
337
338 def first_instr(self, start: int, end: int, instr, target=None, exact=True):
339 """
340 Find the first <instr> in the block from start to end.
341 <instr> is any python bytecode instruction or a list of opcodes
342 If <instr> is an opcode with a target (like a jump), a target
343 destination can be specified which must match precisely if exact
344 is True, or if exact is False, the instruction which has a target
345 closest to <target> will be returned.
346
347 Return index to it or None if not found.
348 """
349 code = self.code
350 assert start >= 0 and end <= len(code)
351
352 if not isinstance(instr, list):
353 instr = [instr]
354
355 result_offset = None
356 current_distance = len(code)
357 for offset in self.op_range(start, end):
358 op = code[offset]
359 if op in instr:
360 if target is None:
361 return offset
362 dest = self.get_target(offset)
363 if dest == target:
364 return offset
365 elif not exact:
366 new_distance = abs(target - dest)
367 if new_distance < current_distance:
368 current_distance = new_distance
369 result_offset = offset
370 return result_offset
371
372 def last_instr(
373 self, start: int, end: int, instr, target=None, exact=True

Callers 3

next_except_jumpMethod · 0.80
next_except_jumpMethod · 0.80
next_except_jumpMethod · 0.80

Calls 2

op_rangeMethod · 0.95
get_targetMethod · 0.95

Tested by

no test coverage detected