From fac9fb81a218e3c9dc3e0d26e3c7fe82e9a2813c Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Thu, 8 Dec 2022 14:20:38 +0100 Subject: [PATCH] gen/fhdl/module: Add add/get_module methods to simplify user design and avoid direct use of setattr/getattr. --- litex/gen/fhdl/module.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/litex/gen/fhdl/module.py b/litex/gen/fhdl/module.py index 16aafe92f..0ddb24699 100644 --- a/litex/gen/fhdl/module.py +++ b/litex/gen/fhdl/module.py @@ -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