gen/fhdl/module: Add add/get_module methods to simplify user design and avoid direct use of setattr/getattr.

This commit is contained in:
Florent Kermarrec 2022-12-08 14:20:38 +01:00
parent 9bf276132a
commit fac9fb81a2
1 changed files with 11 additions and 0 deletions

View File

@ -49,3 +49,14 @@ class LiteXModule(Module, AutoCSR, AutoDoc):
else:
object.__iadd__(m, other)
return m
def add_module(self, name, module):
assert isinstance(module, Module)
assert not hasattr(self, name)
setattr(self, name, module)
def get_module(self, name):
module = getattr(self, name, None)
if module is not None:
assert isinstance(module, Module)
return module