MicroInstructions can now be converted to bits
authorFabian Stemmler <stemmler@in.tum.de>
Sat, 14 Sep 2019 23:59:01 +0000 (01:59 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Sat, 14 Sep 2019 23:59:01 +0000 (01:59 +0200)
net.mograsim.machine/src/net/mograsim/machine/mi/MicroInstruction.java
net.mograsim.machine/src/net/mograsim/machine/mi/MicroInstructionDefinition.java

index 07a15d2..d88a8ef 100644 (file)
@@ -1,5 +1,6 @@
 package net.mograsim.machine.mi;
 
+import net.mograsim.logic.core.types.BitVector;
 import net.mograsim.machine.mi.parameters.MicroInstructionParameter;
 import net.mograsim.machine.mi.parameters.Mnemonic;
 
@@ -17,4 +18,13 @@ public interface MicroInstruction {
        {
                return new StandardMicroInstruction(parameters);
        }
+       
+       default BitVector toBitVector()
+       {
+               BitVector vector = BitVector.of();
+               int size = getSize();
+               for(int i = 0; i < size; i++)
+                       vector.concat(getParameter(i).getValue());
+               return vector;
+       }
 }
index 0ba3b41..b9cd2ef 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;
@@ -31,6 +33,14 @@ 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();