Merge branch 'development' of
authorFabian Stemmler <stemmler@in.tum.de>
Tue, 27 Aug 2019 13:55:03 +0000 (15:55 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Tue, 27 Aug 2019 14:03:43 +0000 (16:03 +0200)
https://gitlab.lrz.de/lrr-tum/students/eragp-misim-2019.git into
development

Conflicts:
net.mograsim.machine/src/net/mograsim/machine/mi/parameters/MnemonicFamily.java

net.mograsim.machine/src/net/mograsim/machine/MainMemory.java
net.mograsim.machine/src/net/mograsim/machine/Memory.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/MicroInstructionDefinition.java
net.mograsim.machine/src/net/mograsim/machine/MicroprogramMemory.java
net.mograsim.machine/src/net/mograsim/machine/mi/parameters/BooleanClassification.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/mi/parameters/IntegerClassification.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/mi/parameters/Mnemonic.java
net.mograsim.machine/src/net/mograsim/machine/mi/parameters/MnemonicFamily.java
net.mograsim.machine/src/net/mograsim/machine/mi/parameters/ParameterClassification.java
net.mograsim.machine/src/net/mograsim/machine/mi/parameters/SimpleTypeClassification.java [deleted file]

index e38d325..dcd3ee2 100644 (file)
@@ -4,11 +4,13 @@ import java.math.BigInteger;
 
 import net.mograsim.logic.core.types.BitVector;
 
-public interface MainMemory {
+public interface MainMemory extends Memory<BitVector> {
        
-       public BitVector getCell(long address);
-       public void setCell(long address, BitVector word);
        public BigInteger getCellAsBigInteger(long address);
        public void setCellAsBigInteger(long address, BigInteger word);
        public MainMemoryDefinition getDefinition();
+       public default long size()
+       {
+               return getDefinition().size();
+       }
 }
diff --git a/net.mograsim.machine/src/net/mograsim/machine/Memory.java b/net.mograsim.machine/src/net/mograsim/machine/Memory.java
new file mode 100644 (file)
index 0000000..8297ebb
--- /dev/null
@@ -0,0 +1,20 @@
+package net.mograsim.machine;
+
+public interface Memory<T>
+{
+       /**
+        * @param address The address of the desired data. Must be non-negative
+        * @return The data at the requested address
+        * 
+        * @throws IndexOutOfBoundsException
+        */
+       public T getCell(long address);
+       
+       /**
+        * Sets the data at the supplied address
+        * @throws IndexOutOfBoundsException
+        */
+       public void setCell(long address, T data);
+       
+       public long size();
+}
index 33a970c..63134a0 100644 (file)
@@ -13,6 +13,9 @@ public interface MicroInstructionDefinition
        /**
         * @return The amount of {@link MicroInstructionParameter}s in a {@link MicroInstruction} that follows this definition.
         */
-       public int size();
+       public default int size()
+       {
+               return getParameterClassifications().length;
+       }
        
 }
index 29bfcb9..333f8a6 100644 (file)
@@ -1,21 +1,5 @@
 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);
+public interface MicroprogramMemory extends Memory<MicroInstruction>
+{
 }
diff --git a/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/BooleanClassification.java b/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/BooleanClassification.java
new file mode 100644 (file)
index 0000000..abe552f
--- /dev/null
@@ -0,0 +1,18 @@
+package net.mograsim.machine.mi.parameters;
+
+import net.mograsim.machine.mi.parameters.MicroInstructionParameter.ParameterType;
+
+public class BooleanClassification implements ParameterClassification
+{
+       @Override
+       public ParameterType getExpectedType()
+       {
+               return ParameterType.BOOLEAN_IMMEDIATE;
+       }
+
+       @Override
+       public int getExpectedBits()
+       {
+               return 1;
+       }
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/IntegerClassification.java b/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/IntegerClassification.java
new file mode 100644 (file)
index 0000000..d5ba964
--- /dev/null
@@ -0,0 +1,25 @@
+package net.mograsim.machine.mi.parameters;
+
+import net.mograsim.machine.mi.parameters.MicroInstructionParameter.ParameterType;
+
+public class IntegerClassification implements ParameterClassification
+{
+       private final int bits;
+       
+       public IntegerClassification(int bits)
+       {
+               this.bits = bits;
+       }
+
+       @Override
+       public ParameterType getExpectedType()
+       {
+               return ParameterType.INTEGER_IMMEDIATE;
+       }
+
+       @Override
+       public int getExpectedBits()
+       {
+               return bits;
+       }
+}
index feeb88e..cca106e 100644 (file)
@@ -65,4 +65,10 @@ public final class Mnemonic implements MicroInstructionParameter
        {
                return ParameterType.MNEMONIC;
        }
+       
+       @Override
+       public String toString()
+       {
+               return text;
+       }
 }
index 3724a42..3deccb0 100644 (file)
@@ -10,21 +10,23 @@ public class MnemonicFamily implements ParameterClassification
 {
        private final Mnemonic[] values;
        private final Map<String, Mnemonic> byText;
-       private final int vectorLenght;
+       private final int vectorLength;
        
        public MnemonicFamily(Mnemonic... values)
        {
                this.values = values;
                if(values.length == 0)
-                       vectorLenght = 0;
+                       vectorLength = 0;
                else
                {
-                       vectorLenght = values[0].getValue().length();
+                       vectorLength = values[0].getValue().length();
                        for(int i = 1; i < values.length; i++)
-                               if(values[i].getValue().length() != vectorLenght)
+                               if(values[i].getValue().length() != vectorLength)
                                        throw new IllegalArgumentException("MnemonicFamily is not of uniform vector length!");
                }
                byText = Arrays.stream(values).collect(Collectors.toMap(m -> m.getText(), m -> m));
+               if(values.length != byText.keySet().size())
+                       throw new IllegalArgumentException("MnemonicFamily contains multiple Mnemonics with the same name!");
        }
        
        public Mnemonic[] getValues()
@@ -45,6 +47,11 @@ public class MnemonicFamily implements ParameterClassification
                        return false;
        }
        
+       public boolean contains(String value)
+       {
+               return byText.keySet().contains(value);
+       }
+       
        public int size()
        {
                return values.length;
@@ -52,13 +59,13 @@ public class MnemonicFamily implements ParameterClassification
        
        public int getVectorLength()
        {
-               return vectorLenght;
+               return vectorLength;
        }
 
        @Override
        public boolean conforms(MicroInstructionParameter param)
        {
-               return param instanceof Mnemonic ? contains((Mnemonic) param) : false;
+               return ParameterClassification.super.conforms(param) && (param instanceof Mnemonic ? contains((Mnemonic) param) : false);
        }
 
        @Override
@@ -66,4 +73,15 @@ public class MnemonicFamily implements ParameterClassification
        {
                return ParameterType.MNEMONIC;
        }
+
+       @Override
+       public int getExpectedBits()
+       {
+               return vectorLength;
+       }
+
+       public String[] getStringValues()
+       {
+               return byText.keySet().toArray(new String[values.length]);
+       }
 }
index b9362a0..3b3f1a2 100644 (file)
@@ -8,10 +8,18 @@ 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);
+       public default boolean conforms(MicroInstructionParameter param)
+       {
+               return param.getType().equals(getExpectedType()) && param.getValue().length() == getExpectedBits();
+       }
        
        /**
         * @return The type of the parameters in this classification.
         */
        public ParameterType getExpectedType();
+       
+       /**
+        * @return The number of bits of the parameters in this classification.
+        */
+       public int getExpectedBits();
 }
diff --git a/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/SimpleTypeClassification.java b/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/SimpleTypeClassification.java
deleted file mode 100644 (file)
index c6687ae..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-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;
-       }
-}