(no commit message)
[libreriscv.git] / openpower / power_trans_ops_copy_from_PO59_table.py
index 061b7e5f358c283430a11701eb7c8602c4599ddd..e41166c1ce94f61057e429b814fa11d577a3cf49 100644 (file)
@@ -7,11 +7,10 @@ FILENAME = Path("openpower/power_trans_ops.mdwn")
 NEW_FILENAME = FILENAME.with_suffix(".new.mdwn")
 OLD_FILENAME = FILENAME.with_suffix(".old.mdwn")
 
-PO_59_HEADER = "## PO=59 XO=10--011--"
+PO_59_63_HEADER = "# Opcode Tables for PO=59/63 XO=1---011--"
 MNEMONIC_COLUMN_NAME = "opcode"
 XO_COLUMN_NAME = "Major 59 and 63"
 
-# TODO: copy PO=59 table to PO=63 table
 
 class LineReader:
     def __init__(self, lines):
@@ -52,28 +51,16 @@ def process(lr):
 
         assert line is not None and line != "", "empty table"
 
-    def parse_mnemonic_to_opcode_map():
+    def parse_single_mnemonic_to_opcode_map():
         # type: () -> Iterable[str]
         nonlocal line, lineno, mnemonic_to_xo_map
 
-        while line != PO_59_HEADER:
-            assert line is not None, "missing PO=59 header"
-            yield line
-            line, lineno = lr.read()
-
-        yield line
-        line, lineno = lr.read()
-
-        while line is not None and not line.startswith(("#", "|")):
-            yield line
-            line, lineno = lr.read()
-
         assert line is not None and line.startswith(
-            "| XO LSB half &#x2192; <br/> XO MSB half &#x2193; |"), \
-            "can't find PO=59 table"
+            "| XO LSB half &#x2192;<br> XO MSB half &#x2193; |"), \
+            "can't find PO=59/63 table"
         line_parts = line.split('|')
         len_line_parts = len(line_parts)
-        assert line_parts[-1] == "", "invalid PO=59 table top row"
+        assert line_parts[-1] == "", "invalid PO=59/63 table top row"
         columns = []  # type: list[str]
         columns_range = range(2, len_line_parts - 1)
         for i in columns_range:
@@ -100,26 +87,29 @@ def process(lr):
             row = line_parts[1].strip()
             if row.startswith('`') and row.endswith('`'):
                 row = row[1:-1].strip()
-            assert row.lstrip(" 01") == "", (f"invalid table line header-cell "
-                                             f"contents -- must be a "
-                                             f"binary string: {row}")
+            assert row.lstrip(" 01/.") == "", (
+                f"invalid table line header-cell contents -- must be a "
+                f"binary string: {row}")
             for i, column in zip(columns_range, columns):
                 cell = line_parts[i]
+                if cell.strip() == "":
+                    continue
                 match = re.fullmatch(
-                    r" *<small> *` *(?P<xo>[01][01 ]*[01]) *` *</small>"
-                    r" *<br/> *(?P<mnemonic>[a-zA-Z0-9_.]+)?"
-                    r"(?(mnemonic)|(?:\([a-zA-Z0-9_.]+\)|\*\*TBD\*\*|))"
+                    r" *<small> *` *(?P<xo>[01./][01 ./]*[01./]) *` *</small>"
+                    r" *<br/?> *(?P<mnemonic>[a-zA-Z0-9_.][a-zA-Z0-9_.()]*)?"
+                    r"(?(mnemonic)|(?:\([a-zA-Z0-9_.()]+\)|"
+                    r"\*\*TBD\*\*|&nbsp;|))"
                     r"(?: *\(draft\))? *", cell)
                 assert match is not None, f"invalid table cell: {cell!r}"
                 xo, mnemonic = match.group("xo", "mnemonic")
-                shrunk_xo = xo.replace(" ", "")
-                expected_xo = (row + column).replace(" ", "")
+                shrunk_xo = xo.replace(" ", "").replace('.', '/')
+                expected_xo = (row + column).replace(" ", "").replace('.', '/')
                 assert shrunk_xo == expected_xo, \
                     f"incorrect XO: found {shrunk_xo} expected {expected_xo}"
                 if mnemonic is None:
                     continue
-                assert mnemonic.endswith('s'), \
-                    f"PO=59 fptrans mnemonic must end in `s`: {mnemonic}"
+                assert mnemonic.endswith('(s)'), \
+                    f"PO=59/63 fptrans mnemonic must end in `(s)`: {mnemonic}"
                 assert mnemonic not in mnemonic_to_xo_map, (
                     f"duplicate mnemonic: {mnemonic} -- has opcode "
                     f"{xo} and {mnemonic_to_xo_map[mnemonic]}")
@@ -129,6 +119,29 @@ def process(lr):
             yield line
             line, lineno = lr.read()
 
+        while line == "":
+            yield line
+            line, lineno = lr.read()
+
+    def parse_mnemonic_to_opcode_map():
+        # type: () -> Iterable[str]
+        nonlocal line, lineno, mnemonic_to_xo_map
+
+        while line != PO_59_63_HEADER:
+            assert line is not None, "missing PO=59/63 header"
+            yield line
+            line, lineno = lr.read()
+
+        yield line
+        line, lineno = lr.read()
+
+        while line is not None and not line.startswith(("#", "|")):
+            yield line
+            line, lineno = lr.read()
+
+        for _ in range(3):
+            yield from parse_single_mnemonic_to_opcode_map()
+
     def skip_table():
         # type: () -> Iterable[str]
         nonlocal line, lineno
@@ -205,8 +218,6 @@ def process(lr):
 
             mnemonic = line_parts[mnemonic_index].strip()
             xo = line_parts[xo_index].strip()
-            if mnemonic.endswith("(s)") or mnemonic.endswith("[s]"):
-                mnemonic = mnemonic[:-3] + "s"
             if mnemonic not in mnemonic_to_xo_map:
                 print(f"mnemonic not assigned an XO value: {mnemonic!r}")
             elif xo == "":