X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fcomponents%2Fgates%2FMultiInputGate.java;h=79a1df50185d56024d66ff930239ca8aa6d0c0d2;hb=ecc651406020231ff0ebc8d1bfc6f916693f69c6;hp=afc89511e72cb0f208d22ae759be6c01c1bff5ef;hpb=67c1d352795802dae0c045cedeed82c883819d4e;p=Mograsim.git diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/gates/MultiInputGate.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/gates/MultiInputGate.java index afc89511..79a1df50 100644 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/gates/MultiInputGate.java +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/gates/MultiInputGate.java @@ -1,56 +1,56 @@ -package net.mograsim.logic.core.components.gates; - -import java.util.List; - -import net.mograsim.logic.core.components.BasicComponent; -import net.mograsim.logic.core.timeline.Timeline; -import net.mograsim.logic.core.types.MutationOperation; -import net.mograsim.logic.core.types.BitVector.BitVectorMutator; -import net.mograsim.logic.core.wires.Wire.ReadEnd; -import net.mograsim.logic.core.wires.Wire.ReadWriteEnd; - -public abstract class MultiInputGate extends BasicComponent -{ - protected ReadEnd[] in; - protected ReadWriteEnd out; - protected final int length; - protected MutationOperation op; - - protected MultiInputGate(Timeline timeline, int processTime, MutationOperation op, ReadWriteEnd out, ReadEnd... in) - { - 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 (ReadEnd w : in) - { - if (w.length() != length) - throw new IllegalArgumentException("All wires connected to the gate must be of uniform length."); - w.addObserver(this); - } - this.out = out; - } - - @Override - public List getAllInputs() - { - return List.of(in); - } - - @Override - public List getAllOutputs() - { - return List.of(out); - } - - @Override - protected void compute() - { - BitVectorMutator mutator = BitVectorMutator.empty(); - for (ReadEnd w : in) - op.apply(mutator, w.getValues()); - out.feedSignals(mutator.get()); - } -} +package net.mograsim.logic.core.components.gates; + +import java.util.List; + +import net.mograsim.logic.core.components.BasicComponent; +import net.mograsim.logic.core.timeline.Timeline; +import net.mograsim.logic.core.types.MutationOperation; +import net.mograsim.logic.core.types.BitVector.BitVectorMutator; +import net.mograsim.logic.core.wires.Wire.ReadEnd; +import net.mograsim.logic.core.wires.Wire.ReadWriteEnd; + +public abstract class MultiInputGate extends BasicComponent +{ + protected ReadEnd[] in; + protected ReadWriteEnd out; + protected final int length; + protected MutationOperation op; + + protected MultiInputGate(Timeline timeline, int processTime, MutationOperation op, ReadWriteEnd out, ReadEnd... in) + { + 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 (ReadEnd w : in) + { + if (w.length() != length) + throw new IllegalArgumentException("All wires connected to the gate must be of uniform length."); + w.registerObserver(this); + } + this.out = out; + } + + @Override + public List getAllInputs() + { + return List.of(in); + } + + @Override + public List getAllOutputs() + { + return List.of(out); + } + + @Override + protected void compute() + { + BitVectorMutator mutator = BitVectorMutator.empty(); + for (ReadEnd w : in) + op.apply(mutator, w.getValues()); + out.feedSignals(mutator.get()); + } +}