Determine if two instructions are approximately equal, ignoring certain fields which we allow to differ, namely: * code objects are ignore (should probably be checked) due to address * line numbers :param i1: left instruction to compare :param i2: right instruction to comp
(i1, i2)
| 63 | |
| 64 | |
| 65 | def are_instructions_equal(i1, i2): |
| 66 | """ |
| 67 | Determine if two instructions are approximately equal, |
| 68 | ignoring certain fields which we allow to differ, namely: |
| 69 | |
| 70 | * code objects are ignore (should probably be checked) due to address |
| 71 | * line numbers |
| 72 | |
| 73 | :param i1: left instruction to compare |
| 74 | :param i2: right instruction to compare |
| 75 | |
| 76 | :return: True if the two instructions are approximately equal, otherwise False. |
| 77 | """ |
| 78 | result = ( |
| 79 | 1 == 1 |
| 80 | and i1.opname == i2.opname |
| 81 | and i1.opcode == i2.opcode |
| 82 | and i1.arg == i2.arg |
| 83 | # ignore differences due to code objects |
| 84 | # TODO : Better way of ignoring address |
| 85 | and (i1.argval == i2.argval or "<code object" in str(i1.argval)) |
| 86 | # TODO : Should probably recurse to check code objects |
| 87 | and (i1.argrepr == i2.argrepr or "<code object" in i1.argrepr) |
| 88 | and i1.offset == i2.offset |
| 89 | # ignore differences in line numbers |
| 90 | # and i1.starts_line |
| 91 | and i1.is_jump_target == i2.is_jump_target |
| 92 | ) |
| 93 | return result |
| 94 | |
| 95 | |
| 96 | def are_code_objects_equal(co1, co2): |
no outgoing calls
no test coverage detected