Skip to content

Commit

Permalink
xasm format fixes and fix one more ...
Browse files Browse the repository at this point in the history
version tuple compare
  • Loading branch information
rocky committed Nov 5, 2021
1 parent a485e79 commit 995eb20
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions xdis/instruction.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018-2020 by Rocky Bernstein
# Copyright (c) 2018-2021 by Rocky Bernstein
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -102,7 +102,7 @@ def disassemble(
# Column: Source code line number
if lineno_width:
if self.starts_line is not None:
if asm_format == "xasm":
if asm_format == "asm":
lineno_fmt = "%%%dd:\n" % lineno_width
fields.append(lineno_fmt % self.starts_line)
fields.append(" " * (lineno_width))
Expand All @@ -115,14 +115,14 @@ def disassemble(
fields.append(" " * (lineno_width + 1))

# Column: Current instruction indicator
if mark_as_current and asm_format != "xasm":
if mark_as_current and asm_format != "asm":
fields.append("-->")
else:
fields.append(" ")

# Column: Jump target marker
if self.is_jump_target:
if asm_format != "xasm":
if asm_format != "asm":
fields.append(">>")
else:
fields = ["L%d:\n" % self.offset] + fields
Expand All @@ -132,7 +132,7 @@ def disassemble(
fields.append(" ")

# Column: Instruction offset from start of code sequence
if asm_format != "xasm":
if asm_format != "asm":
fields.append(repr(self.offset).rjust(4))

# Column: Instruction bytes
Expand Down Expand Up @@ -160,20 +160,23 @@ def disassemble(
if self.arg is not None:
argrepr = self.argrepr
# The argrepr value when the instruction was created generally has all the information we require.
# However fo "xasm" format, want additional explicit information linking operands to tables.
# However fo "asm" format, want additional explicit information linking operands to tables.
if asm_format == "asm":
if self.optype == "jabs":
fields.append("L" + str(self.arg))
elif self.optype == "jrel":
argval = self.offset + self.arg + self.inst_size
fields.append("L" + str(argval))
elif self.optype in indexed_operand:
fields.append(repr(self.arg))
fields.append("(%s)" % argrepr)
argrepr = None
elif self.optype == "const" and not re.search(r"\s", argrepr):
fields.append(repr(self.arg))
fields.append("(%s)" % argrepr)
argrepr = None
elif self.optype == "const" and not re.search(r"\s", argrepr):
fields.append(repr(self.arg))
fields.append("(%s)" % argrepr)
argrepr = None
else:
Expand All @@ -191,8 +194,9 @@ def disassemble(
argrepr = new_repr
pass
if not argrepr:
fields.append(repr(self.arg))

if asm_format != "asm":
fields.append(repr(self.arg))
pass
else:
# Column: Opcode argument details
fields.append("(%s)" % argrepr)
Expand Down
2 changes: 1 addition & 1 deletion xdis/marsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __init__(self, writefunc, python_version=None):
self.python_version = python_version

def dump(self, x):
if isinstance(x, types.CodeType) and PYTHON_VERSION_TRIPLE != self.python_version:
if isinstance(x, types.CodeType) and PYTHON_VERSION_TRIPLE[:2] != self.python_version:
raise RuntimeError(
"code type passed for version %s but we are running version %s"
% (version_tuple_to_str(), self.python_version)
Expand Down

0 comments on commit 995eb20

Please sign in to comment.