Added RegisterGroups for MachineDefinition
authorChristian Femers <femers@in.tum.de>
Sun, 6 Oct 2019 20:13:37 +0000 (22:13 +0200)
committerChristian Femers <femers@in.tum.de>
Sun, 6 Oct 2019 20:13:37 +0000 (22:13 +0200)
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/AbstractAm2900MachineDefinition.java
plugins/net.mograsim.machine/src/net/mograsim/machine/Identifiable.java [new file with mode: 0644]
plugins/net.mograsim.machine/src/net/mograsim/machine/MachineDefinition.java
plugins/net.mograsim.machine/src/net/mograsim/machine/Register.java
plugins/net.mograsim.machine/src/net/mograsim/machine/RegisterGroup.java [new file with mode: 0644]
plugins/net.mograsim.machine/src/net/mograsim/machine/SimpleRegisterGroup.java [new file with mode: 0644]
plugins/net.mograsim.machine/src/net/mograsim/machine/UnionRegisterGroup.java [new file with mode: 0644]

index fa40eb8..20f7c58 100644 (file)
@@ -10,6 +10,7 @@ import net.mograsim.logic.model.model.LogicModelModifiable;
 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)
@@ -97,4 +98,10 @@ public class AbstractAm2900MachineDefinition implements MachineDefinition
                return Am2900MicroInstructionMemoryDefinition.instance;
        }
 
+       @Override
+       public Set<RegisterGroup> getRegisterGroups()
+       {
+               return null; // TODO create groups for am2904, am2901-asmUsable, am2901-internal, ...
+       }
+
 }
diff --git a/plugins/net.mograsim.machine/src/net/mograsim/machine/Identifiable.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/Identifiable.java
new file mode 100644 (file)
index 0000000..2b05913
--- /dev/null
@@ -0,0 +1,9 @@
+package net.mograsim.machine;
+
+public interface Identifiable
+{
+       /**
+        * Returns a human readable unique, consistent id of the object.
+        */
+       String id();
+}
index 8f1ee26..1c4aa86 100644 (file)
@@ -39,6 +39,14 @@ public interface MachineDefinition
         */
        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.
index 4bcb7f2..979f1be 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Set;
  * @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.
@@ -17,6 +17,7 @@ public interface Register
         * @return the registers id as case sensitive String
         * @author Christian Femers
         */
+       @Override
        String id();
 
        /**
diff --git a/plugins/net.mograsim.machine/src/net/mograsim/machine/RegisterGroup.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/RegisterGroup.java
new file mode 100644 (file)
index 0000000..4838590
--- /dev/null
@@ -0,0 +1,16 @@
+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();
+}
diff --git a/plugins/net.mograsim.machine/src/net/mograsim/machine/SimpleRegisterGroup.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/SimpleRegisterGroup.java
new file mode 100644 (file)
index 0000000..0c1d2ae
--- /dev/null
@@ -0,0 +1,38 @@
+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();
+       }
+
+}
diff --git a/plugins/net.mograsim.machine/src/net/mograsim/machine/UnionRegisterGroup.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/UnionRegisterGroup.java
new file mode 100644 (file)
index 0000000..bfe4248
--- /dev/null
@@ -0,0 +1,41 @@
+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;
+       }
+
+}