Align disassembly output with xdis

align number of offset fields with xdis.
Show None type when we mean None, not ''
This commit is contained in:
rocky
2016-07-17 13:05:10 -04:00
parent ea733c31d7
commit 4a3a62d01b
4 changed files with 24 additions and 25 deletions

View File

@@ -1,12 +1,12 @@
# Python 2.7
# Embedded file name: simple_source/branching/05_if.py
6 0 LOAD_NAME 0 'True'
3 POP_JUMP_IF_FALSE 15 '15'
6 0 LOAD_NAME 0 'True'
3 POP_JUMP_IF_FALSE 15 '15'
7 6 LOAD_NAME 1 'False'
9 STORE_NAME 2 'b'
12 JUMP_FORWARD 0 '15'
15_0 COME_FROM '12'
15 LOAD_CONST 0 ''
18 RETURN_VALUE
7 6 LOAD_NAME 1 'False'
9 STORE_NAME 2 'b'
12 JUMP_FORWARD 0 '15'
15_0 COME_FROM '12'
15 LOAD_CONST 0 None
18 RETURN_VALUE

View File

@@ -1,15 +1,15 @@
# Python 2.7
# Embedded file name: simple_source/branching/05_ifelse.py
3 0 LOAD_NAME 0 'True'
3 POP_JUMP_IF_FALSE 15 '15'
3 0 LOAD_NAME 0 'True'
3 POP_JUMP_IF_FALSE 15 '15'
4 6 LOAD_CONST 0 1
9 STORE_NAME 1 'b'
12 JUMP_FORWARD 6 '21'
4 6 LOAD_CONST 0 1
9 STORE_NAME 1 'b'
12 JUMP_FORWARD 6 '21'
6 15 LOAD_CONST 1 2
18 STORE_NAME 2 'd'
21_0 COME_FROM '12'
21 LOAD_CONST 2 ''
24 RETURN_VALUE
6 15 LOAD_CONST 1 2
18 STORE_NAME 2 'd'
21_0 COME_FROM '12'
21 LOAD_CONST 2 None
24 RETURN_VALUE

View File

@@ -217,7 +217,7 @@ class Scanner2(scan.Scanner):
if show_asm in ('both', 'after'):
for t in tokens:
print(t)
print(t.format())
print()
return tokens, customize

View File

@@ -44,17 +44,16 @@ class Token:
def __str__(self):
pattr = self.pattr if self.pattr is not None else ''
prefix = '\n%4d ' % self.linestart if self.linestart else (' ' * 6)
prefix = '\n%3d ' % self.linestart if self.linestart else (' ' * 6)
return (prefix +
('%6s %-17s %r' % (self.offset, self.type, pattr)))
('%9s %-18s %r' % (self.offset, self.type, pattr)))
def format(self):
prefix = '\n%4d ' % self.linestart if self.linestart else (' ' * 6)
offset_opname = '%6s %-17s' % (self.offset, self.type)
prefix = '\n%3d ' % self.linestart if self.linestart else (' ' * 6)
offset_opname = '%9s %-18s' % (self.offset, self.type)
argstr = "%6d " % self.attr if isinstance(self.attr, int) else (' '*7)
pattr = self.pattr if self.pattr is not None else ''
if self.has_arg:
return "%s%s%s %r" % (prefix, offset_opname, argstr, pattr)
return "%s%s%s %r" % (prefix, offset_opname, argstr, self.pattr)
else:
return "%s%s" % (prefix, offset_opname)