pysvp64dis: refactor instruction loading
authorDmitry Selyutin <ghostmansd@gmail.com>
Thu, 1 Sep 2022 12:32:38 +0000 (15:32 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Fri, 2 Sep 2022 08:44:11 +0000 (11:44 +0300)
src/openpower/sv/trans/pysvp64dis.py

index 39d63ef5cd981cc8d40c02815a97ade781a8e52f..98848c66787ed5dd39fc7a37d57bd28241c74b5a 100644 (file)
@@ -25,31 +25,28 @@ def load(ifile, byteorder, **_):
     byteorder = str(byteorder)
 
     while True:
-        prefix = ifile.read(4)
-        length = len(prefix)
+        insn = ifile.read(4)
+        length = len(insn)
         if length == 0:
             return
         elif length < 4:
-            raise IOError(prefix)
-        prefix = _WordInstruction.integer(value=prefix, byteorder=byteorder)
-
-        suffix = ifile.read(4)
-        length = len(suffix)
-        if length == 0:
-            yield prefix
-            return
-        elif length < 4:
-            raise IOError(suffix)
-        suffix = _WordInstruction.integer(value=suffix, byteorder=byteorder)
-
-        if prefix.po == 0x1:
+            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
-        else:
-            yield prefix
-            yield suffix
+        yield insn
 
 
 def dump(insns, **_):