You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Double -a option show asm before tokenization
This commit is contained in:
@@ -11,7 +11,9 @@ import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
from xdis.version_info import version_tuple_to_str
|
||||
from uncompyle6 import verify
|
||||
from uncompyle6.main import main, status_msg
|
||||
from uncompyle6.version import __version__
|
||||
|
||||
program = "uncompyle6"
|
||||
|
||||
@@ -69,10 +71,6 @@ Extensions of generated files:
|
||||
|
||||
program = "uncompyle6"
|
||||
|
||||
from uncompyle6 import verify
|
||||
from uncompyle6.main import main, status_msg
|
||||
from uncompyle6.version import __version__
|
||||
|
||||
|
||||
def usage():
|
||||
print(__doc__)
|
||||
@@ -102,7 +100,9 @@ def main_bin():
|
||||
print("%s: %s" % (os.path.basename(sys.argv[0]), e), file=sys.stderr)
|
||||
sys.exit(-1)
|
||||
|
||||
options = {}
|
||||
options = {
|
||||
"showasm": None
|
||||
}
|
||||
for opt, val in opts:
|
||||
if opt in ("-h", "--help"):
|
||||
print(__doc__)
|
||||
@@ -121,7 +121,10 @@ def main_bin():
|
||||
elif opt == "--linemaps":
|
||||
options["do_linemaps"] = True
|
||||
elif opt in ("--asm", "-a"):
|
||||
if options["showasm"] == None:
|
||||
options["showasm"] = "after"
|
||||
else:
|
||||
options["showasm"] = "both"
|
||||
options["do_verify"] = None
|
||||
elif opt in ("--tree", "-t"):
|
||||
if "showast" not in options:
|
||||
@@ -227,6 +230,8 @@ def main_bin():
|
||||
|
||||
rqueue = Queue(numproc)
|
||||
|
||||
tot_files = okay_files = failed_files = verify_failed_files = 0
|
||||
|
||||
def process_func():
|
||||
try:
|
||||
(tot_files, okay_files, failed_files, verify_failed_files) = (
|
||||
|
@@ -17,7 +17,7 @@ import datetime
|
||||
import os
|
||||
import py_compile
|
||||
import sys
|
||||
from typing import Any, Tuple
|
||||
from typing import Any, Optional, Tuple
|
||||
|
||||
from xdis import iscode
|
||||
from xdis.load import load_module
|
||||
@@ -50,7 +50,7 @@ def decompile(
|
||||
co,
|
||||
bytecode_version: Tuple[int] = PYTHON_VERSION_TRIPLE,
|
||||
out=sys.stdout,
|
||||
showasm=None,
|
||||
showasm: Optional[str]=None,
|
||||
showast={},
|
||||
timestamp=None,
|
||||
showgrammar=False,
|
||||
@@ -107,14 +107,11 @@ def decompile(
|
||||
if source_size:
|
||||
write("# Size of source mod 2**32: %d bytes" % source_size)
|
||||
|
||||
# maybe a second -a will do before as well
|
||||
asm = "after" if showasm else None
|
||||
|
||||
grammar = dict(PARSER_DEFAULT_DEBUG)
|
||||
if showgrammar:
|
||||
grammar["reduce"] = True
|
||||
|
||||
debug_opts = {"asm": asm, "tree": showast, "grammar": grammar}
|
||||
debug_opts = {"asm": showasm, "tree": showast, "grammar": grammar}
|
||||
|
||||
try:
|
||||
if mapstream:
|
||||
@@ -244,7 +241,7 @@ def main(
|
||||
compiled_files: list,
|
||||
source_files: list,
|
||||
outfile=None,
|
||||
showasm=None,
|
||||
showasm: Optional[str] = None,
|
||||
showast={},
|
||||
do_verify=False,
|
||||
showgrammar=False,
|
||||
|
@@ -205,10 +205,17 @@ class Scanner2(Scanner):
|
||||
|
||||
bytecode = self.build_instructions(co)
|
||||
|
||||
# show_asm = 'after'
|
||||
if show_asm in ("both", "before"):
|
||||
for instr in bytecode.get_instructions(co):
|
||||
print(instr.disassemble())
|
||||
print("\n# ---- before tokenization:")
|
||||
bytecode.disassemble_bytes(
|
||||
co.co_code,
|
||||
varnames=co.co_varnames,
|
||||
names=co.co_names,
|
||||
constants=co.co_consts,
|
||||
cells=bytecode._cell_names,
|
||||
linestarts=bytecode._linestarts,
|
||||
asm_format="extended",
|
||||
)
|
||||
|
||||
# list of tokens/instructions
|
||||
new_tokens = []
|
||||
@@ -483,6 +490,7 @@ class Scanner2(Scanner):
|
||||
pass
|
||||
|
||||
if show_asm in ("both", "after"):
|
||||
print("\n# ---- after tokenization:")
|
||||
for t in new_tokens:
|
||||
print(t.format(line_prefix=""))
|
||||
print()
|
||||
|
@@ -414,8 +414,16 @@ class Scanner3(Scanner):
|
||||
|
||||
# show_asm = 'both'
|
||||
if show_asm in ("both", "before"):
|
||||
for instr in bytecode.get_instructions(co):
|
||||
print(instr.disassemble())
|
||||
print("\n# ---- before tokenization:")
|
||||
bytecode.disassemble_bytes(
|
||||
co.co_code,
|
||||
varnames=co.co_varnames,
|
||||
names=co.co_names,
|
||||
constants=co.co_consts,
|
||||
cells=bytecode._cell_names,
|
||||
linestarts=bytecode._linestarts,
|
||||
asm_format="extended",
|
||||
)
|
||||
|
||||
# "customize" is in the process of going away here
|
||||
customize = {}
|
||||
@@ -777,6 +785,7 @@ class Scanner3(Scanner):
|
||||
pass
|
||||
|
||||
if show_asm in ("both", "after"):
|
||||
print("\n# ---- after tokenization:")
|
||||
for t in new_tokens:
|
||||
print(t.format(line_prefix=""))
|
||||
print()
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2015-2020, 2022 by Rocky Bernstein
|
||||
# Copyright (c) 2015-2020, 2022-2023 by Rocky Bernstein
|
||||
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
|
||||
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
||||
#
|
||||
@@ -219,10 +219,17 @@ class Scanner37Base(Scanner):
|
||||
|
||||
bytecode = self.build_instructions(co)
|
||||
|
||||
# show_asm = 'both'
|
||||
if show_asm in ("both", "before"):
|
||||
for instr in bytecode.get_instructions(co):
|
||||
print(instr.disassemble(self.opc))
|
||||
print("\n# ---- before tokenization:")
|
||||
bytecode.disassemble_bytes(
|
||||
co.co_code,
|
||||
varnames=co.co_varnames,
|
||||
names=co.co_names,
|
||||
constants=co.co_consts,
|
||||
cells=bytecode._cell_names,
|
||||
linestarts=bytecode._linestarts,
|
||||
asm_format="extended",
|
||||
)
|
||||
|
||||
# "customize" is in the process of going away here
|
||||
customize = {}
|
||||
@@ -525,6 +532,7 @@ class Scanner37Base(Scanner):
|
||||
pass
|
||||
|
||||
if show_asm in ("both", "after"):
|
||||
print("\n# ---- after tokenization:")
|
||||
for t in tokens:
|
||||
print(t.format(line_prefix=""))
|
||||
print()
|
||||
|
Reference in New Issue
Block a user