Apply formatter, optional problems, save actions to machine project
[Mograsim.git] / net.mograsim.machine / src / net / mograsim / machine / mi / MicroInstructionDefinition.java
index 0ba3b41..fcdbdc4 100644 (file)
@@ -1,8 +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;
@@ -16,13 +18,12 @@ public interface MicroInstructionDefinition
         * @return The {@link ParameterClassification}s of which a MicroInstruction is composed.
         */
        public ParameterClassification[] getParameterClassifications();
-       
+
        /**
         * @throws IndexOutOfBoundsException
         */
        public ParameterClassification getParameterClassification(int index);
-       
-       
+
        /**
         * @return The amount of {@link MicroInstructionParameter}s in a {@link MicroInstruction} that follows this definition.
         */
@@ -30,18 +31,26 @@ public interface MicroInstructionDefinition
        {
                return getParameterClassifications().length;
        }
-       
+
+       /**
+        * @return The amount of {@link Bit}s in a {@link MicroInstruction} that follows this definition.
+        */
+       public default int sizeInBits()
+       {
+               return Arrays.stream(getParameterClassifications()).mapToInt(e -> e.getExpectedBits()).reduce(0, (a, b) -> a + b);
+       }
+
        public default MicroInstruction createDefaultInstruction()
        {
                int size = size();
                MicroInstructionParameter[] params = new MicroInstructionParameter[size];
                ParameterClassification[] classes = getParameterClassifications();
-               for(int i = 0; i < size; i++)
+               for (int i = 0; i < size; i++)
                {
                        MicroInstructionParameter newParam;
                        ParameterClassification classification = classes[i];
                        ParameterType type = classification.getExpectedType();
-                       switch(type)
+                       switch (type)
                        {
                        case BOOLEAN_IMMEDIATE:
                        case MNEMONIC: