diff --git a/b_asic/signal_flow_graph.py b/b_asic/signal_flow_graph.py index 5713c192fff3db669c4297566c2c6262e06cfaad..d0e44afdb4e74a273b09233e67579f15a70edb73 100644 --- a/b_asic/signal_flow_graph.py +++ b/b_asic/signal_flow_graph.py @@ -232,14 +232,31 @@ class SFG(AbstractOperation): return value def split(self) -> Iterable[Operation]: - """ Returns every operation in the SFG except for Input and Output types. """ + """ Iterates over the SFG's Input- and OutputSignals to reconnect them to each necessary operation inside the SFG, + so that the inner operations of the SFG can function on their own, effectively replacing the SFG. """ - ops = [] - for op in self.operations: - if not isinstance(op, Input) and not isinstance(op, Output): - ops.append(op) + # For each input_signal, connect it to the corresponding operation + for port, input_operation in zip(self.inputs, self.input_operations): + # Connect the signal to the new destination + port.signals[0].set_destination(input_operation.output(0).signals[0].destination) - return ops # Need any checking before returning? + # For each output_signal, connect it to the corresponding operation + for port, output_operation in zip(self.outputs, self.output_operations): + # Connect the signal to the new source + port.signals[0].set_source(output_operation.input[0].signals[0].source) + + + + + @property + def input_operations(self) -> Sequence[Operation]: + """Get the internal input operations in the same order as their respective input ports.""" + return self._input_operations + + @property + def output_operations(self) -> Sequence[Operation]: + """Get the internal output operations in the same order as their respective output ports.""" + return self._output_operations def copy_component(self, *args, **kwargs) -> GraphComponent: return super().copy_component(*args, **kwargs, inputs = self._input_operations, outputs = self._output_operations,