Updated functionality of the extend_bus method.

This commit is contained in:
Honza 2021-11-16 00:02:52 +01:00
parent 2083ed35a1
commit c8ed08691f

View File

@ -48,18 +48,23 @@ class Bus():
"""
return self.out_bus
def bus_extend(self, N: int, prefix: str = "bus"):
def bus_extend(self, N: int, prefix: str = "bus", last_wire_extend: bool = True):
"""Provides bus extension to contain more wires.
Args:
N (int): Number of wires in the bus. Defaults to 1.
prefix (str, optional): Prefix name of the bus. Defaults to "bus".
last_wire_extend (bool, optional): Specifies whether the last wire of the bus should be extended (connected) to all the extending wires. Defaults to True.
"""
# Checks if any extension is neccesarry and if so, proceeds to wire extend the bus
if self.N < N:
# Adding wires into current bus's wires list (wire names are concatenated from bus prefix and their index position inside the bus in square brackets)
self.bus += [Wire(name=prefix+f"[{i}]", prefix=prefix, index=i, parent_bus=self) for i in range(self.N, N)]
if last_wire_extend is True:
for w_index in range(self.N, N):
self.connect(bus_wire_index=w_index, inner_component_out_wire=self.get_wire(self.N - 1))
self.N = N
def get_wire(self, wire_index: int = 0):
"""Retrieves a wire from the bus by a given index.