Skip to content

Commit

Permalink
3.11 LOAD_ATTR extended formatting...
Browse files Browse the repository at this point in the history
ignore CACHE instructions.
And remove BINARY_xxx rutines. 3.11 uses BINARY_OP
  • Loading branch information
rocky committed Aug 20, 2023
1 parent 62563cd commit 698b2bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
21 changes: 12 additions & 9 deletions xdis/opcodes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,10 @@ def update_sets(loc):
def extended_format_binary_op(
opc, instructions, fmt_str: str, reverse_args=False
) -> Optional[str]:
stack_arg1 = instructions[1]
i = 1
while instructions[i].opname == "CACHE":
i += 1
stack_arg1 = instructions[i]
arg1 = None
if stack_arg1.formatted is not None:
arg1 = stack_arg1.formatted
Expand All @@ -323,17 +326,17 @@ def extended_format_binary_op(
):
if arg1 is None:
arg1 = instructions[1].argrepr
i = 2
while instructions[i].opname == "CACHE":
i += 1
j = i + 1
while instructions[j].opname == "CACHE":
j += 1
if (
instructions[i].opcode in opc.NAME_OPS | opc.CONST_OPS | opc.LOCAL_OPS
and instructions[1].opcode in opc.NAME_OPS | opc.CONST_OPS | opc.LOCAL_OPS
instructions[j].opcode in opc.NAME_OPS | opc.CONST_OPS | opc.LOCAL_OPS
and instructions[i].opcode in opc.NAME_OPS | opc.CONST_OPS | opc.LOCAL_OPS
):
if reverse_args:
args = (arg1, instructions[i].argrepr)
args = (arg1, instructions[j].argrepr)
else:
args = (instructions[i].argrepr, arg1)
args = (instructions[j].argrepr, arg1)
return fmt_str % args
else:
return fmt_str % ("...", arg1)
Expand All @@ -349,7 +352,7 @@ def extended_format_unary_op(opc, instructions, fmt_str: str) -> Optional[str]:


def extended_format_ATTR(opc, instructions):
if instructions[1].opcode in opc.NAME_OPS | opc.CONST_OPS:
if instructions[1].opcode in opc.NAME_OPS | opc.CONST_OPS | opc.LOCAL_OPS:
return "%s.%s" % (instructions[1].argrepr, instructions[0].argrepr)


Expand Down
10 changes: 1 addition & 9 deletions xdis/opcodes/opcode_311.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
from xdis.opcodes.base import (
def_op,
extended_format_ATTR,
extended_format_BINARY_ADD,
extended_format_BINARY_MODULO,
extended_format_BINARY_SUBSCR,
extended_format_BINARY_SUBTRACT,
extended_format_COMPARE_OP,
extended_format_RETURN_VALUE,
finalize_opcodes,
Expand Down Expand Up @@ -107,7 +103,7 @@
#---------------------------------------------------------
# replaced binary and inplace ops
def_op(l, "CACHE", 0, 0, 0)
def_op(l, "BINARY_OP", 122, 2, 1)
binary_op(l, "BINARY_OP", 122)
# call ops
def_op(l, "CALL", 171, 1, 0)
def_op(l, "KW_NAMES", 172, 0, 0)
Expand Down Expand Up @@ -196,10 +192,6 @@ def format_extended_contains_op(arg):
}

opcode_extended_fmt = {
"BINARY_SUBSCR": extended_format_BINARY_SUBSCR,
"BINARY_SUBTRACT": extended_format_BINARY_SUBTRACT,
"BINARY_ADD": extended_format_BINARY_ADD,
"BINARY_MODULO": extended_format_BINARY_MODULO,
"CALL_FUNCTION": extended_format_CALL_FUNCTION,
"CALL_METHOD": extended_format_CALL_METHOD,
"COMPARE_OP": extended_format_COMPARE_OP,
Expand Down

0 comments on commit 698b2bb

Please sign in to comment.