package net.mograsim.machine;
-import net.mograsim.machine.mnemonics.Mnemonic;
+import net.mograsim.machine.mi.parameters.MicroInstructionParameter;
+import net.mograsim.machine.mi.parameters.Mnemonic;
public interface MicroInstruction {
- public Mnemonic getValue(int index);
+ public MicroInstructionParameter getParameter(int index);
/**
* @return The amount of {@link Mnemonic}s, the instruction is composed of
package net.mograsim.machine;
-import net.mograsim.machine.mnemonics.Mnemonic;
-import net.mograsim.machine.mnemonics.MnemonicFamily;
+import net.mograsim.machine.mi.parameters.MicroInstructionParameter;
+import net.mograsim.machine.mi.parameters.ParameterClassification;
public interface MicroInstructionDefinition
{
/**
- * @return The {@link MnemonicFamily}s of which a MicroInstruction is composed.
+ * @return The {@link ParameterClassification}s of which a MicroInstruction is composed.
*/
- public MnemonicFamily[] getMnemonicFamilies();
+ public ParameterClassification[] getParameterClassifications();
/**
- * @return The amount of {@link Mnemonic}s a {@link MicroInstruction} that follows this definition consists of.
+ * @return The amount of {@link MicroInstructionParameter}s in a {@link MicroInstruction} that follows this definition.
*/
public int size();
--- /dev/null
+package net.mograsim.machine.mi.parameters;
+
+import net.mograsim.logic.core.types.BitVector;
+
+public class BooleanImmediate implements MicroInstructionParameter
+{
+ private boolean value;
+
+ public BooleanImmediate(boolean value)
+ {
+ this.value = value;
+ }
+
+ @Override
+ public BitVector getValue()
+ {
+ return value ? BitVector.SINGLE_1 : BitVector.SINGLE_0;
+ }
+
+ @Override
+ public ParameterType getType()
+ {
+ return ParameterType.BOOLEAN_IMMEDIATE;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (value ? 1231 : 1237);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof BooleanImmediate))
+ return false;
+ BooleanImmediate other = (BooleanImmediate) obj;
+ if (value != other.value)
+ return false;
+ return true;
+ }
+
+
+}
--- /dev/null
+package net.mograsim.machine.mi.parameters;
+
+import java.math.BigInteger;
+
+import net.mograsim.logic.core.types.BitVector;
+
+public final class IntegerImmediate implements MicroInstructionParameter
+{
+ private BitVector value;
+
+ public IntegerImmediate(BigInteger value, int bits)
+ {
+ this.value = BitVector.from(value, bits);
+ }
+
+ public IntegerImmediate(BitVector value)
+ {
+ this.value = value;
+ }
+
+ @Override
+ public BitVector getValue()
+ {
+ return value;
+ }
+
+ @Override
+ public ParameterType getType()
+ {
+ return ParameterType.INTEGER_IMMEDIATE;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((value == null) ? 0 : value.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof IntegerImmediate))
+ return false;
+ IntegerImmediate other = (IntegerImmediate) obj;
+ if (value == null)
+ {
+ if (other.value != null)
+ return false;
+ } else if (!value.equals(other.value))
+ return false;
+ return true;
+ }
+}
--- /dev/null
+package net.mograsim.machine.mi.parameters;
+
+import net.mograsim.logic.core.types.BitVector;
+
+public interface MicroInstructionParameter
+{
+ public BitVector getValue();
+
+ public ParameterType getType();
+
+ public static enum ParameterType
+ {
+ INTEGER_IMMEDIATE, BOOLEAN_IMMEDIATE, MNEMONIC
+ }
+}
--- /dev/null
+package net.mograsim.machine.mi.parameters;
+
+import net.mograsim.logic.core.types.BitVector;
+
+public final class Mnemonic implements MicroInstructionParameter
+{
+ 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;
+ }
+
+ @Override
+ public BitVector getValue()
+ {
+ return vector;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((text == null) ? 0 : text.hashCode());
+ result = prime * result + ((vector == null) ? 0 : vector.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof Mnemonic))
+ return false;
+ Mnemonic other = (Mnemonic) obj;
+ if (text == null)
+ {
+ if (other.text != null)
+ return false;
+ } else if (!text.equals(other.text))
+ return false;
+ if (vector == null)
+ {
+ if (other.vector != null)
+ return false;
+ } else if (!vector.equals(other.vector))
+ return false;
+ return true;
+ }
+
+ @Override
+ public ParameterType getType()
+ {
+ return ParameterType.MNEMONIC;
+ }
+}
--- /dev/null
+package net.mograsim.machine.mi.parameters;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import net.mograsim.machine.mi.parameters.MicroInstructionParameter.ParameterType;
+
+public class MnemonicFamily implements ParameterClassification
+{
+ 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].getValue().width();
+ for(int i = 1; i < values.length; i++)
+ if(values[i].getValue().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;
+ }
+
+ @Override
+ public boolean conforms(MicroInstructionParameter param)
+ {
+ return param instanceof Mnemonic ? contains((Mnemonic) param) : false;
+ }
+
+ @Override
+ public ParameterType getExpectedType()
+ {
+ return ParameterType.MNEMONIC;
+ }
+}
--- /dev/null
+package net.mograsim.machine.mi.parameters;
+
+import net.mograsim.machine.mi.parameters.MicroInstructionParameter.ParameterType;
+
+public interface ParameterClassification
+{
+ /**
+ * 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);
+
+ /**
+ * @return The type of the parameters in this classification.
+ */
+ public ParameterType getExpectedType();
+}
--- /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;
+ }
+}
+++ /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;
- }
-}