1 package net.mograsim.machine.mi;
3 import java.util.Arrays;
4 import java.util.Optional;
6 import net.mograsim.logic.core.types.Bit;
7 import net.mograsim.machine.mi.parameters.MicroInstructionParameter;
8 import net.mograsim.machine.mi.parameters.ParameterClassification;
10 public interface MicroInstructionDefinition
13 * @return The {@link ParameterClassification}s of which a MicroInstruction is composed.
15 public ParameterClassification[] getParameterClassifications();
18 * @throws IndexOutOfBoundsException
20 public ParameterClassification getParameterClassification(int index);
23 * @return The amount of {@link MicroInstructionParameter}s in a {@link MicroInstruction} that follows this definition.
25 public default int size()
27 return getParameterClassifications().length;
31 * @return The amount of {@link Bit}s in a {@link MicroInstruction} that follows this definition.
33 public default int sizeInBits()
35 return Arrays.stream(getParameterClassifications()).mapToInt(e -> e.getExpectedBits()).reduce(0, (a, b) -> a + b);
38 public default MicroInstruction createDefaultInstruction()
41 MicroInstructionParameter[] params = new MicroInstructionParameter[size];
42 ParameterClassification[] classes = getParameterClassifications();
43 for (int i = 0; i < size; i++)
45 ParameterClassification classification = classes[i];
46 params[i] = classification.getDefault();
48 return new StandardMicroInstruction(params);
51 public Optional<String> getParameterDescription(int index);