package net.mograsim.machine;
-public interface MicroInstruction {
+import net.mograsim.machine.mnemonics.Mnemonic;
+public interface MicroInstruction {
+
+ public Mnemonic getValue(int index);
+
+ /**
+ * @return The amount of {@link Mnemonic}s, the instruction is composed of
+ */
+ public int getSize();
}
--- /dev/null
+package net.mograsim.machine;
+
+import net.mograsim.machine.mnemonics.Mnemonic;
+import net.mograsim.machine.mnemonics.MnemonicFamily;
+
+public interface MicroInstructionDefinition
+{
+ /**
+ * @return The {@link MnemonicFamily}s of which a MicroInstruction is composed.
+ */
+ public MnemonicFamily[] getMnemonicFamilies();
+
+ /**
+ * @return The amount of {@link Mnemonic}s a {@link MicroInstruction} that follows this definition consists of.
+ */
+ public int size();
+
+}
package net.mograsim.machine;
public interface MicroprogramMemory {
-
+
+ /**
+ * @param address The address of the desired instruction. Must be non-negative
+ * @return The instruction at the requested address
+ *
+ * @throws IndexOutOfBoundsException
+ */
+ public MicroInstruction getInstruction(long address);
+
+ /**
+ * Sets the instruction at the supplied address
+ * @param address
+ * @param instruction
+ *
+ * @throws IndexOutOfBoundsException
+ */
+ public void setInstruction(long address, MicroInstruction instruction);
}
--- /dev/null
+package net.mograsim.machine.mnemonics;
+
+import net.mograsim.logic.core.types.BitVector;
+
+public final class Mnemonic
+{
+ private final String text;
+ private final BitVector vector;
+
+ public Mnemonic(String text, BitVector vector)
+ {
+ super();
+ this.text = text;
+ this.vector = vector;
+ }
+
+ public String getText()
+ {
+ return text;
+ }
+
+ public BitVector getVector()
+ {
+ return vector;
+ }
+}
--- /dev/null
+package net.mograsim.machine.mnemonics;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class MnemonicFamily
+{
+ private final Mnemonic[] values;
+ private final Map<String, Mnemonic> byText;
+ private final int vectorLenght;
+
+ public MnemonicFamily(Mnemonic... values)
+ {
+ this.values = values;
+ if(values.length == 0)
+ vectorLenght = 0;
+ else
+ {
+ vectorLenght = values[0].getVector().width();
+ for(int i = 1; i < values.length; i++)
+ if(values[i].getVector().width() != vectorLenght)
+ throw new IllegalArgumentException("MnemonicFamily is not of uniform vector length!");
+ }
+ byText = Arrays.stream(values).collect(Collectors.toMap(m -> m.getText(), m -> m));
+ }
+
+ public Mnemonic[] getValues()
+ {
+ return values.clone();
+ }
+
+ public Mnemonic get(String text)
+ {
+ return byText.get(text);
+ }
+
+ public boolean contains(Mnemonic m)
+ {
+ if(m != null)
+ return m.equals(byText.get(m.getText()));
+ else
+ return false;
+ }
+
+ public int size()
+ {
+ return values.length;
+ }
+
+ public int getVectorLength()
+ {
+ return vectorLenght;
+ }
+}