1 package net.mograsim.logic.core.components.gates;
5 import net.mograsim.logic.core.components.BasicComponent;
6 import net.mograsim.logic.core.timeline.Timeline;
7 import net.mograsim.logic.core.types.MutationOperation;
8 import net.mograsim.logic.core.types.BitVector.BitVectorMutator;
9 import net.mograsim.logic.core.wires.Wire.ReadEnd;
10 import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;
12 public abstract class MultiInputGate extends BasicComponent
14 protected ReadEnd[] in;
15 protected ReadWriteEnd out;
16 protected final int length;
17 protected MutationOperation op;
19 protected MultiInputGate(Timeline timeline, int processTime, MutationOperation op, ReadWriteEnd out, ReadEnd... in)
21 super(timeline, processTime);
23 length = out.length();
26 throw new IllegalArgumentException(String.format("Cannot create gate with %d wires.", in.length));
29 if (w.length() != length)
30 throw new IllegalArgumentException("All wires connected to the gate must be of uniform length.");
37 public List<ReadEnd> getAllInputs()
43 public List<ReadWriteEnd> getAllOutputs()
49 protected void compute()
51 BitVectorMutator mutator = BitVectorMutator.empty();
53 op.apply(mutator, w.getValues());
54 out.feedSignals(mutator.get());