X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fcomponents%2Fgates%2FMultiInputGate.java;h=e76661d92baa000c4e3ff270cada86078d978d97;hb=70afb26181aba8de30ea6f796ea5c2a573d9ecab;hp=2094b846f6b13a295aad96a559dc8fb698207088;hpb=f2cd90fa2b844507bc9697d3af1f3e18aac80b37;p=Mograsim.git diff --git a/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java b/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java index 2094b846..e76661d9 100644 --- a/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java +++ b/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java @@ -2,45 +2,43 @@ package era.mi.logic.components.gates; import java.util.List; -import era.mi.logic.Bit; import era.mi.logic.components.BasicComponent; -import era.mi.logic.wires.WireArray; -import era.mi.logic.wires.WireArray.WireArrayEnd; +import era.mi.logic.types.BitVector.BitVectorMutator; +import era.mi.logic.types.MutationOperation; +import era.mi.logic.wires.Wire.WireEnd; public abstract class MultiInputGate extends BasicComponent { - protected WireArray[] in; - protected WireArray out; - protected WireArrayEnd outI; + protected WireEnd[] in; + protected WireEnd out; protected final int length; - protected Operation op; + protected MutationOperation op; - protected MultiInputGate(int processTime, Operation op, WireArray out, WireArray... in) + protected MultiInputGate(int processTime, MutationOperation op, WireEnd out, WireEnd... in) { super(processTime); this.op = op; - length = out.length; + length = out.length(); this.in = in.clone(); if (in.length < 1) throw new IllegalArgumentException(String.format("Cannot create gate with %d wires.", in.length)); - for (WireArray w : in) + for (WireEnd w : in) { - if (w.length != length) + if (w.length() != length) throw new IllegalArgumentException("All wires connected to the gate must be of uniform length."); w.addObserver(this); } this.out = out; - outI = out.createInput(); } @Override - public List getAllInputs() + public List getAllInputs() { return List.of(in); } @Override - public List getAllOutputs() + public List getAllOutputs() { return List.of(out); } @@ -48,14 +46,9 @@ public abstract class MultiInputGate extends BasicComponent @Override protected void compute() { - Bit[] result = in[0].getValues(); - for (int i = 1; i < in.length; i++) - result = op.execute(result, in[i].getValues()); - outI.feedSignals(result); - } - - protected interface Operation - { - public Bit[] execute(Bit[] a, Bit[] b); + BitVectorMutator mutator = BitVectorMutator.empty(); + for (WireEnd w : in) + op.apply(mutator, w.getValues()); + out.feedSignals(mutator.get()); } }