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,
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
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
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, **_):