Skip to content

Tailored Module

Tailored Module.

ATailoredMod

Bases: BaseMod

Module Which Is Tailored For Every Use Case By The Parent Module, Mainly The Number And Names Of Ports.

See :any:BaseMod for arguments, attributes and details.

Due to the frozen instance approach, implementation specific containers have to be implemented via u.field().

The source code files are typically generated next to the parent module of tailored module. Also the module name is based on the parent module and extended by the instance name. A :any:ATailoredMod requires a Mako template mostly. The default template is typically located next to the python file of the tailored module.

Tailored modules have two build methods:

  • _build
  • _build_dep
  • _build_final

Please take the following points into account:

  • _build should be used for all static code and initialization.
  • Tailored modules should provide add methods to tailor the module instance to the needs of the parent module.
  • _build_dep is called after all add methods have been called and should be used for all dynamic aspects which can only be known after the parent module made its adjustments.

Attributes:

Name Type Description
filelists ModFileLists

Filelists.

Module Reference Examples

Example Definition:

>>> import logging
>>> import ucdp as u
>>> LOGGER = logging.getLogger(__name__)
>>> class DmxMod(u.ATailoredMod):
...     slaves: u.Namespace = u.Field(default_factory=u.Namespace, init=False)
...
...     def add_slave(self, name, route=None):
...         self.slaves[name] = slave = Slave(dmx=self, name=name)
...         portname = f"slv_{name}_o"
...         self.add_port(u.UintType(16), portname)
...         if route:
...             self.con(portname, route)
...         return slave
...
...     def _build(self) -> None:
...         pass#self.add_port(u.UintType(16), "mst_i")
...
...     def _build_dep(self):
...         if not self.slaves:
...             LOGGER.warning("%r: has no APB slaves", self)
...
>>> class Slave(u.NamedObject):
...     dmx: u.BaseMod = u.Field(repr=False)

Example Usage:

>>> import ucdp as u
>>> class TopMod(u.AMod):
...     def _build(self) -> None:
...         dmx = DmxMod(self, 'u_dmx')
...         dmx.add_slave('a')
...         dmx.add_slave('b')
>>> top = TopMod()
>>> top
<ucdp.modtailored.TopMod(inst='top', libname='ucdp', modname='top')>
>>> top.get_inst('u_dmx')
<ucdp.modtailored.DmxMod(inst='top/u_dmx', libname='ucdp', modname='top_dmx')>
>>> top.get_inst('u_dmx').slaves
Namespace([Slave(name='a'), Slave(name='b')])

filelists class-attribute

filelists = ()

File Lists.

modname property

modname

Module Name.

topmodname property

topmodname

Top Module Name.

libname property

libname

Library Name.

is_tb property

is_tb

Determine if module belongs to Testbench or Design.

model_post_init

model_post_init(__context)

Run Build.