Generalized common functionality of different Memories to new interface
authorFabian Stemmler <stemmler@in.tum.de>
Tue, 27 Aug 2019 13:47:32 +0000 (15:47 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Tue, 27 Aug 2019 13:47:32 +0000 (15:47 +0200)
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/MicroprogramMemory.java

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 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>
+{
 }