add seek/tell on load in pysvp64dis so that generator can be reused
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 9 Sep 2022 15:25:31 +0000 (16:25 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 9 Sep 2022 15:25:31 +0000 (16:25 +0100)
src/openpower/sv/trans/pysvp64dis.py

index 38b4017d05a6f7e9466b1a95affdc02673f7fd72..135d9c0c8d3d119fa6dd114980680ab84f69a80a 100644 (file)
@@ -24,6 +24,7 @@ class ByteOrder(_enum.Enum):
 
 def load(ifile, byteorder=ByteOrder.LITTLE, **_):
     byteorder = str(byteorder)
+    curpos = ifile.tell() # get file position
 
     while True:
         insn = ifile.read(4)
@@ -49,6 +50,8 @@ 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
+
 
 def dump(insns, verbose, short=False, **_):
     db = _Database(_find_wiki_dir())