X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fcomponents%2FMerger.java;h=a9d1410160808ebb866f57e34a90b395a4dab6b9;hb=b7ce41467a2cbd9f45554982730741810e99feaa;hp=1efcf8ad276cf0d6d4922ed92bda4a466af458fc;hpb=74aebd92f41d03f4a44c9a455ef8c05465136412;p=Mograsim.git diff --git a/era.mi/src/era/mi/logic/components/Merger.java b/era.mi/src/era/mi/logic/components/Merger.java index 1efcf8ad..a9d14101 100644 --- a/era.mi/src/era/mi/logic/components/Merger.java +++ b/era.mi/src/era/mi/logic/components/Merger.java @@ -1,74 +1,83 @@ package era.mi.logic.components; -import java.util.Arrays; -import java.util.Collections; import java.util.List; -import era.mi.logic.Bit; -import era.mi.logic.wires.WireArray; -import era.mi.logic.wires.WireArray.WireArrayInput; -import era.mi.logic.wires.WireArrayObserver; +import era.mi.logic.types.BitVector; +import era.mi.logic.wires.Wire; +import era.mi.logic.wires.Wire.ReadEnd; +import era.mi.logic.wires.Wire.ReadWriteEnd; +import era.mi.logic.wires.WireObserver; -public class Merger implements WireArrayObserver, Component { - private WireArrayInput outI; - private WireArray[] inputs; +public class Merger implements WireObserver, Component +{ + private ReadWriteEnd out; + private ReadEnd[] inputs; private int[] beginningIndex; /** * - * @param union The output of merging n {@link WireArray}s into one. Must have length = a1.length() + a2.length() + ... + an.length(). + * @param union The output of merging n {@link Wire}s into one. Must have length = a1.length() + a2.length() + ... + an.length(). * @param inputs The inputs to be merged into the union */ - public Merger(WireArray union, WireArray... inputs) { + public Merger(ReadWriteEnd union, ReadEnd... inputs) + { this.inputs = inputs; - this.outI = union.createInput(); + this.out = union; this.beginningIndex = new int[inputs.length]; int length = 0; - for (int i = 0; i < inputs.length; i++) { + for (int i = 0; i < inputs.length; i++) + { beginningIndex[i] = length; - length += inputs[i].length; + length += inputs[i].length(); inputs[i].addObserver(this); } - if (length != union.length) + if (length != union.length()) throw new IllegalArgumentException( "The output of merging n WireArrays into one must have length = a1.length() + a2.length() + ... + an.length()."); } - public WireArray getInput(int index) { + public ReadEnd getInput(int index) + { return inputs[index]; } - public WireArray getUnion() { - return outI.owner; + public ReadEnd getUnion() + { + return out; } @Override - public void update(WireArray initiator, Bit[] oldValues) { + public void update(ReadEnd initiator, BitVector oldValues) + { int index = find(initiator); int beginning = beginningIndex[index]; - outI.feedSignals(beginning, initiator.getValues()); + out.feedSignals(beginning, inputs[index].getValues()); } - private int find(WireArray w) { + private int find(ReadEnd r) + { for (int i = 0; i < inputs.length; i++) - if (inputs[i] == w) + if (inputs[i] == r) return i; return -1; } - public WireArray[] getInputs() { + public ReadEnd[] getInputs() + { return inputs.clone(); } @Override - public List getAllInputs() { - return Collections.unmodifiableList(Arrays.asList(inputs)); + public List getAllInputs() + { + return List.of(inputs); } @Override - public List getAllOutputs() { - return Collections.unmodifiableList(Arrays.asList(outI.owner)); + public List getAllOutputs() + { + return List.of(out); } }