#!/usr/bin/env python3 """VCS V8.11: compact generated AOT entry dispatch and harmless source noise. The checked-in VCS corpus currently emits one dense uint16_t PC->entry-id table per 16 KiB generated unit. Most slots are zero. This pass replaces each dense map with 64-bit occupancy masks plus a base id per 64-slot group. Entry ids are assigned in increasing-PC order by the code generator, so the original id is: group_base + popcount(mask bits preceding slot) This preserves the exact accepted PC set while shrinking the hot dispatch metadata by roughly an order of magnitude. It also removes standalone NOP comments and gotos that jump to the immediately following label; both are semantically inert and only inflate the generated source. The pass is intentionally textual and conservative. A table is changed only when its values are proven to be a monotonic 1..N entry-id sequence and the corresponding lookup expression is found exactly once. """ from __future__ import annotations import argparse import json import re import sys from dataclasses import dataclass, asdict from pathlib import Path TABLE_RE = re.compile( r"static const std::uint16_t (?PkEntryIds_[A-Za-z0-9_]+)\[(?P\d+)\] = \{\n" r"(?P.*?)\n\};\n", re.DOTALL, ) NOP_RE = re.compile(r"(?m)^[ \t]*// nop\r?\n") ADJACENT_GOTO_RE = re.compile(r"(?m)^(?P[ \t]*)goto (L_[0-9A-Fa-f]+);\r?\n(?P=indent)?(?P