From: Daniel Kirschten Date: Mon, 30 Sep 2019 21:51:43 +0000 (+0200) Subject: Am2900Machine now has registers X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=45cdf52447cc661bdffa0573ea31ff52cc134ad5;p=Mograsim.git Am2900Machine now has registers --- diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900Machine.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900Machine.java index f705e74e..759fda98 100644 --- a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900Machine.java +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900Machine.java @@ -6,6 +6,8 @@ import java.util.Set; import net.mograsim.logic.core.components.CoreClock; import net.mograsim.logic.core.timeline.Timeline; import net.mograsim.logic.core.types.BitVector; +import net.mograsim.logic.model.am2900.machine.registers.NumberedRegister; +import net.mograsim.logic.model.am2900.machine.registers.QRegister; import net.mograsim.logic.model.model.LogicModel; import net.mograsim.logic.model.model.LogicModelModifiable; import net.mograsim.logic.model.model.components.ModelComponent; @@ -81,7 +83,7 @@ public class Am2900Machine implements Machine MicroInstructionParameter[] defaultParams = muiDef.createDefaultInstruction().getParameters(); defaultParams[19] = paramClassifications[19].parse("JZ"); MicroInstruction jzMI = MicroInstruction.create(defaultParams); - logicModel.getComponentByName("Am2900").setHighLevelState("muir_2.q", jzMI.toBitVector()); + am2900.setHighLevelState("muir_2.q", jzMI.toBitVector()); } @Override @@ -110,15 +112,37 @@ public class Am2900Machine implements Machine @Override public BitVector getRegister(Register r) { - // TODO Auto-generated method stub - return null; + String am2901CellSuffix; + if (r instanceof QRegister) + am2901CellSuffix = "qreg.q"; + else if (r instanceof NumberedRegister) + am2901CellSuffix = "regs.c" + ((NumberedRegister) r).getIndexAsBitstring() + ".q"; + else + throw new IllegalArgumentException("Not a register of an Am2900Machine: " + r); + BitVector result = BitVector.of(); + for (int i = 0; i < 16; i += 4) + { + String hlsID = String.format("am2901_%d-%d.%s", (i + 3), i, am2901CellSuffix); + result = result.concat((BitVector) am2900.getHighLevelState(hlsID)); + } + return result; } @Override public void setRegister(Register r, BitVector value) { - // TODO Auto-generated method stub - + String am2901CellSuffix; + if (r instanceof QRegister) + am2901CellSuffix = "qreg.q"; + else if (r instanceof NumberedRegister) + am2901CellSuffix = "regs.c" + ((NumberedRegister) r).getIndexAsBitstring() + ".q"; + else + throw new IllegalArgumentException("Not a register of an Am2900Machine: " + r); + for (int i = 0; i < 16; i += 4) + { + String hlsID = String.format("am2901_%d-%d.%s", (i + 3), i, am2901CellSuffix); + am2900.setHighLevelState(hlsID, value.subVector(i, i + 4)); + } } @Override diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MachineDefinition.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MachineDefinition.java index 1ed03720..325f63fb 100644 --- a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MachineDefinition.java +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MachineDefinition.java @@ -1,7 +1,11 @@ package net.mograsim.logic.model.am2900.machine; +import java.util.Collections; +import java.util.HashSet; import java.util.Set; +import net.mograsim.logic.model.am2900.machine.registers.NumberedRegister; +import net.mograsim.logic.model.am2900.machine.registers.QRegister; import net.mograsim.logic.model.model.LogicModelModifiable; import net.mograsim.machine.ISASchema; import net.mograsim.machine.MachineDefinition; @@ -13,6 +17,16 @@ public class Am2900MachineDefinition implements MachineDefinition { public static final String AM2900_MACHINE_ID = "Am2900"; + public static final Set allRegisters; + + static + { + Set allRegistersModifiable = new HashSet<>(); + allRegistersModifiable.add(QRegister.instance); + allRegistersModifiable.addAll(NumberedRegister.instancesCorrectOrder); + allRegisters = Collections.unmodifiableSet(allRegistersModifiable); + } + @Override public String getId() { @@ -40,8 +54,7 @@ public class Am2900MachineDefinition implements MachineDefinition @Override public Set getRegisters() { - // TODO Auto-generated method stub - return null; + return allRegisters; } @Override diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MicroInstructionDefinition.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MicroInstructionDefinition.java index 280b7886..0b6a26f8 100644 --- a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MicroInstructionDefinition.java +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MicroInstructionDefinition.java @@ -1,5 +1,6 @@ package net.mograsim.logic.model.am2900.machine; +import java.util.Arrays; import java.util.Optional; import net.mograsim.machine.mi.MicroInstructionDefinition; @@ -89,7 +90,7 @@ public class Am2900MicroInstructionDefinition implements MicroInstructionDefinit @Override public ParameterClassification[] getParameterClassifications() { - return classes; + return Arrays.copyOf(classes, classes.length); } @Override 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/NumberedRegister.java new file mode 100644 index 00000000..7ca3d382 --- /dev/null +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/NumberedRegister.java @@ -0,0 +1,49 @@ +package net.mograsim.logic.model.am2900.machine.registers; + +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 static final List instancesCorrectOrder; + + static + { + List instancesCorrectOrderModifiable = new ArrayList<>(); + for (int i = 0; i < 16; i++) + instancesCorrectOrderModifiable.add(new NumberedRegister(i)); + instancesCorrectOrder = Collections.unmodifiableList(instancesCorrectOrderModifiable); + } + + private final int index; + private final String indexBitstring; + + private NumberedRegister(int i) + { + super("R" + i, new HashSet<>(Arrays.asList(new String[] { "R" + i, "Register #" + i, "Register " + i })), 16, new HashMap<>()); + this.index = i; + + 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; + } +} \ No newline at end of file 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 new file mode 100644 index 00000000..b5d35407 --- /dev/null +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/registers/QRegister.java @@ -0,0 +1,17 @@ +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.machine/src/net/mograsim/machine/StandardRegister.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/StandardRegister.java new file mode 100644 index 00000000..6fea551f --- /dev/null +++ b/plugins/net.mograsim.machine/src/net/mograsim/machine/StandardRegister.java @@ -0,0 +1,47 @@ +package net.mograsim.machine; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public abstract class StandardRegister implements Register +{ + private final String id; + private final Set names; + private final int width; + private final Map widthForAliases; + + public StandardRegister(String id, Set names, int width, Map widthForAliases) + { + this.id = id; + this.names = Collections.unmodifiableSet(new HashSet<>(names)); + this.width = width; + this.widthForAliases = Collections.unmodifiableMap(new HashMap<>(widthForAliases)); + } + + @Override + public String id() + { + return id; + } + + @Override + public Set names() + { + return names; + } + + @Override + public int getWidth() + { + return width; + } + + @Override + public int getWidth(String name) + { + return widthForAliases.getOrDefault(name, width); + } +} \ No newline at end of file