A MicroInstructionDefinition now has a default
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Sun, 15 Sep 2019 16:16:45 +0000 (18:16 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Sun, 15 Sep 2019 16:19:14 +0000 (18:19 +0200)
net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MicroInstructionDefinition.java
net.mograsim.machine/src/net/mograsim/machine/mi/MicroInstructionDefinition.java
net.mograsim.machine/src/net/mograsim/machine/mi/parameters/BooleanClassification.java
net.mograsim.machine/src/net/mograsim/machine/mi/parameters/IntegerClassification.java
net.mograsim.machine/src/net/mograsim/machine/mi/parameters/MnemonicFamily.java
net.mograsim.machine/src/net/mograsim/machine/mi/parameters/ParameterClassification.java

index 12cbd37..5916af8 100644 (file)
@@ -14,35 +14,38 @@ import net.mograsim.machine.mi.parameters.ParameterClassification;
 
 public class Am2900MicroInstructionDefinition implements MicroInstructionDefinition
 {
-       private final static MnemonicFamily am2910Instructions = new MnemonicFamily(true, "JZ", "CJS", "JMAP", "PUSH", "JSRP", "CJV", "JRP",
-                       "RFCT", "RPCT", "CRTN", "CJPP", "LDCT", "LOOP", "CONT", "TWB");
-       private final static MnemonicFamily am2904StatusInstructions = new MnemonicFamily(true,
+       private final static MnemonicFamily am2910Instructions = new MnemonicFamily(true, "JZ", "JZ", "CJS", "JMAP", "PUSH", "JSRP", "CJV",
+                       "JRP", "RFCT", "RPCT", "CRTN", "CJPP", "LDCT", "LOOP", "CONT", "TWB");
+       private final static MnemonicFamily am2904StatusInstructions = new MnemonicFamily(true, "MI_Zero",
                        new String[] { "MI_Zero", "MI_NotZero", "MI_UGTEQ", "MI_ULT", "MI_UGT", "MI_ULTEQ", "MI_SGTEQ", "MI_SLT", "MI_SGT", "MI_SLTEQ",
                                        "MA_Zero", "MA_NotZero", "MA_UGTEQ", "MA_ULT", "MA_UGT", "MA_ULTEQ", "MA_SGTEQ", "MA_SLT", "MA_SGT", "MA_SLTEQ" },
                        new long[] { 0b01_0101, 0b01_0100, 0b01_1101, 0b01_1100, 0b01_1110, 0b01_1111, 0b01_0010, 0b01_0011, 0b01_0000, 0b01_0001,
                                        0b10_0101, 0b10_0100, 0b10_1101, 0b10_1100, 0b10_1110, 0b10_1111, 0b10_0010, 0b10_0011, 0b10_0000, 0b10_0001 },
                        6);
-       private final static MnemonicFamily am2904ShiftInstructions = new MnemonicFamily(true, "SL", "SH", "SCONI", "SDH", "SDC", "SDN", "SDL",
-                       "SDCO", "SRCO", "SRCIO", "SR", "SDIC", "SDRCI", "SDRCO", "SDXOR", "SDR");
-       private final static MnemonicFamily am2904CarryInstructions = new MnemonicFamily(true, new String[] { "CI0", "CI1", "CIX", "CIC" },
-                       new long[] { 0b00, 0b01, 0b10, 0b11 }, 2);
-       private final static MnemonicFamily am2901DestInstructions = new MnemonicFamily(true, "QREG", "NOP", "RAMA", "RAMF", "RAMQD", "RAMD",
-                       "RAMQU", "RAMU");
-       private final static MnemonicFamily am2901FuncInstructions = new MnemonicFamily(true, "ADD", "SUBR", "SUBS", "OR", "AND", "NOTRS",
-                       "EXOR", "EXNOR");
-       private final static MnemonicFamily am2901SrcInstructions = new MnemonicFamily(true, "AQ", "AB", "ZQ", "ZB", "ZA", "DA", "DQ", "DZ");
-       private final static MnemonicFamily interruptInstructions = new MnemonicFamily(
+       private final static MnemonicFamily am2904ShiftInstructions = new MnemonicFamily(true, "SL", "SL", "SH", "SCONI", "SDH", "SDC", "SDN",
+                       "SDL", "SDCO", "SRCO", "SRCIO", "SR", "SDIC", "SDRCI", "SDRCO", "SDXOR", "SDR");
+       private final static MnemonicFamily am2904CarryInstructions = new MnemonicFamily(true, "CI0",
+                       new String[] { "CI0", "CI1", "CIX", "CIC" }, new long[] { 0b00, 0b01, 0b10, 0b11 }, 2);
+       private final static MnemonicFamily am2901DestInstructions = new MnemonicFamily(true, "NOP", "QREG", "NOP", "RAMA", "RAMF", "RAMQD",
+                       "RAMD", "RAMQU", "RAMU");
+       private final static MnemonicFamily am2901FuncInstructions = new MnemonicFamily(true, "ADD", "ADD", "SUBR", "SUBS", "OR", "AND",
+                       "NOTRS", "EXOR", "EXNOR");
+       private final static MnemonicFamily am2901SrcInstructions = new MnemonicFamily(true, "AB", "AQ", "AB", "ZQ", "ZB", "ZA", "DA", "DQ",
+                       "DZ");
+       private final static MnemonicFamily interruptInstructions = new MnemonicFamily("X",
                        new MnemonicPair("X", BitVector.of(Bit.ZERO, 4))/* TODO */);
-       private final static BooleanClassification hL = new BooleanClassification("H", "L");
-       private final static BooleanClassification registerSelect = new BooleanClassification("MR", "IR");
-       private final static IntegerClassification register = new IntegerClassification(4);
+       private final static BooleanClassification hL = new BooleanClassification(true, "H", "L");
+       private final static BooleanClassification registerSelect = new BooleanClassification(false, "MR", "IR");
+       private final static IntegerClassification register = new IntegerClassification(0, 4);
 
-       private final static ParameterClassification[] classes = { new BooleanClassification("Dis", "IE"), new IntegerClassification(16),
-                       new BooleanClassification("D", "K"), interruptInstructions, new BooleanClassification("H", "AB"), registerSelect, register,
-                       registerSelect, register, am2901DestInstructions, am2901FuncInstructions, am2901SrcInstructions, new IntegerClassification(12),
-                       am2910Instructions, new BooleanClassification("PS", "C"), am2904StatusInstructions, hL, hL, am2904ShiftInstructions,
-                       am2904CarryInstructions, new BooleanClassification("H", "DB"), new BooleanClassification("H", "E"), hL,
-                       new BooleanClassification("H", "E"), new BooleanClassification("H", "I"), new BooleanClassification("R", "W"), hL };
+       private final static ParameterClassification[] classes = { new BooleanClassification(true, "Dis", "IE"),
+                       new IntegerClassification(0, 16), new BooleanClassification(false, "D", "K"), interruptInstructions,
+                       new BooleanClassification(true, "H", "AB"), registerSelect, register, registerSelect, register, am2901DestInstructions,
+                       am2901FuncInstructions, am2901SrcInstructions, new IntegerClassification(0, 12), am2910Instructions,
+                       new BooleanClassification(true, "PS", "C"), am2904StatusInstructions, hL, hL, am2904ShiftInstructions, am2904CarryInstructions,
+                       new BooleanClassification(true, "H", "DB"), new BooleanClassification(true, "H", "E"), hL,
+                       new BooleanClassification(true, "H", "E"), new BooleanClassification(true, "H", "I"), new BooleanClassification(true, "R", "W"),
+                       hL };
 
        private final static String[] paramDesc = { "Allow interrupts?", "Interrupt instructions; omitted for simplicity",
                        "Get D-input from data bus/constant value", "Constant value", "Operand sources for ALU operation", "ALU operation",
index 5221e3e..6625fa6 100644 (file)
@@ -1,15 +1,10 @@
 package net.mograsim.machine.mi;
 
-import java.math.BigInteger;
 import java.util.Arrays;
 import java.util.Optional;
 
 import net.mograsim.logic.core.types.Bit;
-import net.mograsim.machine.mi.parameters.IntegerClassification;
-import net.mograsim.machine.mi.parameters.IntegerImmediate;
 import net.mograsim.machine.mi.parameters.MicroInstructionParameter;
-import net.mograsim.machine.mi.parameters.MicroInstructionParameter.ParameterType;
-import net.mograsim.machine.mi.parameters.MnemonicFamily;
 import net.mograsim.machine.mi.parameters.ParameterClassification;
 
 public interface MicroInstructionDefinition
@@ -47,22 +42,8 @@ public interface MicroInstructionDefinition
                ParameterClassification[] classes = getParameterClassifications();
                for (int i = 0; i < size; i++)
                {
-                       MicroInstructionParameter newParam;
                        ParameterClassification classification = classes[i];
-                       ParameterType type = classification.getExpectedType();
-                       switch (type)
-                       {
-                       case BOOLEAN_IMMEDIATE:
-                       case MNEMONIC:
-                               newParam = ((MnemonicFamily) classification).get(0);
-                               break;
-                       case INTEGER_IMMEDIATE:
-                               newParam = new IntegerImmediate(BigInteger.valueOf(0), ((IntegerClassification) classification).getExpectedBits());
-                               break;
-                       default:
-                               throw new IllegalStateException("Unknown ParameterType " + type);
-                       }
-                       params[i] = newParam;
+                       params[i] = classification.getDefault();
                }
                return new StandardMicroInstruction(updateCallback, params);
        }
index 28bf971..73acc66 100644 (file)
@@ -7,9 +7,10 @@ public class BooleanClassification extends MnemonicFamily
 {
        String trueName, falseName;
 
-       public BooleanClassification(String trueName, String falseName)
+       public BooleanClassification(boolean defaultValue, String trueName, String falseName)
        {
-               super(new MnemonicPair(trueName, BitVector.SINGLE_1), new MnemonicPair(falseName, BitVector.SINGLE_0));
+               super(defaultValue ? trueName : falseName, new MnemonicPair(trueName, BitVector.SINGLE_1),
+                               new MnemonicPair(falseName, BitVector.SINGLE_0));
                this.trueName = trueName;
                this.falseName = falseName;
        }
index 1a5003f..c24cabe 100644 (file)
@@ -2,15 +2,18 @@ package net.mograsim.machine.mi.parameters;
 
 import java.math.BigInteger;
 
+import net.mograsim.logic.core.types.BitVector;
 import net.mograsim.machine.mi.parameters.MicroInstructionParameter.ParameterType;
 
 public class IntegerClassification implements ParameterClassification
 {
        private final int bits;
+       private final IntegerImmediate defaultValue;
 
-       public IntegerClassification(int bits)
+       public IntegerClassification(int defaultValue, int bits)
        {
                this.bits = bits;
+               this.defaultValue = new IntegerImmediate(BitVector.from(defaultValue, bits));
        }
 
        @Override
@@ -30,4 +33,10 @@ public class IntegerClassification implements ParameterClassification
        {
                return new IntegerImmediate(new BigInteger(toParse), bits);
        }
+
+       @Override
+       public MicroInstructionParameter getDefault()
+       {
+               return defaultValue;
+       }
 }
index 7ed69f9..d6906fb 100644 (file)
@@ -10,26 +10,27 @@ import net.mograsim.machine.mi.parameters.MicroInstructionParameter.ParameterTyp
 public class MnemonicFamily implements ParameterClassification
 {
        private final Mnemonic[] values;
+       private final Mnemonic defaultValue;
        private final String[] stringValues;
        private Map<String, Mnemonic> byText;
        private int vectorLength;
 
-       public MnemonicFamily(String... names)
+       public MnemonicFamily(String defaultValueName, String... names)
        {
-               this(false, (int) Math.round(Math.ceil(Math.log(names.length) / Math.log(2))), names);
+               this(false, defaultValueName, (int) Math.round(Math.ceil(Math.log(names.length) / Math.log(2))), names);
        }
 
-       public MnemonicFamily(boolean reverse, String... names)
+       public MnemonicFamily(boolean reverse, String defaultValueName, String... names)
        {
-               this(reverse, (int) Math.round(Math.ceil(Math.log(names.length) / Math.log(2))), names);
+               this(reverse, defaultValueName, (int) Math.round(Math.ceil(Math.log(names.length) / Math.log(2))), names);
        }
 
-       public MnemonicFamily(int bits, String... names)
+       public MnemonicFamily(String defaultValueName, int bits, String... names)
        {
-               this(false, bits, names);
+               this(false, defaultValueName, bits, names);
        }
 
-       public MnemonicFamily(boolean reverse, int bits, String... names)
+       public MnemonicFamily(boolean reverse, String defaultValueName, int bits, String... names)
        {
                this.values = new Mnemonic[names.length];
                this.stringValues = new String[names.length];
@@ -40,14 +41,23 @@ public class MnemonicFamily implements ParameterClassification
                }
 
                setup(names, values, reverse);
+
+               int defaultValueIndex = -1;
+               for (int i = 0; i < names.length; i++)
+                       if (names[i].equals(defaultValueName))
+                       {
+                               defaultValueIndex = i;
+                               break;
+                       }
+               this.defaultValue = this.values[defaultValueIndex];
        }
 
-       public MnemonicFamily(String[] names, long[] values, int bits)
+       public MnemonicFamily(String defaultValueName, String[] names, long[] values, int bits)
        {
-               this(false, names, values, bits);
+               this(false, defaultValueName, names, values, bits);
        }
 
-       public MnemonicFamily(boolean reverse, String[] names, long[] values, int bits)
+       public MnemonicFamily(boolean reverse, String defaultValueName, String[] names, long[] values, int bits)
        {
                if (names.length != values.length)
                        throw new IllegalArgumentException();
@@ -61,14 +71,23 @@ public class MnemonicFamily implements ParameterClassification
                }
 
                setup(names, vectors, reverse);
+
+               int defaultValueIndex = -1;
+               for (int i = 0; i < names.length; i++)
+                       if (names[i].equals(defaultValueName))
+                       {
+                               defaultValueIndex = i;
+                               break;
+                       }
+               this.defaultValue = this.values[defaultValueIndex];
        }
 
-       public MnemonicFamily(String[] names, BitVector[] values)
+       public MnemonicFamily(String defaultValueName, String[] names, BitVector[] values)
        {
-               this(false, names, values);
+               this(false, defaultValueName, names, values);
        }
 
-       public MnemonicFamily(boolean reverse, String[] names, BitVector[] values)
+       public MnemonicFamily(boolean reverse, String defaultValueName, String[] names, BitVector[] values)
        {
                if (names.length != values.length)
                        throw new IllegalArgumentException();
@@ -76,19 +95,32 @@ public class MnemonicFamily implements ParameterClassification
                this.stringValues = new String[values.length];
 
                setup(names, values, reverse);
-       }
 
-       public MnemonicFamily(MnemonicPair... values)
-       {
-               this(false, values);
+               int defaultValueIndex = -1;
+               for (int i = 0; i < names.length; i++)
+                       if (names[i].equals(defaultValueName))
+                       {
+                               defaultValueIndex = i;
+                               break;
+                       }
+               this.defaultValue = this.values[defaultValueIndex];
        }
 
-       public MnemonicFamily(boolean reverse, MnemonicPair... values)
+       public MnemonicFamily(String defaultValueName, MnemonicPair... values)
        {
                this.values = new Mnemonic[values.length];
                this.stringValues = new String[values.length];
 
                setup(values);
+
+               int defaultValueIndex = -1;
+               for (int i = 0; i < values.length; i++)
+                       if (stringValues[i].equals(defaultValueName))
+                       {
+                               defaultValueIndex = i;
+                               break;
+                       }
+               this.defaultValue = this.values[defaultValueIndex];
        }
 
        private void setup(String[] names, BitVector[] values, boolean reverse)
@@ -140,6 +172,12 @@ public class MnemonicFamily implements ParameterClassification
                return byText.get(text);
        }
 
+       @Override
+       public MicroInstructionParameter getDefault()
+       {
+               return defaultValue;
+       }
+
        public boolean contains(Mnemonic m)
        {
                if (m != null)
index 223ff42..c81f6e5 100644 (file)
@@ -25,4 +25,6 @@ public interface ParameterClassification
        public int getExpectedBits();
 
        public MicroInstructionParameter parse(String toParse);
+
+       public MicroInstructionParameter getDefault();
 }