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,
)
from openpower.decoder.power_insn import (
+ Verbosity as _Verbosity,
Database as _Database,
WordInstruction as _WordInstruction,
PrefixedInstruction as _PrefixedInstruction,
def load(ifile, byteorder=ByteOrder.LITTLE, **_):
byteorder = str(byteorder)
+ # 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
+ cpfile.seek(0) # restore position so that generator can be reused
+
-def dump(insns, verbose, short=False, **_):
+def dump(insns, verbosity, **_):
db = _Database(_find_wiki_dir())
for insn in insns:
- yield from insn.disassemble(db=db, verbose=verbose, short=short)
+ yield from insn.disassemble(db=db, verbosity=verbosity)
# this is the entry-point for the console-script pysvp64dis
type=_argparse.FileType("w"), default=_sys.stdout)
parser.add_argument("-b", "--byteorder",
type=ByteOrder, default=ByteOrder.LITTLE)
- parser.add_argument("-v", "--verbose",
- action="store_true", default=False)
parser.add_argument("-s", "--short",
- action="store_true", default=False)
+ dest="verbosity", default=_Verbosity.NORMAL,
+ action="store_const", const=_Verbosity.SHORT)
+ parser.add_argument("-v", "--verbose",
+ dest="verbosity", default=_Verbosity.NORMAL,
+ action="store_const", const=_Verbosity.VERBOSE)
parser.add_argument("-l", "--log",
action="store_true", default=False)