Skip to content

Commit

Permalink
Add unplace method to circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
rsetaluri committed May 2, 2019
1 parent 6af4d68 commit 3d13552
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions magma/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ def __process_new_style_definition(self, io, renamed_ports):
# For instance references, we place the instance in the current
# definition, then add the driver of its inputs to the queue
inst = curr.name.inst
if inst.defn:
inst.defn.__unplace(inst)
self.place(inst)
for key, value in inst.interface.items():
if value.isinput():
Expand Down Expand Up @@ -600,6 +602,7 @@ def place(cls, inst):
raise Exception(f"Can not place instance twice. Instance "
f"{repr(inst)} already placed in defn {cls.name}.")
type_ = type(inst)
inst.prev_name = inst.name
if not inst.name:
count = cls.instanced_circuits_counter[type_.name]
inst.name = f"{type(inst).name}_inst{str(count)}"
Expand All @@ -609,6 +612,15 @@ def place(cls, inst):
inst.stack = inspect.stack()
cls.instances.append(inst)

def __unplace(cls, inst):
if inst not in cls.instances:
raise Exception(f"Instance {repr(inst)} not placed in {cls.name}")
inst.defn = None
inst.name = inst.prev_name
if hasattr(inst, "stack"):
delattr(inst, "stack")
cls.instances.remove(inst)


# Register graphviz repr if running in IPython.
# There's a bug in IPython which breaks visual reprs
Expand Down

0 comments on commit 3d13552

Please sign in to comment.