1 package net.mograsim.machine.mi.parameters;
3 import java.util.Arrays;
5 import java.util.stream.Collectors;
7 import net.mograsim.machine.mi.parameters.MicroInstructionParameter.ParameterType;
9 public class MnemonicFamily implements ParameterClassification
11 private final Mnemonic[] values;
12 private final Map<String, Mnemonic> byText;
13 private final int vectorLength;
15 public MnemonicFamily(Mnemonic... values)
18 if(values.length == 0)
22 vectorLength = values[0].getValue().length();
23 for(int i = 1; i < values.length; i++)
24 if(values[i].getValue().length() != vectorLength)
25 throw new IllegalArgumentException("MnemonicFamily is not of uniform vector length!");
27 byText = Arrays.stream(values).collect(Collectors.toMap(m -> m.getText(), m -> m));
28 if(values.length != byText.keySet().size())
29 throw new IllegalArgumentException("MnemonicFamily contains multiple Mnemonics with the same name!");
32 public Mnemonic[] getValues()
34 return values.clone();
37 public Mnemonic get(String text)
39 return byText.get(text);
42 public boolean contains(Mnemonic m)
45 return m.equals(byText.get(m.getText()));
50 public boolean contains(String value)
52 return byText.keySet().contains(value);
60 public int getVectorLength()
66 public boolean conforms(MicroInstructionParameter param)
68 return ParameterClassification.super.conforms(param) && (param instanceof Mnemonic ? contains((Mnemonic) param) : false);
72 public ParameterType getExpectedType()
74 return ParameterType.MNEMONIC;
78 public int getExpectedBits()
83 public String[] getStringValues()
85 return byText.keySet().toArray(new String[values.length]);