)
from openpower.decoder.power_insn import (
ByteOrder as _ByteOrder,
- Style as _Style,
+ collect as _collect,
Database as _Database,
- WordInstruction as _WordInstruction,
- PrefixedInstruction as _PrefixedInstruction,
- SVP64Instruction as _SVP64Instruction,
+ DisassemblerError as _DisassemblerError,
+ Style as _Style,
)
-def load(ifile, byteorder=_ByteOrder.LITTLE, **_):
- while True:
- insn = ifile.read(4)
- length = len(insn)
- if length == 0:
- return
- elif length < 4:
- raise IOError(insn)
- insn = _WordInstruction.integer(value=insn, byteorder=byteorder)
- if insn.PO == 0x1:
- suffix = ifile.read(4)
- length = len(suffix)
- if length == 0:
- yield insn
- return
- elif length < 4:
- raise IOError(suffix)
-
- prefix = insn
- suffix = _WordInstruction.integer(value=suffix, byteorder=byteorder)
- insn = _SVP64Instruction.pair(prefix=prefix, suffix=suffix)
- if insn.prefix.id != 0b11:
- insn = _PrefixedInstruction.pair(prefix=prefix, suffix=suffix)
- yield insn
-
-
-def dump(insns, style, **_):
- db = _Database(_find_wiki_dir())
- for insn in insns:
- record = db[insn]
- yield from insn.disassemble(record=record, style=style)
-
-
# this is the entry-point for the console-script pysvp64dis
def main():
parser = _argparse.ArgumentParser()
action="store_true", default=False)
args = dict(vars(parser.parse_args()))
+ db = _Database(_find_wiki_dir())
# if logging requested do not disable it.
- if not args['log']:
- _os.environ['SILENCELOG'] = '1'
+ if not args["log"]:
+ _os.environ["SILENCELOG"] = "1"
# load instructions and dump them
- insns = load(**args)
- for line in dump(insns, **args):
- print(line, file=args["ofile"])
+ ifile = args["ifile"]
+ ofile = args["ofile"]
+ byteorder = args["byteorder"]
+ style = args["style"]
+
+ insns = _collect(stream=ifile, byteorder=byteorder)
+ lines = db.disassemble(insns=insns, byteorder=byteorder, style=style)
+ for line in lines:
+ print(line, file=ofile)
# still here but use "python3 setup.py develop" then run the
from openpower.simulator.program import Program
-from openpower.sv.trans.pysvp64dis import load, dump
from openpower.sv.trans.svp64 import SVP64Asm
-from openpower.decoder.power_insn import Database, Style
+from openpower.decoder.power_insn import ByteOrder, collect, Database, Style
from openpower.decoder.power_enums import find_wiki_dir
from openpower.sv import sv_binutils_fptrans
import unittest
import itertools
import sys
-class SVSTATETestCase(unittest.TestCase):
+def disassemble(db, insns):
+ for insn in insns:
+ yield "; ".join(db.disassemble(insn,
+ byteorder=ByteOrder.LITTLE,
+ style=Style.SHORT))
+
+
+class SVSTATETestCase(unittest.TestCase):
def _do_tst(self, expected):
+ db = Database(find_wiki_dir())
isa = SVP64Asm(expected)
lst = list(isa)
+ byteorder = ByteOrder.LITTLE
+ print(lst)
with Program(lst, bigendian=False) as program:
print ("ops", program._instructions)
binfile = BytesIO()
binfile.write(program.binfile.read())
program.binfile.seek(0)
binfile.seek(0)
- insns = load(binfile)
+ insns = collect(stream=binfile, byteorder=byteorder)
#for insn in insns:
#print ("insn", insn)
insns = list(insns)
- print ("insns", insns)
- for i, line in enumerate(dump(insns, style=Style.SHORT)):
+ print("insns", insns)
+ lines = tuple(disassemble(db, insns))
+ for i, line in enumerate(lines):
name = expected[i].split(" ")[0]
with self.subTest("%d:%s" % (i, name)):
print("instruction", repr(line), repr(expected[i]))