1 package net.mograsim.machine.mi;
3 import java.math.BigInteger;
5 import net.mograsim.machine.mi.parameters.IntegerClassification;
6 import net.mograsim.machine.mi.parameters.IntegerImmediate;
7 import net.mograsim.machine.mi.parameters.MicroInstructionParameter;
8 import net.mograsim.machine.mi.parameters.MnemonicFamily;
9 import net.mograsim.machine.mi.parameters.ParameterClassification;
10 import net.mograsim.machine.mi.parameters.MicroInstructionParameter.ParameterType;
12 public interface MicroInstructionDefinition
15 * @return The {@link ParameterClassification}s of which a MicroInstruction is composed.
17 public ParameterClassification[] getParameterClassifications();
20 * @throws IndexOutOfBoundsException
22 public ParameterClassification getParameterClassification(int index);
26 * @return The amount of {@link MicroInstructionParameter}s in a {@link MicroInstruction} that follows this definition.
28 public default int size()
30 return getParameterClassifications().length;
33 public default MicroInstruction createDefaultInstruction()
36 MicroInstructionParameter[] params = new MicroInstructionParameter[size];
37 ParameterClassification[] classes = getParameterClassifications();
38 for(int i = 0; i < size; i++)
40 MicroInstructionParameter newParam;
41 ParameterClassification classification = classes[i];
42 ParameterType type = classification.getExpectedType();
45 case BOOLEAN_IMMEDIATE:
47 newParam = ((MnemonicFamily) classification).get(0);
49 case INTEGER_IMMEDIATE:
50 newParam = new IntegerImmediate(BigInteger.valueOf(0), ((IntegerClassification) classification).getExpectedBits());
53 throw new IllegalStateException("Unknown ParameterType " + type);
57 return new StandardMicroInstruction(params);
60 public static MicroInstructionDefinition create(ParameterClassification... classes)
62 return new StandardMicroInstructionDefinition(classes);