From addfe2790a05cc7a6106ef66acd1d7e7d8845e4c Mon Sep 17 00:00:00 2001 From: Fabian Stemmler Date: Tue, 27 Aug 2019 15:47:32 +0200 Subject: [PATCH] Generalized common functionality of different Memories to new interface --- .../src/net/mograsim/machine/MainMemory.java | 8 +++++--- .../src/net/mograsim/machine/Memory.java | 20 +++++++++++++++++++ .../mograsim/machine/MicroprogramMemory.java | 20 ++----------------- 3 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 net.mograsim.machine/src/net/mograsim/machine/Memory.java diff --git a/net.mograsim.machine/src/net/mograsim/machine/MainMemory.java b/net.mograsim.machine/src/net/mograsim/machine/MainMemory.java index e38d3259..dcd3ee21 100644 --- a/net.mograsim.machine/src/net/mograsim/machine/MainMemory.java +++ b/net.mograsim.machine/src/net/mograsim/machine/MainMemory.java @@ -4,11 +4,13 @@ import java.math.BigInteger; import net.mograsim.logic.core.types.BitVector; -public interface MainMemory { +public interface MainMemory extends Memory { - 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 index 00000000..8297ebb9 --- /dev/null +++ b/net.mograsim.machine/src/net/mograsim/machine/Memory.java @@ -0,0 +1,20 @@ +package net.mograsim.machine; + +public interface Memory +{ + /** + * @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(); +} diff --git a/net.mograsim.machine/src/net/mograsim/machine/MicroprogramMemory.java b/net.mograsim.machine/src/net/mograsim/machine/MicroprogramMemory.java index 29bfcb9e..333f8a64 100644 --- a/net.mograsim.machine/src/net/mograsim/machine/MicroprogramMemory.java +++ b/net.mograsim.machine/src/net/mograsim/machine/MicroprogramMemory.java @@ -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 +{ } -- 2.17.1