0th Mnemonic is default Mnemonic not otherwise specified
authorFabian Stemmler <stemmler@in.tum.de>
Thu, 10 Oct 2019 11:57:23 +0000 (13:57 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Fri, 11 Oct 2019 13:29:41 +0000 (15:29 +0200)
plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/MnemonicFamily.java

index 445485b..aecf7c5 100644 (file)
@@ -8,6 +8,7 @@ import java.util.stream.Collectors;
 
 import net.mograsim.logic.core.types.Bit;
 import net.mograsim.logic.core.types.BitVector;
+import net.mograsim.machine.MachineException;
 import net.mograsim.machine.mi.parameters.MicroInstructionParameter.ParameterType;
 
 public class MnemonicFamily implements ParameterClassification
@@ -20,12 +21,15 @@ public class MnemonicFamily implements ParameterClassification
 
        MnemonicFamily(String defaultValueName, MnemonicPair... values)
        {
+               if (values.length == 0)
+                       throw new MachineException("Mnemonics must not be empty!");
                this.values = new Mnemonic[values.length];
                this.stringValues = new String[values.length];
 
                setup(values);
 
-               int defaultValueIndex = -1;
+               // if no valid defaultValue is specified, pick first value as default
+               int defaultValueIndex = 0;
                for (int i = 0; i < values.length; i++)
                        if (stringValues[i].equals(defaultValueName))
                        {