/**
* @return The amount of {@link MicroInstructionParameter}s in a {@link MicroInstruction} that follows this definition.
*/
- public int size();
+ public default int size()
+ {
+ return getParameterClassifications().length;
+ }
}
--- /dev/null
+package net.mograsim.machine.mi.parameters;
+
+import net.mograsim.machine.mi.parameters.MicroInstructionParameter.ParameterType;
+
+public class BooleanClassification implements ParameterClassification
+{
+ @Override
+ public ParameterType getExpectedType()
+ {
+ return ParameterType.BOOLEAN_IMMEDIATE;
+ }
+
+ @Override
+ public int getExpectedBits()
+ {
+ return 1;
+ }
+}
--- /dev/null
+package net.mograsim.machine.mi.parameters;
+
+import net.mograsim.machine.mi.parameters.MicroInstructionParameter.ParameterType;
+
+public class IntegerClassification implements ParameterClassification
+{
+ private final int bits;
+
+ public IntegerClassification(int bits)
+ {
+ this.bits = bits;
+ }
+
+ @Override
+ public ParameterType getExpectedType()
+ {
+ return ParameterType.INTEGER_IMMEDIATE;
+ }
+
+ @Override
+ public int getExpectedBits()
+ {
+ return bits;
+ }
+}
{
return ParameterType.MNEMONIC;
}
+
+ @Override
+ public String toString()
+ {
+ return text;
+ }
}
{
private final Mnemonic[] values;
private final Map<String, Mnemonic> byText;
- private final int vectorLenght;
+ private final int vectorLength;
public MnemonicFamily(Mnemonic... values)
{
this.values = values;
if(values.length == 0)
- vectorLenght = 0;
+ vectorLength = 0;
else
{
- vectorLenght = values[0].getValue().width();
+ vectorLength = values[0].getValue().width();
for(int i = 1; i < values.length; i++)
- if(values[i].getValue().width() != vectorLenght)
+ if(values[i].getValue().width() != vectorLength)
throw new IllegalArgumentException("MnemonicFamily is not of uniform vector length!");
}
byText = Arrays.stream(values).collect(Collectors.toMap(m -> m.getText(), m -> m));
+ if(values.length != byText.keySet().size())
+ throw new IllegalArgumentException("MnemonicFamily contains multiple Mnemonics with the same name!");
}
public Mnemonic[] getValues()
return false;
}
+ public boolean contains(String value)
+ {
+ return byText.keySet().contains(value);
+ }
+
public int size()
{
return values.length;
public int getVectorLength()
{
- return vectorLenght;
+ return vectorLength;
}
@Override
public boolean conforms(MicroInstructionParameter param)
{
- return param instanceof Mnemonic ? contains((Mnemonic) param) : false;
+ return ParameterClassification.super.conforms(param) && (param instanceof Mnemonic ? contains((Mnemonic) param) : false);
}
@Override
{
return ParameterType.MNEMONIC;
}
+
+ @Override
+ public int getExpectedBits()
+ {
+ return vectorLength;
+ }
+
+ public String[] getStringValues()
+ {
+ return byText.keySet().toArray(new String[values.length]);
+ }
}
* Determines whether a {@link MicroInstructionParameter} is part of this class of parameters.
* @return true if the classification contains the Parameter, false otherwise
*/
- public boolean conforms(MicroInstructionParameter param);
+ public default boolean conforms(MicroInstructionParameter param)
+ {
+ return param.getType().equals(getExpectedType()) && param.getValue().width() == getExpectedBits();
+ }
/**
* @return The type of the parameters in this classification.
*/
public ParameterType getExpectedType();
+
+ /**
+ * @return The number of bits of the parameters in this classification.
+ */
+ public int getExpectedBits();
}
+++ /dev/null
-package net.mograsim.machine.mi.parameters;
-
-import net.mograsim.machine.mi.parameters.MicroInstructionParameter.ParameterType;
-
-public class SimpleTypeClassification implements ParameterClassification
-{
- private ParameterType expectedType;
-
- public SimpleTypeClassification(ParameterType expectedType)
- {
- this.expectedType = expectedType;
- }
-
- @Override
- public boolean conforms(MicroInstructionParameter param)
- {
- return expectedType.equals(param.getType());
- }
-
- @Override
- public ParameterType getExpectedType()
- {
- return expectedType;
- }
-}