ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
gen_hum_register_map.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# SPDX-License-Identifier: MIT
3# Copyright (c) 2026 Brighton Sikarskie
4"""Generate docs/reference/HUM_REGISTERS.csv from the committed manual PDF.
5
6The Hardware User's Manual publishes, per chapter, a description subsection
7for every register it defines -- symbol, full name, offset and the page the
8description starts on. This turns that into a committed, reviewable CSV so a
9human can read the manual's symbol table without opening a 4291-page PDF, and
10so a diff shows exactly what a manual revision changed.
11
12The CSV is a CONVENIENCE, never an authority. ``check_hum_register_map.py``
13re-derives the table from the PDF on every run and byte-compares the committed
14copy against it, so a CSV edited to make a violation disappear fails the gate
15rather than hiding the defect -- the "no check may compare a constant to
16itself" property from the #190 audit.
17
18Usage::
19
20 scripts/gen/gen_hum_register_map.py # rewrite the committed CSV
21 scripts/gen/gen_hum_register_map.py --stdout # print it instead
22"""
23
24from __future__ import annotations
25
26import argparse
27import pathlib
28import sys
29
30sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1] / "checks"))
31
32from hum_regmap import HUM_CSV, HUM_PDF, HumExtractionError, extract_from_pdf, to_csv
33
34
35def main(argv: list[str] | None = None) -> int:
36 """Write (or print) the manual's register symbol table."""
37 parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
38 parser.add_argument("--stdout", action="store_true", help="print the CSV instead of writing it")
39 parser.add_argument("--pdf", type=pathlib.Path, default=HUM_PDF, help="manual PDF to parse")
40 parser.add_argument("--out", type=pathlib.Path, default=HUM_CSV, help="CSV path to write")
41 args = parser.parse_args(argv)
42
43 try:
44 rows = extract_from_pdf(args.pdf)
45 except HumExtractionError as exc:
46 print(f"ERROR: {exc}", file=sys.stderr)
47 return 1
48
49 text = to_csv(rows)
50 if args.stdout:
51 sys.stdout.write(text)
52 return 0
53
54 args.out.parent.mkdir(parents=True, exist_ok=True)
55 args.out.write_text(text, encoding="utf-8")
56 chapters = len({row.chapter for row in rows})
57 print(f"wrote {args.out} -- {len(rows)} registers across {chapters} chapters")
58 return 0
59
60
61if __name__ == "__main__":
62 sys.exit(main())
void main(void)
The application entry point Reset_Handler hands control to.
Definition main.c:298