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

@@ -8,5 +8,5 @@
9 STORE_NAME 2 'b'
12 JUMP_FORWARD 0 '15'
15_0 COME_FROM '12'
15 LOAD_CONST 0 ''
15 LOAD_CONST 0 None
18 RETURN_VALUE

View File

@@ -11,5 +11,5 @@
6 15 LOAD_CONST 1 2
18 STORE_NAME 2 'd'
21_0 COME_FROM '12'
21 LOAD_CONST 2 ''
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)