Python code generator

The Python code “generator” is an automated way of saving a RegisterList object to a Python pickle. It is not intended to be used during development, but bundling the Python class pickles when making an FPGA release can be very useful.

Running the RegisterList.create_python_class() method will create a binary pickle, which represents the object precisely, as well as a convenient Python file to re-create the pickle, shown below:

Example Python class
# This file is automatically generated by hdl_registers.
# Generated 2022-09-29 22:04 from file regs_example.toml at commit 439807c202d6c110.

import pickle
from pathlib import Path

THIS_DIR = Path(__file__).parent

class Example:

    Instantiate this class to get the RegisterList object for the example module.

    def __new__(cls):
        Recreate the RegisterList object from binary pickle.
        with (THIS_DIR / "example.pickle").open("rb") as file_handle:
            return pickle.load(file_handle)

def get_register_list():
    Return a RegisterList object with the registers/constants from the example module.
    Recreated from a python pickle file.
    return Example()

A Python-based system test environment can use the re-created RegisterList objects from the FPGA release to perform register reads/writes on the correct registers addresses and field indexes.