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.wires.CoreWire;
9 import net.mograsim.logic.core.wires.CoreWire.ReadEnd;
10 import net.mograsim.logic.core.wires.CoreWire.ReadWriteEnd;
12 public class CoreUnidirectionalMerger extends CoreComponent implements LogicObserver
14 private ReadWriteEnd out;
15 private ReadEnd[] inputs;
16 private int[] beginningIndex;
20 * @param union The output of merging n {@link CoreWire}s into one. Must have width = a1.width() + a2.width() + ... + an.width().
21 * @param inputs The inputs to be merged into the union
23 public CoreUnidirectionalMerger(Timeline timeline, ReadWriteEnd union, ReadEnd... inputs)
28 this.beginningIndex = new int[inputs.length];
31 for (int i = 0; i < inputs.length; i++)
33 beginningIndex[i] = width;
34 width += inputs[i].width();
35 inputs[i].registerObserver(this);
38 if (width != union.width())
39 throw new IllegalArgumentException(
40 "The output of merging n WireArrays into one must have width = a1.width() + a2.width() + ... + an.width().");
43 public ReadEnd getInput(int index)
48 public ReadEnd getUnion()
54 public void update(LogicObservable initiator)
56 int index = find(initiator);
57 int beginning = beginningIndex[index];
58 out.feedSignals(beginning, inputs[index].getValues());
61 private int find(LogicObservable r)
63 for (int i = 0; i < inputs.length; i++)
69 public ReadEnd[] getInputs()
71 return inputs.clone();
75 public List<ReadEnd> getAllInputs()
77 return List.of(inputs);
81 public List<ReadWriteEnd> getAllOutputs()