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;
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
@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
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;
{
public static final String AM2900_MACHINE_ID = "Am2900";
+ public static final Set<Register> allRegisters;
+
+ static
+ {
+ Set<Register> allRegistersModifiable = new HashSet<>();
+ allRegistersModifiable.add(QRegister.instance);
+ allRegistersModifiable.addAll(NumberedRegister.instancesCorrectOrder);
+ allRegisters = Collections.unmodifiableSet(allRegistersModifiable);
+ }
+
@Override
public String getId()
{
@Override
public Set<Register> getRegisters()
{
- // TODO Auto-generated method stub
- return null;
+ return allRegisters;
}
@Override
package net.mograsim.logic.model.am2900.machine;
+import java.util.Arrays;
import java.util.Optional;
import net.mograsim.machine.mi.MicroInstructionDefinition;
@Override
public ParameterClassification[] getParameterClassifications()
{
- return classes;
+ return Arrays.copyOf(classes, classes.length);
}
@Override
--- /dev/null
+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<NumberedRegister> instancesCorrectOrder;
+
+ static
+ {
+ List<NumberedRegister> 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
--- /dev/null
+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
--- /dev/null
+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<String> names;
+ private final int width;
+ private final Map<String, Integer> widthForAliases;
+
+ public StandardRegister(String id, Set<String> names, int width, Map<String, Integer> 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<String> 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