From: Luke Kenneth Casson Leighton Date: Sat, 10 Sep 2022 23:54:29 +0000 (+0100) Subject: fix issue with pysvp64dis.py load() reading from stdin X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2ff083fd71e9526dfdc5f326649d370a1b0d8754;p=openpower-isa.git fix issue with pysvp64dis.py load() reading from stdin take a copy of the input and allow "seek()" on the copy (BytesIO) --- diff --git a/src/openpower/sv/trans/pysvp64dis.py b/src/openpower/sv/trans/pysvp64dis.py index 837041da..d5ddba91 100644 --- a/src/openpower/sv/trans/pysvp64dis.py +++ b/src/openpower/sv/trans/pysvp64dis.py @@ -2,6 +2,7 @@ import argparse as _argparse import enum as _enum import sys as _sys import os +from io import BytesIO from openpower.decoder.power_enums import ( find_wiki_dir as _find_wiki_dir, @@ -25,10 +26,14 @@ class ByteOrder(_enum.Enum): def load(ifile, byteorder=ByteOrder.LITTLE, **_): byteorder = str(byteorder) - curpos = ifile.tell() # get file position + + # copy over to persistent binfile (BytesIO) + cpfile = BytesIO() + cpfile.write(ifile.read()) + cpfile.seek(0) while True: - insn = ifile.read(4) + insn = cpfile.read(4) length = len(insn) if length == 0: return @@ -36,7 +41,7 @@ def load(ifile, byteorder=ByteOrder.LITTLE, **_): raise IOError(insn) insn = _WordInstruction.integer(value=insn, byteorder=byteorder) if insn.po == 0x1: - suffix = ifile.read(4) + suffix = cpfile.read(4) length = len(suffix) if length == 0: yield insn @@ -51,7 +56,7 @@ def load(ifile, byteorder=ByteOrder.LITTLE, **_): insn = _PrefixedInstruction.pair(prefix=prefix, suffix=suffix) yield insn - ifile.seek(curpos) # restore position so that generator can be reused + cpfile.seek(0) # restore position so that generator can be reused def dump(insns, verbosity, **_):