hdl_registers.generator.python package


hdl_registers.generator.python.python_class_generator module

class hdl_registers.generator.python.python_class_generator.PythonClassGenerator(register_list: RegisterList, output_folder: Path)

Bases: RegisterCodeGenerator, RegisterCodeGeneratorHelpers

Generate a Python class with register definitions.

COMMENT_START: str = '#'
SHORT_DESCRIPTION = 'Python class'
__init__(register_list: RegisterList, output_folder: Path)
  • register_list – Registers and constants from this register list will be included in the generated artifacts.

  • output_folder – Result file will be placed in this folder.

create(**kwargs: Any) None

Create the binary pickle also, apart from the class file.

Note that this is a little bit hacky, preferably each generator should produce only one file.

get_code(**kwargs: Any) str

Save register list object to binary file (pickle) and create a python class that recreates it.

  • register_list (RegisterList) – This register list object will be saved.

  • output_folder (pathlib.Path) – The pickle and python files will be saved here.

property output_file: Path

Result will be placed in this file.

property should_create: bool

Since this generator creates two files, where on is binary, it is impossible to do the version/hash check. Hence, set it to “always create”. The mechanism “create if needed” should not be used for this generator anyway, since this generator is not designed to run in real-time like e.g. the VHDL generator.