feat: sys4load labels globals from merged build/globals.json (Task 3)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-07-07 08:24:36 -04:00
parent 84a8da765f
commit 69c788b65a
2 changed files with 20 additions and 7 deletions

View File

@@ -45,9 +45,10 @@ try:
except ImportError:
INFERRED = {}
# Global-variable labels (optional): annotate global operands with the partial global-var
# map (build/global-var-map.json, produced by tools/global_map.py). High/medium confidence
# only — the low-confidence tail (~12k sparse guesses) is left out to keep listings readable.
# Global-variable labels (optional): annotate global operands from the merged registry
# build/globals.json (curated vm-map/globals.toml over the auto shape map), produced by
# tools/globals_build.py --build. Curated entries show their name+category; the auto tail
# keeps only high/med confidence to stay readable. Degrades to {} if the file is absent.
GLOBAL_ATYPES = {3, 4, 5, 6, 8} # global-int/float/string/ptr/string-ptr
@@ -61,15 +62,18 @@ def _short_global_label(lbl: str) -> str:
def _load_global_labels() -> dict:
try:
p = Path(__file__).resolve().parent.parent / "build" / "global-var-map.json"
p = Path(__file__).resolve().parent.parent / "build" / "globals.json"
data = json.loads(p.read_text(encoding="utf-8"))
except Exception:
return {}
out = {}
for addr_s, e in data.get("globals", {}).items():
lbl, conf = e.get("label"), e.get("confidence")
if lbl and conf in ("high", "med"):
out[int(addr_s, 16)] = _short_global_label(lbl)
addr = int(addr_s, 16)
if e.get("provenance") == "curated" and e.get("name"):
cat = e.get("category")
out[addr] = f"{e['name']}({cat})" if cat and cat != "unknown" else e["name"]
elif e.get("usage") and e.get("confidence") in ("high", "med"):
out[addr] = _short_global_label(e["usage"])
return out

View File

@@ -40,9 +40,18 @@ def test_merge_precedence():
check(auto_only is not None and merged[int(auto_only, 16)]["provenance"] == "auto",
"auto-only address retained with provenance=auto")
def test_sys4load_labels_from_registry():
import importlib, sys4load
importlib.reload(sys4load) # re-run _load_global_labels against current build/globals.json
lbl = sys4load.GLOBAL_LABELS.get(0x3234, "")
check("chapter_mode" in lbl, f"sys4load labels 0x3234 with curated name (got {lbl!r})")
lbl2 = sys4load.GLOBAL_LABELS.get(0xa57, "")
check("lily_form_a" in lbl2, f"sys4load labels 0xa57 with curated name (got {lbl2!r})")
if __name__ == "__main__":
test_load_and_lint()
test_lint_catches_bad_vocab()
test_merge_precedence()
test_sys4load_labels_from_registry()
print(f"\n{len(FAILS)} failures")
sys.exit(1 if FAILS else 0)