Defined Interfaces regarding MicroInstructions
authorFabian Stemmler <stemmler@in.tum.de>
Mon, 26 Aug 2019 14:04:20 +0000 (16:04 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Mon, 26 Aug 2019 14:04:20 +0000 (16:04 +0200)
Added Mnemonic and MnemonicFamily;
MicroInstructionDefinition now defines structure of MicroInstructions;
Defined MicroInstruction and MicroprogramMemory;

net.mograsim.machine/src/net/mograsim/machine/MicroInstruction.java
net.mograsim.machine/src/net/mograsim/machine/MicroInstructionDefinition.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/MicroprogramMemory.java
net.mograsim.machine/src/net/mograsim/machine/mnemonics/Mnemonic.java [new file with mode: 0644]
net.mograsim.machine/src/net/mograsim/machine/mnemonics/MnemonicFamily.java [new file with mode: 0644]

index 0846cd5..b054c66 100644 (file)
@@ -1,5 +1,13 @@
 package net.mograsim.machine;
 
-public interface MicroInstruction {
+import net.mograsim.machine.mnemonics.Mnemonic;
 
+public interface MicroInstruction {
+       
+       public Mnemonic getValue(int index);
+       
+       /**
+        * @return The amount of {@link Mnemonic}s, the instruction is composed of
+        */
+       public int getSize();
 }
diff --git a/net.mograsim.machine/src/net/mograsim/machine/MicroInstructionDefinition.java b/net.mograsim.machine/src/net/mograsim/machine/MicroInstructionDefinition.java
new file mode 100644 (file)
index 0000000..3676b2b
--- /dev/null
@@ -0,0 +1,18 @@
+package net.mograsim.machine;
+
+import net.mograsim.machine.mnemonics.Mnemonic;
+import net.mograsim.machine.mnemonics.MnemonicFamily;
+
+public interface MicroInstructionDefinition
+{
+       /**
+        * @return The {@link MnemonicFamily}s of which a MicroInstruction is composed.
+        */
+       public MnemonicFamily[] getMnemonicFamilies();
+       
+       /**
+        * @return The amount of {@link Mnemonic}s a {@link MicroInstruction} that follows this definition consists of.
+        */
+       public int size();
+       
+}
index c12d676..29bfcb9 100644 (file)
@@ -1,5 +1,21 @@
 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);
 }
diff --git a/net.mograsim.machine/src/net/mograsim/machine/mnemonics/Mnemonic.java b/net.mograsim.machine/src/net/mograsim/machine/mnemonics/Mnemonic.java
new file mode 100644 (file)
index 0000000..822d7ed
--- /dev/null
@@ -0,0 +1,26 @@
+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;
+       }
+}
diff --git a/net.mograsim.machine/src/net/mograsim/machine/mnemonics/MnemonicFamily.java b/net.mograsim.machine/src/net/mograsim/machine/mnemonics/MnemonicFamily.java
new file mode 100644 (file)
index 0000000..a55175f
--- /dev/null
@@ -0,0 +1,55 @@
+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;
+       }
+}