X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fcomponents%2FSplitter.java;h=4764c27a1de2b7e69d02975f4eac192a8b7cccd8;hb=e7180dd9040734555e6a07f2561fb688118b7002;hp=e936c82e30c11714741db0dc85efae3d9ba971a0;hpb=70afb26181aba8de30ea6f796ea5c2a573d9ecab;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 e936c82e..4764c27a 100644 --- a/era.mi/src/era/mi/logic/components/Splitter.java +++ b/era.mi/src/era/mi/logic/components/Splitter.java @@ -1,43 +1,43 @@ -package era.mi.logic.components; - -import era.mi.logic.types.BitVector; -import era.mi.logic.wires.Wire; -import era.mi.logic.wires.Wire.WireEnd; -import era.mi.logic.wires.WireObserver; - -public class Splitter implements WireObserver -{ - private WireEnd input; - private WireEnd[] outputs; - - public Splitter(WireEnd input, WireEnd... outputs) - { - this.input = input; - this.outputs = outputs; - input.addObserver(this); - int length = 0; - for (WireEnd 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() - { - BitVector inputBits = input.getValues(); - int startIndex = 0; - for (int i = 0; i < outputs.length; i++) - { - outputs[i].feedSignals(inputBits.subVector(startIndex, startIndex + outputs[i].length())); - startIndex += outputs[i].length(); - } - } - - @Override - public void update(Wire initiator, BitVector oldValues) - { - compute(); - } -} +package era.mi.logic.components; + +import era.mi.logic.types.BitVector; +import era.mi.logic.wires.Wire; +import era.mi.logic.wires.Wire.WireEnd; +import era.mi.logic.wires.WireObserver; + +public class Splitter implements WireObserver +{ + private WireEnd input; + private WireEnd[] outputs; + + public Splitter(WireEnd input, WireEnd... outputs) + { + this.input = input; + this.outputs = outputs; + input.addObserver(this); + int length = 0; + for (WireEnd 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() + { + BitVector inputBits = input.getValues(); + int startIndex = 0; + for (int i = 0; i < outputs.length; i++) + { + outputs[i].feedSignals(inputBits.subVector(startIndex, startIndex + outputs[i].length())); + startIndex += outputs[i].length(); + } + } + + @Override + public void update(Wire initiator, BitVector oldValues) + { + compute(); + } +}