Skip to content

Commit

Permalink
Keep track of instances and update each instance on add_port()
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajsekhar Setaluri committed May 23, 2019
1 parent c609df8 commit 5a689c2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions magma/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def __new__(metacls, name, bases, dct):
else:
dct["debug_info"] = None

# Keep track of instances of this Circuit.
dct["my_instances"] = set()


# create a new circuit class
cls = type.__new__(metacls, name, bases, dct)
Expand Down Expand Up @@ -185,6 +188,10 @@ def add_port(cls, name, typ):
cls.IO.ports.update({name: typ})
cls.interface.add_port(name, typ, defn=cls, add_to_decl=True)
setattr(cls, name, cls.interface.ports[name])
for inst in cls.my_instances:
inst.IO.ports.update({name: typ})
inst.interface.add_port(name, typ, inst=inst, add_to_decl=False)
setattr(inst, name, inst.interface.ports[name])


#
Expand Down Expand Up @@ -361,6 +368,10 @@ def __init__(self, *largs, **kwargs):
if currentDefinition:
currentDefinition.place(self)

defn = type(self)
assert self not in defn.my_instances
defn.my_instances.add(self)

def __repr__(self):
args = []
for k, v in self.kwargs.items():
Expand Down

0 comments on commit 5a689c2

Please sign in to comment.