From: Dmitry Selyutin Date: Sun, 15 Jan 2023 08:35:18 +0000 (+0300) Subject: pysvp64dis: do not create temporary bytes upon load X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fc018f79368c9c2969e2f5fc29befaa99b1d43c3;p=openpower-isa.git pysvp64dis: do not create temporary bytes upon load --- diff --git a/src/openpower/sv/trans/pysvp64dis.py b/src/openpower/sv/trans/pysvp64dis.py index 3722af09..64ef66ec 100644 --- a/src/openpower/sv/trans/pysvp64dis.py +++ b/src/openpower/sv/trans/pysvp64dis.py @@ -2,7 +2,6 @@ import argparse as _argparse import enum as _enum import sys as _sys import os as _os -from io import BytesIO from openpower.decoder.power_enums import ( find_wiki_dir as _find_wiki_dir, @@ -27,13 +26,8 @@ class ByteOrder(_enum.Enum): 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 = cpfile.read(4) + insn = ifile.read(4) length = len(insn) if length == 0: return @@ -41,7 +35,7 @@ def load(ifile, byteorder=ByteOrder.LITTLE, **_): raise IOError(insn) insn = _WordInstruction.integer(value=insn, byteorder=byteorder) if insn.PO == 0x1: - suffix = cpfile.read(4) + suffix = ifile.read(4) length = len(suffix) if length == 0: yield insn @@ -56,8 +50,6 @@ def load(ifile, byteorder=ByteOrder.LITTLE, **_): insn = _PrefixedInstruction.pair(prefix=prefix, suffix=suffix) yield insn - cpfile.seek(0) # restore position so that generator can be reused - def dump(insns, verbosity, **_): db = _Database(_find_wiki_dir()) diff --git a/src/openpower/sv/trans/test_pysvp64dis.py b/src/openpower/sv/trans/test_pysvp64dis.py index d39717e2..dedf12ae 100644 --- a/src/openpower/sv/trans/test_pysvp64dis.py +++ b/src/openpower/sv/trans/test_pysvp64dis.py @@ -5,6 +5,7 @@ from openpower.decoder.power_insn import Database, Verbosity from openpower.decoder.power_enums import find_wiki_dir from openpower.sv import sv_binutils_fptrans import unittest +from io import BytesIO import itertools import sys @@ -15,8 +16,12 @@ class SVSTATETestCase(unittest.TestCase): lst = list(isa) with Program(lst, bigendian=False) as program: print ("ops", program._instructions) + binfile = BytesIO() program.binfile.seek(0) - insns = load(program.binfile) + binfile.write(program.binfile.read()) + program.binfile.seek(0) + binfile.seek(0) + insns = load(binfile) #for insn in insns: #print ("insn", insn) insns = list(insns)