README.rst: note addition of pydisassemble

Remove duplicate disassembly printing from scanners and
put common code in caller(s). Show source-code line numbers in disassembly output
and fix alignment of byte offsets.
disas.py: workaround Python 2/3 different layouts before we get to
bytecodes in a code object.
This commit is contained in:
rocky
2015-12-15 01:42:07 -05:00
parent 5e5da104c5
commit 34ecd54e2c
11 changed files with 131 additions and 98 deletions

View File

@@ -11,8 +11,7 @@ from __future__ import print_function
import dis, marshal
from collections import namedtuple
from uncompyle6.scanner import Token
from uncompyle6.scanner import Token, L65536
# Get all the opcodes into globals
globals().update(dis.opmap)
@@ -62,14 +61,19 @@ class Scanner34(scan.Scanner):
# w/o touching arguments
current_token = Token(dis.opname[op])
current_token.offset = offset
current_token.linestart = True if offset in self.linestarts else False
if offset in self.linestarts:
current_token.linestart = self.linestarts[offset]
else:
current_token.linestart = None
if op >= dis.HAVE_ARGUMENT:
# Calculate op's argument value based on its argument and
# preceding extended argument, if any
oparg = code[offset+1] + code[offset+2]*256 + extended_arg
extended_arg = 0
if op == dis.EXTENDED_ARG:
extended_arg = oparg*65536
extended_arg = oparg * L65536
# Fill token's attr/pattr fields
current_token.attr = oparg