From 2968b327788769a1248f6e7c14d1c7ba86457ff2 Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Mon, 7 Oct 2019 01:28:44 +0200 Subject: [PATCH] Re-added Am2901 registers --- .../META-INF/MANIFEST.MF | 1 + .../AbstractAm2900MachineDefinition.java | 4 ++- .../am2900/machine/registers/QRegister.java | 17 ---------- .../registers/am2901/Am2901Register.java | 21 ++++++++++++ .../registers/am2901/Am2901RegisterGroup.java | 25 ++++++++++++++ .../{ => am2901}/NumberedRegister.java | 33 +++++-------------- .../machine/registers/am2901/QRegister.java | 11 +++++++ 7 files changed, 70 insertions(+), 42 deletions(-) delete mode 100644 plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/QRegister.java create mode 100644 plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/Am2901Register.java create mode 100644 plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/Am2901RegisterGroup.java rename plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/{ => am2901}/NumberedRegister.java (51%) create mode 100644 plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/QRegister.java diff --git a/plugins/net.mograsim.logic.model.am2900/META-INF/MANIFEST.MF b/plugins/net.mograsim.logic.model.am2900/META-INF/MANIFEST.MF index 82e0a34d..302a687f 100644 --- a/plugins/net.mograsim.logic.model.am2900/META-INF/MANIFEST.MF +++ b/plugins/net.mograsim.logic.model.am2900/META-INF/MANIFEST.MF @@ -10,6 +10,7 @@ Export-Package: net.mograsim.logic.model.am2900, net.mograsim.logic.model.am2900.components.am2910, net.mograsim.logic.model.am2900.machine, net.mograsim.logic.model.am2900.machine.registers, + net.mograsim.logic.model.am2900.machine.registers.am2901, net.mograsim.logic.model.examples Bundle-RequiredExecutionEnvironment: JavaSE-11 Require-Bundle: org.eclipse.osgi, diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/AbstractAm2900MachineDefinition.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/AbstractAm2900MachineDefinition.java index aed53563..3469b2db 100644 --- a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/AbstractAm2900MachineDefinition.java +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/AbstractAm2900MachineDefinition.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import net.mograsim.logic.model.am2900.machine.registers.am2901.Am2901RegisterGroup; import net.mograsim.logic.model.model.LogicModelModifiable; import net.mograsim.machine.ISASchema; import net.mograsim.machine.MachineDefinition; @@ -26,7 +27,8 @@ public class AbstractAm2900MachineDefinition implements MachineDefinition // TODO MIR, IR, PC/BZ... unsortedRegisters = Collections.unmodifiableList(unsortedRegistersModifiable); List registerGroupsModifiable = new ArrayList<>(); - // TODO Am2901, Am2904, Am2910 + registerGroupsModifiable.add(Am2901RegisterGroup.instance); + // TODO Am2904, Am2910 registerGroups = Collections.unmodifiableList(registerGroupsModifiable); } diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/QRegister.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/QRegister.java deleted file mode 100644 index b5d35407..00000000 --- a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/QRegister.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.mograsim.logic.model.am2900.machine.registers; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; - -import net.mograsim.machine.StandardRegister; - -public class QRegister extends StandardRegister -{ - public static final QRegister instance = new QRegister(); - - private QRegister() - { - super("qreg", new HashSet<>(Arrays.asList(new String[] { "qreg", "Q register" })), 16, new HashMap<>()); - } -} \ No newline at end of file diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/Am2901Register.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/Am2901Register.java new file mode 100644 index 00000000..c16a4d2c --- /dev/null +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/Am2901Register.java @@ -0,0 +1,21 @@ +package net.mograsim.logic.model.am2900.machine.registers.am2901; + +import net.mograsim.logic.model.am2900.machine.registers.Am2900Register; +import net.mograsim.machine.registers.HighLevelStateBasedRegister; + +public class Am2901Register extends HighLevelStateBasedRegister implements Am2900Register +{ + public Am2901Register(String id, String cellSuffix, int logicWidthPerAm2901) + { + super(id, new int[] { logicWidthPerAm2901, logicWidthPerAm2901, logicWidthPerAm2901, logicWidthPerAm2901 }, + prefixWithAm2901s(cellSuffix)); + } + + private static String[] prefixWithAm2901s(String suffix) + { + String[] prefixed = new String[4]; + for (int i = 0, b = 0; i < 4; i++, b += 4) + prefixed[i] = String.format("am2901_%d-%d.%s", (b + 3), b, suffix); + return prefixed; + } +} \ No newline at end of file diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/Am2901RegisterGroup.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/Am2901RegisterGroup.java new file mode 100644 index 00000000..88766b1d --- /dev/null +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/Am2901RegisterGroup.java @@ -0,0 +1,25 @@ +package net.mograsim.logic.model.am2900.machine.registers.am2901; + +import java.util.ArrayList; +import java.util.List; + +import net.mograsim.machine.registers.Register; +import net.mograsim.machine.registers.SimpleRegisterGroup; + +public class Am2901RegisterGroup extends SimpleRegisterGroup +{ + public static final Am2901RegisterGroup instance = new Am2901RegisterGroup(); + + private Am2901RegisterGroup() + { + super("Am2901", getAllRegisters()); + } + + private static Register[] getAllRegisters() + { + List allRegistersModifiable = new ArrayList<>(); + allRegistersModifiable.addAll(NumberedRegister.instancesCorrectOrder); + allRegistersModifiable.add(QRegister.instance); + return allRegistersModifiable.toArray(Register[]::new); + } +} \ No newline at end of file diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/NumberedRegister.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/NumberedRegister.java similarity index 51% rename from plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/NumberedRegister.java rename to plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/NumberedRegister.java index 7ca3d382..e98e5946 100644 --- a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/NumberedRegister.java +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/NumberedRegister.java @@ -1,15 +1,10 @@ -package net.mograsim.logic.model.am2900.machine.registers; +package net.mograsim.logic.model.am2900.machine.registers.am2901; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; import java.util.List; -import net.mograsim.machine.StandardRegister; - -public class NumberedRegister extends StandardRegister +public class NumberedRegister extends Am2901Register { public static final List instancesCorrectOrder; @@ -21,29 +16,19 @@ public class NumberedRegister extends StandardRegister instancesCorrectOrder = Collections.unmodifiableList(instancesCorrectOrderModifiable); } - private final int index; - private final String indexBitstring; - - private NumberedRegister(int i) + private NumberedRegister(int index) { - super("R" + i, new HashSet<>(Arrays.asList(new String[] { "R" + i, "Register #" + i, "Register " + i })), 16, new HashMap<>()); - this.index = i; + super("R" + index, "regs.c" + getIndexAsBitstring(index) + ".q", 4); + + } + private static String getIndexAsBitstring(int index) + { StringBuilder sb = new StringBuilder(); sb.append((index & 0b1000) != 0 ? '1' : '0'); sb.append((index & 0b0100) != 0 ? '1' : '0'); sb.append((index & 0b0010) != 0 ? '1' : '0'); sb.append((index & 0b0001) != 0 ? '1' : '0'); - this.indexBitstring = sb.toString(); - } - - public int getIndex() - { - return index; - } - - public String getIndexAsBitstring() - { - return indexBitstring; + return sb.toString(); } } \ No newline at end of file diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/QRegister.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/QRegister.java new file mode 100644 index 00000000..4e426cc6 --- /dev/null +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/am2901/QRegister.java @@ -0,0 +1,11 @@ +package net.mograsim.logic.model.am2900.machine.registers.am2901; + +public class QRegister extends Am2901Register +{ + public static final QRegister instance = new QRegister(); + + private QRegister() + { + super("Q", "qreg.q", 4); + } +} \ No newline at end of file -- 2.17.1