import net.mograsim.machine.ISASchema;
import net.mograsim.machine.MachineDefinition;
import net.mograsim.machine.Register;
+import net.mograsim.machine.RegisterGroup;
//we can't use the Singleton pattern here because a MachineDefinition needs a public parameterless constructor
//(used for detecting installed machines in plugin.core)
return Am2900MicroInstructionMemoryDefinition.instance;
}
+ @Override
+ public Set<RegisterGroup> getRegisterGroups()
+ {
+ return null; // TODO create groups for am2904, am2901-asmUsable, am2901-internal, ...
+ }
+
}
--- /dev/null
+package net.mograsim.machine;
+
+public interface Identifiable
+{
+ /**
+ * Returns a human readable unique, consistent id of the object.
+ */
+ String id();
+}
*/
Set<Register> getRegisters();
+ /**
+ * Returns a set of all RegisterGroups that the machine contains
+ *
+ * @return all register groups present in the machine.
+ * @author Christian Femers
+ */
+ Set<RegisterGroup> getRegisterGroups();
+
/**
* The number of bits used by the machine to address main memory. Note that this should be the number of bits used in the CPU, not a
* possibly different one used by the bus system.
* @author Christian Femers
*
*/
-public interface Register
+public interface Register extends Identifiable
{
/**
* The unique identifier of the register. This does not have to be the display name or name in the assembly language.
* @return the registers id as case sensitive String
* @author Christian Femers
*/
+ @Override
String id();
/**
--- /dev/null
+package net.mograsim.machine;
+
+import java.util.Set;
+
+public interface RegisterGroup extends Identifiable
+{
+ /**
+ * Returns all Registers contained in this group and subgroups
+ */
+ Set<Register> getRegisters();
+
+ /**
+ * Returns the sub groups of this group. May very well be an empty set.
+ */
+ Set<RegisterGroup> getSubGroups();
+}
--- /dev/null
+package net.mograsim.machine;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class SimpleRegisterGroup implements RegisterGroup
+{
+
+ private final String id;
+ private final Set<Register> registers;
+
+ protected SimpleRegisterGroup(String id, Register... registers)
+ {
+ this.id = id;
+ this.registers = Collections.unmodifiableSet(new HashSet<>(List.of(registers)));
+ }
+
+ @Override
+ public String id()
+ {
+ return id;
+ }
+
+ @Override
+ public Set<Register> getRegisters()
+ {
+ return registers;
+ }
+
+ @Override
+ public Set<RegisterGroup> getSubGroups()
+ {
+ return Set.of();
+ }
+
+}
--- /dev/null
+package net.mograsim.machine;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class UnionRegisterGroup implements RegisterGroup
+{
+ private final String id;
+ private final Set<RegisterGroup> subGroups;
+ private final Set<Register> subGroupRegisters;
+
+ public UnionRegisterGroup(String id, RegisterGroup... subGroups)
+ {
+ this.id = id;
+ this.subGroups = Collections.unmodifiableSet(new HashSet<>(List.of(subGroups)));
+ this.subGroupRegisters = this.subGroups.stream().flatMap(sg -> sg.getRegisters().stream()).distinct()
+ .collect(Collectors.toUnmodifiableSet());
+ }
+
+ @Override
+ public String id()
+ {
+ return id;
+ }
+
+ @Override
+ public Set<Register> getRegisters()
+ {
+ return subGroupRegisters;
+ }
+
+ @Override
+ public Set<RegisterGroup> getSubGroups()
+ {
+ return subGroups;
+ }
+
+}