X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fcomponents%2FSplitter.java;h=ff23e5c5f529a2c8a3a22224e6d3adb7c67c202b;hb=72b00816f86e5d34d871c87fea76a94ffca25246;hp=58d48e7c563861d3555d1d862dabd6dca3f68c2c;hpb=4c8fb641dc21efe699f457dcd48fc3cf3660740d;p=Mograsim.git diff --git a/era.mi/src/era/mi/logic/components/Splitter.java b/era.mi/src/era/mi/logic/components/Splitter.java index 58d48e7c..ff23e5c5 100644 --- a/era.mi/src/era/mi/logic/components/Splitter.java +++ b/era.mi/src/era/mi/logic/components/Splitter.java @@ -1,53 +1,40 @@ -package era.mi.logic.components; - -import era.mi.logic.Bit; -import era.mi.logic.wires.WireArray; -import era.mi.logic.wires.WireArrayObserver; - -public class Splitter implements WireArrayObserver -{ - private WireArray input; - private WireArray[] outputs; - - public Splitter(WireArray input, WireArray... outputs) - { - this.input = input; - this.outputs = outputs; - input.addObserver(this); - int length = 0; - for(WireArray out : outputs) - length += out.length; - - if(input.length != length) - throw new IllegalArgumentException("The input of splitting one into n WireArrays must have length = a1.length() + a2.length() + ... + an.length()."); - } - - protected void compute() - { - int startIndex = 0; - Bit[] inputBits = input.getValues(); - for(int i = 0; i < outputs.length; i++) - { - Bit[] outputBits = new Bit[outputs[i].length]; - System.arraycopy(inputBits, startIndex, outputBits, 0, outputs[i].length); - outputs[i].feedSignals(outputBits); - startIndex += outputs[i].length; - } - } - - public WireArray getInput() - { - return input; - } - - public WireArray[] getOutputs() - { - return outputs.clone(); - } - - @Override - public void update(WireArray initiator) - { - compute(); - } -} +package era.mi.logic.components; + +import era.mi.logic.Bit; +import era.mi.logic.wires.WireArray; +import era.mi.logic.wires.WireArray.WireArrayInput; +import era.mi.logic.wires.WireArrayObserver; + +public class Splitter implements WireArrayObserver { + private WireArray input; + private WireArrayInput[] outputs; + + public Splitter(WireArray input, WireArray... outputs) { + this.input = input; + this.outputs = WireArray.extractInputs(outputs); + input.addObserver(this); + int length = 0; + for (WireArray out : outputs) + length += out.length; + + if (input.length != length) + throw new IllegalArgumentException( + "The input of splitting one into n WireArrays must have length = a1.length() + a2.length() + ... + an.length()."); + } + + protected void compute() { + int startIndex = 0; + Bit[] inputBits = input.getValues(); + for (int i = 0; i < outputs.length; i++) { + Bit[] outputBits = new Bit[outputs[i].owner.length]; + System.arraycopy(inputBits, startIndex, outputBits, 0, outputs[i].owner.length); + outputs[i].feedSignals(outputBits); + startIndex += outputs[i].owner.length; + } + } + + @Override + public void update(WireArray initiator, Bit[] oldValues) { + compute(); + } +}