Made get/setHLS final to force components to set a HLSHandler
[Mograsim.git] / plugins / net.mograsim.machine / src / net / mograsim / machine / mi / components / ModelMicroInstructionMemory.java
index b3c4174..706734f 100644 (file)
@@ -3,11 +3,14 @@ package net.mograsim.machine.mi.components;
 import net.mograsim.logic.model.model.LogicModelModifiable;
 import net.mograsim.logic.model.model.wires.Pin;
 import net.mograsim.logic.model.model.wires.PinUsage;
-import net.mograsim.machine.Machine;
+import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
+import net.mograsim.logic.model.serializing.IdentifyParams;
+import net.mograsim.logic.model.snippets.HighLevelStateHandler;
 import net.mograsim.machine.ModelMemory;
+import net.mograsim.machine.mi.MicroInstructionMemory;
 import net.mograsim.machine.mi.MicroInstructionMemoryDefinition;
 
-public abstract class ModelMicroInstructionMemory<M extends Machine> extends ModelMemory<M>
+public abstract class ModelMicroInstructionMemory extends ModelMemory
 {
        private final Pin addrPin, dataPin;
        private CoreMicroInstructionMemory memory;
@@ -21,6 +24,38 @@ public abstract class ModelMicroInstructionMemory<M extends Machine> extends Mod
                addPin(dataPin = new Pin(model, this, "D", definition.getMicroInstructionDefinition().sizeInBits(), PinUsage.OUTPUT, getWidth(),
                                50));
 
+               setHighLevelStateHandler(new HighLevelStateHandler()
+               {
+                       @Override
+                       public Object getHighLevelState(String stateID)
+                       {
+                               if (stateID.equals("memory_binding"))
+                                       return memory.getMemory();
+                               throw new IllegalArgumentException("No high level state with ID " + stateID);
+                       }
+
+                       @Override
+                       public void setHighLevelState(String stateID, Object newState)
+                       {
+                               if (stateID.equals("memory_binding"))
+                                       memory.setMemory((MicroInstructionMemory) newState);
+                               else
+                                       throw new IllegalArgumentException("No high level state with ID " + stateID);
+                       }
+
+                       @Override
+                       public String getIDForSerializing(IdentifyParams idParams)
+                       {
+                               return null;
+                       }
+
+                       @Override
+                       public Object getParamsForSerializing(IdentifyParams idParams)
+                       {
+                               return null;
+                       }
+               });
+
                init();
        }
 
@@ -48,4 +83,9 @@ public abstract class ModelMicroInstructionMemory<M extends Machine> extends Mod
        {
                this.memory = memory;
        }
-}
+
+       static
+       {
+               LogicCoreAdapter.addComponentAdapter(new MicroInstructionMemoryAdapter());
+       }
+}
\ No newline at end of file