#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-3.0-only """Generate the executable-format reference from public constant declarations.""" import argparse from pathlib import Path import re def render(root): header = root / "src/formats/executable_layout.hpp" declarations = re.findall(r"^inline constexpr auto (\w+) = (0x[0-9a-fA-F]+[uUlL]*);$", header.read_text(encoding="utf-8"), re.M) text = """# Executable and runtime layout constants OpenBMH reads the executable image supplied with the user's game installation. The compatibility adapters bind fields in that image's loaded address space. The declarations in [`executable_layout.hpp`](../../src/formats/executable_layout.hpp) name format locations and test fixture bounds; they contain no game resources. The adapter uses the German-format layout internally. English image fields are translated into that layout. The values below are data locations or bounds, not callable functions. Structure-relative offsets and bit masks remain separate. Each declaration uses `inline constexpr auto` with the original integer spelling and suffix. This preserves signedness, expression typing and constant-expression use. Do not replace these with a single integer type without checking call sites. `LayoutTranslation` names identify relocation-table fields read from the selected image. Ordinal suffixes distinguish fields; they do not encode addresses. `Fixture` and `Synthetic` names describe test setup, including arbitrary synthetic workspace locations and buffer sizes; they are not additional original-game layout claims. Generated by `tools/public_release/collect_layout.py`. Update this table when declarations change. Game text, resort, image and audio fallbacks belong outside it. | Constant | Literal | Use | |---|---|---| """ for name, literal in declarations: value = int(re.sub("[uUlL]+$", "", literal), 16) if name.startswith(("Fixture", "Synthetic")): use = "Test fixture location or bound" else: use = "English image adapter" if value < 0xa0000 else "German-compatible image / runtime field" text += f"| `{name}` | `{literal}` | {use} |\n" return text def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--root", type=Path, default=Path(__file__).resolve().parents[2]) parser.add_argument("--check", action="store_true") args = parser.parse_args() destination = args.root / "docs/formats/EXECUTABLE_LAYOUT.md" expected = render(args.root) if args.check: if not destination.is_file() or destination.read_text(encoding="utf-8") != expected: parser.exit(1, "Executable-layout reference needs regeneration\n") else: destination.write_text(expected, encoding="utf-8") if __name__ == "__main__": main()