Files
xenia-rs/migration/project-root/ppc-manual/generator/cxx_scraper.py
MechaCat02 e6d43a23ac chore: add migration/ bundle for cross-machine setup
Bundles state that lives OUTSIDE the xenia-rs repo so a fresh clone on
another machine can be brought up to identical configuration via
migration/setup.sh:

  - claude-memory/             ~/.claude/projects/-home-fabi-RE-Project-Sylpheed/memory/
                               (103 files, 1.1 MB - MEMORY.md + every
                                project_xenia_rs_*.md from audits
                                addis_signext through audit-058)
  - project-root/dot-claude/   <project-root>/.claude/settings.json
                               (Stop hook + permissions)
  - project-root/ppc-manual/   <project-root>/ppc-manual/
                               (PowerPC reference docs, 397 files, 3.7 MB)
  - project-root/run-canary.sh <project-root>/run-canary.sh
  - README.md                  Human-readable setup checklist
  - setup.sh                   Idempotent installer (also reclones
                               xenia-canary at pinned HEAD 6de80dffe)
  - MANIFEST.md                Per-file mapping + per-file-not-bundled
                               restoration recipe

Excluded from bundle (not shippable via git):
  - Sylpheed ISO (7.8 GB; copyright; manual copy required)
  - sylpheed.db (395 MB; regenerable from XEX via analysis tooling)
  - target/ build artifacts (rebuild on target)
  - audit-runs probe firehoses (.log/.stdout/.stderr ~11 GB; rerun if needed)
  - audit-runs memory dumps (.bin ~4.5 GB; rerun audit-026/027/029 if needed)
  - xenia-canary checkout (setup.sh reclones from
    git.mc02.dev/fabi/Xenia-Canary.git at HEAD 6de80dffe)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 21:38:38 +02:00

76 lines
2.4 KiB
Python

"""
Scrapes xenia-canary's emit files for the location of each instruction's
semantic implementation function `InstrEmit_<mnem>`.
The files are:
src/xenia/cpu/ppc/ppc_emit_alu.cc (integer ALU)
src/xenia/cpu/ppc/ppc_emit_memory.cc (loads/stores/cache/sync)
src/xenia/cpu/ppc/ppc_emit_altivec.cc (VMX + VMX128)
src/xenia/cpu/ppc/ppc_emit_fpu.cc (floating-point)
src/xenia/cpu/ppc/ppc_emit_control.cc (branch/CR/SPR/syscall/trap)
Returns, for each mnemonic, the relative file path and the starting line
of the `int InstrEmit_<mnem>(...)` definition.
"""
from __future__ import annotations
from dataclasses import dataclass
from pathlib import Path
import re
CXX_EMIT_FILES = [
"src/xenia/cpu/ppc/ppc_emit_alu.cc",
"src/xenia/cpu/ppc/ppc_emit_memory.cc",
"src/xenia/cpu/ppc/ppc_emit_altivec.cc",
"src/xenia/cpu/ppc/ppc_emit_fpu.cc",
"src/xenia/cpu/ppc/ppc_emit_control.cc",
]
@dataclass
class CxxRef:
mnem: str
emit_file: str | None = None # relative to xenia-canary/
emit_line: int | None = None
def _cxx_ident(mnem: str) -> str:
"""Canary maps '.' in the mnemonic to a trailing 'x' in the C++ symbol
(e.g. addic. → InstrEmit_addicx)."""
return mnem.replace(".", "x")
class CxxScraper:
def __init__(self, repo_root: Path):
self.canary_root = repo_root / "xenia-canary"
self._index: dict[str, tuple[str, int]] = {}
fn_pat = re.compile(r"^\s*int\s+InstrEmit_([A-Za-z_][A-Za-z0-9_]*)\s*\(")
for rel in CXX_EMIT_FILES:
path = self.canary_root / rel
if not path.is_file():
continue
for i, line in enumerate(path.read_text(encoding="utf-8").splitlines(), start=1):
m = fn_pat.match(line)
if not m:
continue
name = m.group(1)
self._index.setdefault(name, (rel, i))
def lookup(self, mnem: str) -> CxxRef:
ident = _cxx_ident(mnem)
hit = self._index.get(ident)
if hit is None:
return CxxRef(mnem=mnem)
return CxxRef(mnem=mnem, emit_file=hit[0], emit_line=hit[1])
if __name__ == "__main__":
root = Path(__file__).resolve().parent.parent.parent
s = CxxScraper(root)
for m in ("addx", "addic.", "lwz", "bclrx", "mfspr", "stvx", "vaddfp",
"vaddfp128", "faddx", "lvsl"):
r = s.lookup(m)
print(f"{m:12s} {r.emit_file}:{r.emit_line}")