Hdl21
Hdl21 copied to clipboard
`BundleInstance.__setattr__` (and maybe a few others?) should probably fail
Some new-user intuition about how to use Bundle
s:
import hdl21 as h
@h.module
class Inner:
d = h.Diff(port=True)
@h.module
class Outer:
# Make an `Inner` instance, and a `Diff` connected to it
d = h.Diff()
i = Inner(d=d)
# This is the problem part here:
x, y = 2 * h.Signal()
d.p = x
d.n = y
# And connect Signals `x` and `y` to other stuff
v = h.Vdc()(p=x, n=y)
Which, I get why that might be your intuition. We allow LHS-assignment/ __setattr__
of Instance
-ports; bundles probably seem kinda similar.
But they're not. And that produces a netlist like so:
subckt Outer
+ // No ports
+ // No parameters
i
+ // Ports:
+ ( d_p d_n )
+ Inner
+ // No parameters
v
+ // Ports:
+ ( x y )
+ vsource
+ dc=0 type=dc mag=0
Which is bad in that:
- (a)
x
andy
don't connect to thed
signals at all, and - (b) We didn't offer any indication this looked like a problem
All that's happening: BundleInstance.__setattr__
is just the "regular" object.__setattr__
. It stores fields named p
and n
, which are Signals, which never get looked at again.
This should probably fail at __setattr__
. There may be some other "struct-like" types on which we want to add similar behavior; Slice
and Concat
come to mind.