Reworked Parameter Classifications
[Mograsim.git] / net.mograsim.machine / src / net / mograsim / machine / mi / parameters / MnemonicFamily.java
index aa07f80..62785be 100644 (file)
@@ -10,21 +10,23 @@ public class MnemonicFamily implements ParameterClassification
 {
        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()
@@ -45,6 +47,11 @@ public class MnemonicFamily implements ParameterClassification
                        return false;
        }
        
+       public boolean contains(String value)
+       {
+               return byText.keySet().contains(value);
+       }
+       
        public int size()
        {
                return values.length;
@@ -52,13 +59,13 @@ public class MnemonicFamily implements ParameterClassification
        
        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
@@ -66,4 +73,15 @@ public class MnemonicFamily implements ParameterClassification
        {
                return ParameterType.MNEMONIC;
        }
+
+       @Override
+       public int getExpectedBits()
+       {
+               return vectorLength;
+       }
+
+       public String[] getStringValues()
+       {
+               return byText.keySet().toArray(new String[values.length]);
+       }
 }