Skip to content

Commit 46fc983

Browse files
alxdrljannau
authored andcommitted
tools/: move JSON register definition files
so as to load those files directly from the module location: - move *_regs.json files to proxyclient/m1n1 module's folder - load definition files using Python's resource loader This has the benefit of avoiding path traversal and is a prerequisite to the packaging of proxyclient as a PyPi package. Signed-off-by: Alexis Deruelle <alexis.deruelle@gmail.com>
1 parent 94b9c61 commit 46fc983

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

proxyclient/m1n1/sysreg.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-License-Identifier: MIT
2-
import json, os, re
2+
import json, re
3+
import importlib.resources as resources
34
from enum import Enum, IntEnum, IntFlag
45
from .utils import Register, Register64, Register32
56

@@ -11,7 +12,8 @@ def _load_registers():
1112
sysreg_fwd = {}
1213
sysop_fwd = {}
1314
for fname in ["arm_regs.json", "apple_regs.json"]:
14-
data = json.load(open(os.path.join(os.path.dirname(__file__), "..", "..", "tools", fname)))
15+
data = json.loads(resources.read_text(__package__, fname, encoding="utf-8"))
16+
1517
for reg in data:
1618
if "accessors" in reg:
1719
for acc in reg["accessors"]:

tools/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Register definition tools
2+
3+
This folder contains various scripts that handle ARM and Apple register
4+
symbolic definition used by `proxyclient` (see `proxyclient/m1n1/sysreg.py`).
5+
6+
## Script description
7+
8+
- `gen_reg_class.py` generates Python class from JSON register definition file
9+
- `gen_reg_include.py` generates C include definition (see src/\*\_regs.h)
10+
- `reg2json.py` generates JSON definition files from XML input
11+
- `reg_filter.py` loads JSON register definition file and translates system
12+
register encoding to symbolic names
13+
14+
## Note on file location
15+
16+
There's two register definition files, `apple_regs.json` and `arm_regs.json`,
17+
that were initially stored alongside these scripts.
18+
19+
Register now resides in the `proxyclient/m1n1` folder, so that `proxyclient`
20+
can load them while avoiding path traversal, using Python's resource loader.

0 commit comments

Comments
 (0)