insndb/db: introduce instruction argument type
authorDmitry Selyutin <ghostmansd@gmail.com>
Sun, 4 Jun 2023 08:49:54 +0000 (11:49 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Sun, 4 Jun 2023 09:30:53 +0000 (12:30 +0300)
src/openpower/insndb/db.py

index 4f922c65e6f654dd680bc5824be7bff9369c5b9e..b8311f31780262e767601374b5332484db26a57f 100644 (file)
@@ -11,6 +11,21 @@ from openpower.insndb.core import (
 )
 
 
+class Instruction(str):
+    def __new__(cls, string):
+        svp64 = False
+        if string.startswith("sv."):
+            string = string[len("sv."):]
+            svp64 = True
+        self = super().__new__(cls, string)
+        self.__svp64 = svp64
+        return self
+
+    @property
+    def svp64(self):
+        return self.__svp64
+
+
 class BaseVisitor(Visitor):
     def __init__(self, **_):
         pass
@@ -89,7 +104,8 @@ def main():
     for (command, (visitor, help)) in commands.items():
         parser = main_subparser.add_parser(command, help=help)
         if issubclass(visitor, ConcreteInstructionVisitor):
-            parser.add_argument("insn", metavar="INSN", help="instruction")
+            parser.add_argument("insn", type=Instruction,
+                metavar="INSN", help="instruction")
 
     args = vars(main_parser.parse_args())
     command = args.pop("command")
@@ -100,3 +116,7 @@ def main():
 
     db = Database(find_wiki_dir())
     db.visit(visitor=visitor)
+
+
+if __name__ == "__main__":
+    main()