X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fcomponents%2Fgates%2FMultiInputGate.java;h=038e22728fe080d89f3bde1b760a834258f780de;hb=6c67a9ff8361cd9fc082f40e2676f2c8b5911fe4;hp=2b0a529296d8e5962cf9c67f99638a11413a2753;hpb=dcbba0b189fd37135adc4487f1b8b645e7045bc4;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 2b0a5292..038e2272 100644 --- a/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java +++ b/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java @@ -3,25 +3,28 @@ package era.mi.logic.components.gates; import java.util.List; import era.mi.logic.components.BasicComponent; -import era.mi.logic.types.Bit; -import era.mi.logic.wires.Wire.WireEnd; +import era.mi.logic.timeline.Timeline; +import era.mi.logic.types.BitVector.BitVectorMutator; +import era.mi.logic.types.MutationOperation; +import era.mi.logic.wires.Wire.ReadEnd; +import era.mi.logic.wires.Wire.ReadWriteEnd; public abstract class MultiInputGate extends BasicComponent { - protected WireEnd[] in; - protected WireEnd out; + protected ReadEnd[] in; + protected ReadWriteEnd out; protected final int length; - protected Operation op; + protected MutationOperation op; - protected MultiInputGate(int processTime, Operation op, WireEnd out, WireEnd... in) + protected MultiInputGate(Timeline timeline, int processTime, MutationOperation op, ReadWriteEnd out, ReadEnd... in) { - super(processTime); + super(timeline, processTime); this.op = op; 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 (WireEnd w : in) + for (ReadEnd w : in) { if (w.length() != length) throw new IllegalArgumentException("All wires connected to the gate must be of uniform length."); @@ -31,13 +34,13 @@ public abstract class MultiInputGate extends BasicComponent } @Override - public List getAllInputs() + public List getAllInputs() { return List.of(in); } @Override - public List getAllOutputs() + public List getAllOutputs() { return List.of(out); } @@ -45,14 +48,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()); - out.feedSignals(result); - } - - protected interface Operation - { - public Bit[] execute(Bit[] a, Bit[] b); + BitVectorMutator mutator = BitVectorMutator.empty(); + for (ReadEnd w : in) + op.apply(mutator, w.getValues()); + out.feedSignals(mutator.get()); } }