You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Track recent xdis changes
This commit is contained in:
@@ -48,8 +48,7 @@ class Scanner26(scan.Scanner2):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def ingest(self, co, classname=None, code_objects={}, show_asm=None):
|
def ingest(self, co, classname=None, code_objects={}, show_asm=None):
|
||||||
"""
|
"""Create "tokens" the bytecode of an Python code object. Largely these
|
||||||
Create "tokens" the bytecode of an Python code object. Largely these
|
|
||||||
are the opcode name, but in some cases that has been modified to make parsing
|
are the opcode name, but in some cases that has been modified to make parsing
|
||||||
easier.
|
easier.
|
||||||
returning a list of uncompyle6 Token's.
|
returning a list of uncompyle6 Token's.
|
||||||
@@ -57,14 +56,17 @@ class Scanner26(scan.Scanner2):
|
|||||||
Some transformations are made to assist the deparsing grammar:
|
Some transformations are made to assist the deparsing grammar:
|
||||||
- various types of LOAD_CONST's are categorized in terms of what they load
|
- various types of LOAD_CONST's are categorized in terms of what they load
|
||||||
- COME_FROM instructions are added to assist parsing control structures
|
- COME_FROM instructions are added to assist parsing control structures
|
||||||
- operands with stack argument counts or flag masks are appended to the opcode name, e.g.:
|
- operands with stack argument counts or flag masks are appended to the
|
||||||
|
opcode name, e.g.:
|
||||||
* BUILD_LIST, BUILD_SET
|
* BUILD_LIST, BUILD_SET
|
||||||
* MAKE_FUNCTION and FUNCTION_CALLS append the number of positional arguments
|
* MAKE_FUNCTION and FUNCTION_CALLS append the number of positional
|
||||||
|
arguments
|
||||||
- EXTENDED_ARGS instructions are removed
|
- EXTENDED_ARGS instructions are removed
|
||||||
|
|
||||||
Also, when we encounter certain tokens, we add them to a set which will cause custom
|
Also, when we encounter certain tokens, we add them to a set
|
||||||
grammar rules. Specifically, variable arg tokens like MAKE_FUNCTION or BUILD_LIST
|
which will cause custom grammar rules. Specifically, variable
|
||||||
cause specific rules for the specific number of arguments they take.
|
arg tokens like MAKE_FUNCTION or BUILD_LIST cause specific
|
||||||
|
rules for the specific number of arguments they take.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not show_asm:
|
if not show_asm:
|
||||||
|
@@ -221,7 +221,7 @@ class Scanner37Base(Scanner):
|
|||||||
|
|
||||||
if show_asm in ("both", "before"):
|
if show_asm in ("both", "before"):
|
||||||
print("\n# ---- before tokenization:")
|
print("\n# ---- before tokenization:")
|
||||||
bytecode.disassemble_bytes(
|
self.insts = bytecode.disassemble_bytes(
|
||||||
co.co_code,
|
co.co_code,
|
||||||
varnames=co.co_varnames,
|
varnames=co.co_varnames,
|
||||||
names=co.co_names,
|
names=co.co_names,
|
||||||
@@ -229,6 +229,9 @@ class Scanner37Base(Scanner):
|
|||||||
cells=bytecode._cell_names,
|
cells=bytecode._cell_names,
|
||||||
linestarts=bytecode._linestarts,
|
linestarts=bytecode._linestarts,
|
||||||
asm_format="extended",
|
asm_format="extended",
|
||||||
|
filename=co.co_filename,
|
||||||
|
show_source=True,
|
||||||
|
first_line_number=co.co_firstlineno,
|
||||||
)
|
)
|
||||||
|
|
||||||
# "customize" is in the process of going away here
|
# "customize" is in the process of going away here
|
||||||
@@ -302,6 +305,8 @@ class Scanner37Base(Scanner):
|
|||||||
inst.starts_line,
|
inst.starts_line,
|
||||||
inst.is_jump_target,
|
inst.is_jump_target,
|
||||||
inst.has_extended_arg,
|
inst.has_extended_arg,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get jump targets
|
# Get jump targets
|
||||||
@@ -348,9 +353,9 @@ class Scanner37Base(Scanner):
|
|||||||
j = tokens_append(
|
j = tokens_append(
|
||||||
j,
|
j,
|
||||||
Token(
|
Token(
|
||||||
come_from_name,
|
opname=come_from_name,
|
||||||
jump_offset,
|
attr=jump_offset,
|
||||||
repr(jump_offset),
|
pattr=repr(jump_offset),
|
||||||
offset="%s_%s" % (inst.offset, jump_idx),
|
offset="%s_%s" % (inst.offset, jump_idx),
|
||||||
has_arg=True,
|
has_arg=True,
|
||||||
opc=self.opc,
|
opc=self.opc,
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
# More could be done here though.
|
# More could be done here though.
|
||||||
|
|
||||||
from math import copysign
|
from math import copysign
|
||||||
from xdis.codetype import UnicodeForPython3
|
from xdis.cross_types import UnicodeForPython3
|
||||||
from xdis.version_info import PYTHON_VERSION_TRIPLE
|
from xdis.version_info import PYTHON_VERSION_TRIPLE
|
||||||
|
|
||||||
def get_code_name(code) -> str:
|
def get_code_name(code) -> str:
|
||||||
|
Reference in New Issue
Block a user