dan-fritchman / Hdl21

Hardware Description Library
BSD 3-Clause "New" or "Revised" License
69 stars 16 forks source link

Naming Generator-Internal Modules #203

Open dan-fritchman opened 1 year ago

dan-fritchman commented 1 year ago

Example:

@h.generator
def Big(params: Params) -> h.Module:
    @h.module
    class Unit:
        # Unit cell, used a handful of times in `Big` below. 
        # The important part: *also depends on `params`*
        # E.g.
        p = h.Port(width=params.width) # Or any other parameter dependency

    @h.module
    class Big:
        # Thing that instantiates several instances of `Unit`
        p = h.Port(width=params.width) # Or any other parameter dependency
        units = params.how_many * Unit(p=p) 

    return Big

In short:

This may look like a contrived example, but is pretty common in e.g. a DAC.

When and why is this a problem?

Note this only becomes a problem if there is more than one call to Big with different parameters. Both its internal Unit modules would get the same non-uniquified name (Unit).

What could be done:

Naming would get resolved... it's not entirely clear when.

Important thing is, all those should work.

Also - there are workarounds. Namely: