3636 store_op ,
3737 update_pj3 ,
3838)
39- from xdis .opcodes .format .extended import extended_format_binary_op
39+ from xdis .opcodes .format .extended import (
40+ NULL_EXTENDED_OP ,
41+ extended_format_binary_op ,
42+ extended_format_unary_op ,
43+ )
4044from xdis .opcodes .opcode_310 import opcode_arg_fmt310 , opcode_extended_fmt310
4145
4246version_tuple = (3 , 11 )
@@ -245,6 +249,21 @@ def extended_format_BINARY_OP(opc, instructions) -> Tuple[str, Optional[int]]:
245249 return extended_format_binary_op (opc , instructions , f"%s { opname } %s" )
246250
247251
252+ def extended_format_COPY_OP (
253+ opc , instructions : List [Instruction ]
254+ ) -> Tuple [str , Optional [int ]]:
255+ """Try to extract TOS value and show that surrounded in a "push() ".
256+ The trailing space at the used as a sentinal for `get_instruction_tos_str()`
257+ which tries to remove the push() part when the operand value string is needed.
258+ """
259+
260+ # We add a space at the end as a sentinal to use in get_instruction_tos_str()
261+ if instructions [1 ].optype not in ["jrel" , "jabs" ]:
262+ return extended_format_unary_op (opc , instructions , "copy(%s) " )
263+ else :
264+ return NULL_EXTENDED_OP
265+
266+
248267def extended_format_SWAP (
249268 opc , instructions : List [Instruction ]
250269) -> Tuple [str , Optional [int ]]:
@@ -263,12 +282,13 @@ def extended_format_SWAP(
263282 i = swap_instr .argval
264283 # s = ""
265284
266- if ( i is None or not (0 < i < len (instructions ) )):
285+ if i is None or not (0 < i < len (instructions )):
267286 return "" , None
268287
269288 # To be continued
270289 return "" , None
271290
291+
272292def format_BINARY_OP (arg : int ) -> str :
273293 return _nb_ops [arg ][1 ]
274294
@@ -294,6 +314,7 @@ def format_SWAP_OP(arg: int) -> str:
294314 ** opcode_extended_fmt310 ,
295315 ** {
296316 "BINARY_OP" : extended_format_BINARY_OP ,
317+ "COPY" : extended_format_COPY_OP ,
297318 },
298319}
299320
0 commit comments