pysvp64dis: integrate into insndb insndb
authorDmitry Selyutin <ghostmansd@gmail.com>
Fri, 2 Jun 2023 16:25:18 +0000 (19:25 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Fri, 2 Jun 2023 16:33:05 +0000 (19:33 +0300)
setup.py
src/openpower/insndb/dis.py [new file with mode: 0644]
src/openpower/sv/trans/pysvp64dis.py [deleted file]
src/openpower/sv/trans/test_pysvp64dis.py
src/openpower/sv/trans/test_pysvp64dis_branch.py

index 304b2c95b1ccff2579e74a719f14fae5df8d0afb..827d39be604f9cbb5e5700a89b23034d80664c41 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -83,7 +83,7 @@ setup(
             'sv_analysis=openpower.sv.sv_analysis:main',
             'pypowersim=openpower.decoder.isa.pypowersim:run_simulation',
             'pysvp64asm=openpower.insndb.asm:main',
-            'pysvp64dis=openpower.sv.trans.pysvp64dis:main'
+            'pysvp64dis=openpower.insndb.dis:main'
         ]
     }
 )
diff --git a/src/openpower/insndb/dis.py b/src/openpower/insndb/dis.py
new file mode 100644 (file)
index 0000000..720963b
--- /dev/null
@@ -0,0 +1,97 @@
+import argparse
+import enum
+import sys
+import os
+
+from openpower.decoder.power_enums import (
+    find_wiki_dir,
+)
+from openpower.insndb.types import (
+    Style,
+    Database,
+    WordInstruction,
+    PrefixedInstruction,
+    SVP64Instruction,
+)
+
+
+class ByteOrder(enum.Enum):
+    LITTLE = "little"
+    BIG = "big"
+
+    def __str__(self):
+        return self.name.lower()
+
+
+def load(ifile, byteorder=ByteOrder.LITTLE, **_):
+    byteorder = str(byteorder)
+
+    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()
+    parser.add_argument("ifile", nargs="?",
+        type=argparse.FileType("rb"), default=sys.stdin.buffer)
+    parser.add_argument("ofile", nargs="?",
+        type=argparse.FileType("w"), default=sys.stdout)
+    parser.add_argument("-b", "--byteorder",
+        type=ByteOrder, default=ByteOrder.LITTLE)
+    parser.add_argument("-s", "--short",
+        dest="style", default=Style.NORMAL,
+        action="store_const", const=Style.SHORT)
+    parser.add_argument("-v", "--verbose",
+        dest="style", default=Style.NORMAL,
+        action="store_const", const=Style.VERBOSE)
+    parser.add_argument("-l", "--legacy",
+        dest="style", default=Style.NORMAL,
+        action="store_const", const=Style.LEGACY)
+    parser.add_argument("-L", "--log",
+        action="store_true", default=False)
+
+    args = dict(vars(parser.parse_args()))
+
+    # if logging requested do not disable it.
+    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"])
+
+
+# still here but use "python3 setup.py develop" then run the
+# command "pysvp64dis" instead of "python3 src/openpower/sv/trans/pysvp64dis.py"
+if __name__ == "__main__":
+    main()
diff --git a/src/openpower/sv/trans/pysvp64dis.py b/src/openpower/sv/trans/pysvp64dis.py
deleted file mode 100644 (file)
index 720963b..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-import argparse
-import enum
-import sys
-import os
-
-from openpower.decoder.power_enums import (
-    find_wiki_dir,
-)
-from openpower.insndb.types import (
-    Style,
-    Database,
-    WordInstruction,
-    PrefixedInstruction,
-    SVP64Instruction,
-)
-
-
-class ByteOrder(enum.Enum):
-    LITTLE = "little"
-    BIG = "big"
-
-    def __str__(self):
-        return self.name.lower()
-
-
-def load(ifile, byteorder=ByteOrder.LITTLE, **_):
-    byteorder = str(byteorder)
-
-    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()
-    parser.add_argument("ifile", nargs="?",
-        type=argparse.FileType("rb"), default=sys.stdin.buffer)
-    parser.add_argument("ofile", nargs="?",
-        type=argparse.FileType("w"), default=sys.stdout)
-    parser.add_argument("-b", "--byteorder",
-        type=ByteOrder, default=ByteOrder.LITTLE)
-    parser.add_argument("-s", "--short",
-        dest="style", default=Style.NORMAL,
-        action="store_const", const=Style.SHORT)
-    parser.add_argument("-v", "--verbose",
-        dest="style", default=Style.NORMAL,
-        action="store_const", const=Style.VERBOSE)
-    parser.add_argument("-l", "--legacy",
-        dest="style", default=Style.NORMAL,
-        action="store_const", const=Style.LEGACY)
-    parser.add_argument("-L", "--log",
-        action="store_true", default=False)
-
-    args = dict(vars(parser.parse_args()))
-
-    # if logging requested do not disable it.
-    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"])
-
-
-# still here but use "python3 setup.py develop" then run the
-# command "pysvp64dis" instead of "python3 src/openpower/sv/trans/pysvp64dis.py"
-if __name__ == "__main__":
-    main()
index b8a8fe2b812ea0af4514e7f3f7d0cc509798b6f4..d8af280a3f9ff304c555a4fe1ea79e2bd5683de0 100644 (file)
@@ -1,5 +1,5 @@
 from openpower.simulator.program import Program
-from openpower.sv.trans.pysvp64dis import load, dump
+from openpower.insndb.dis import load, dump
 from openpower.insndb.asm import SVP64Asm
 from openpower.insndb.types import Database, Style
 from openpower.decoder.power_enums import find_wiki_dir
index 44a215fb54cb7e7ddd1138343553f80de47451f3..99bb09908b2fdc3db0462ba61350ba3b97de0322 100644 (file)
@@ -1,5 +1,5 @@
 from openpower.simulator.program import Program
-from openpower.sv.trans.pysvp64dis import load, dump
+from openpower.insndb.dis import load, dump
 from openpower.insndb.asm import SVP64Asm
 from openpower.insndb.types import Database, Style
 from openpower.decoder.power_enums import find_wiki_dir