1 package net.mograsim.logic.core.components;
\r
3 import java.util.List;
\r
5 import net.mograsim.logic.core.LogicObservable;
\r
6 import net.mograsim.logic.core.LogicObserver;
\r
7 import net.mograsim.logic.core.timeline.Timeline;
\r
8 import net.mograsim.logic.core.types.BitVector;
\r
9 import net.mograsim.logic.core.wires.Wire.ReadEnd;
\r
10 import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;
\r
12 public class Splitter extends Component implements LogicObserver
\r
14 private ReadEnd input;
\r
15 private ReadWriteEnd[] outputs;
\r
17 public Splitter(Timeline timeline, ReadEnd input, ReadWriteEnd... outputs)
\r
21 this.outputs = outputs;
\r
22 input.registerObserver(this);
\r
24 for (ReadEnd out : outputs)
\r
25 length += out.length();
\r
27 if (input.length() != length)
\r
28 throw new IllegalArgumentException(
\r
29 "The input of splitting one into n WireArrays must have length = a1.length() + a2.length() + ... + an.length().");
\r
32 protected void compute()
\r
34 BitVector inputBits = input.getValues();
\r
36 for (int i = 0; i < outputs.length; i++)
\r
38 outputs[i].feedSignals(inputBits.subVector(startIndex, startIndex + outputs[i].length()));
\r
39 startIndex += outputs[i].length();
\r
44 public void update(LogicObservable initiator)
\r
50 public List<ReadEnd> getAllInputs()
\r
52 return List.of(input);
\r
56 public List<ReadWriteEnd> getAllOutputs()
\r
58 return List.of(outputs);
\r