From b1784ddec05aa9c7859688c6d1631648769f742d Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson <rasmus@rasmus.local> Date: Wed, 22 Apr 2020 21:10:50 +0200 Subject: [PATCH] Implemented Split function. Need to do some testing and write some secure code for Split. Added two properties to SFG class --- b_asic/signal_flow_graph.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/b_asic/signal_flow_graph.py b/b_asic/signal_flow_graph.py index 5713c192..d0e44afd 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, -- GitLab