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):
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 → <br/> XO MSB half ↓ |"), \
- "can't find PO=59 table"
+ "| XO LSB half →<br> XO MSB half ↓ |"), \
+ "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:
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\*\*| |))"
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]}")
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
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 == "":