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