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)
| 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 |
no test coverage detected