From: Daniel Kirschten Date: Tue, 1 Oct 2019 14:25:58 +0000 (+0200) Subject: Made get/setHLS final to force components to set a HLSHandler X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=0c97f70d199e1ffcd2bc13817f7bb12867ba033e;p=Mograsim.git Made get/setHLS final to force components to set a HLSHandler --- diff --git a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/ModelComponent.java b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/ModelComponent.java index d543c543..ded66859 100644 --- a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/ModelComponent.java +++ b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/ModelComponent.java @@ -14,6 +14,7 @@ import net.mograsim.logic.model.model.wires.Pin; import net.mograsim.logic.model.serializing.IdentifyParams; import net.mograsim.logic.model.serializing.JSONSerializable; import net.mograsim.logic.model.snippets.HighLevelStateHandler; +import net.mograsim.logic.model.snippets.highlevelstatehandlers.DefaultHighLevelStateHandler; /** * The base class for all model components.
@@ -77,6 +78,8 @@ public abstract class ModelComponent implements JSONSerializable this.pinAddedListeners = new ArrayList<>(); this.pinRemovedListeners = new ArrayList<>(); + this.highLevelStateHandler = new DefaultHighLevelStateHandler(); + if (callInit) init(); } @@ -216,7 +219,7 @@ public abstract class ModelComponent implements JSONSerializable * * @author Daniel Kirschten */ - public Object getHighLevelState(String stateID) + public final Object getHighLevelState(String stateID) { return highLevelStateHandler.getHighLevelState(stateID); } @@ -230,7 +233,7 @@ public abstract class ModelComponent implements JSONSerializable * * @author Daniel Kirschten */ - public void setHighLevelState(String stateID, Object newState) + public final void setHighLevelState(String stateID, Object newState) { highLevelStateHandler.setHighLevelState(stateID, newState); } diff --git a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelClock.java b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelClock.java index 38963536..d84e2027 100644 --- a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelClock.java +++ b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelClock.java @@ -20,6 +20,7 @@ import net.mograsim.logic.model.modeladapter.LogicCoreAdapter; import net.mograsim.logic.model.modeladapter.componentadapters.ClockAdapter; import net.mograsim.logic.model.serializing.IdentifyParams; import net.mograsim.logic.model.serializing.IndirectModelComponentCreator; +import net.mograsim.logic.model.snippets.HighLevelStateHandler; import net.mograsim.logic.model.util.JsonHandler; import net.mograsim.preferences.Preferences; @@ -53,6 +54,47 @@ public class ModelClock extends ModelComponent this.outputPin = new Pin(model, this, "", 1, PinUsage.OUTPUT, oc.newX(width, height / 2), oc.newY(width, height / 2)); addPin(outputPin); + setHighLevelStateHandler(new HighLevelStateHandler() + { + @Override + public Object getHighLevelState(String stateID) + { + switch (stateID) + { + case "out": + if (clock != null) + return clock.getOut().getInputValues(); + return null; + default: + throw new IllegalArgumentException("No high level state with ID " + stateID); + } + } + + @Override + public void setHighLevelState(String stateID, Object newState) + { + switch (stateID) + { + case "out": + throw new UnsupportedOperationException("cannot set state of clock"); + default: + 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(); } @@ -89,32 +131,6 @@ public class ModelClock extends ModelComponent return clock != null; } - @Override - public Object getHighLevelState(String stateID) - { - switch (stateID) - { - case "out": - if (clock != null) - return clock.getOut().getInputValues(); - return null; - default: - return super.getHighLevelState(stateID); - } - } - - @Override - public void setHighLevelState(String stateID, Object newState) - { - switch (stateID) - { - case "out": - throw new UnsupportedOperationException("cannot set state of clock"); - default: - super.setHighLevelState(stateID, newState); - } - } - public CoreClock getClock() { return clock; diff --git a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelManualSwitch.java b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelManualSwitch.java index 7a995041..cf9735ae 100644 --- a/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelManualSwitch.java +++ b/plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/model/components/atomic/ModelManualSwitch.java @@ -19,6 +19,7 @@ import net.mograsim.logic.model.modeladapter.LogicCoreAdapter; import net.mograsim.logic.model.modeladapter.componentadapters.ManualSwitchAdapter; import net.mograsim.logic.model.serializing.IdentifyParams; import net.mograsim.logic.model.serializing.IndirectModelComponentCreator; +import net.mograsim.logic.model.snippets.HighLevelStateHandler; import net.mograsim.preferences.Preferences; public class ModelManualSwitch extends ModelComponent @@ -48,6 +49,49 @@ public class ModelManualSwitch extends ModelComponent setSize(width, height); addPin(this.outputPin = new Pin(model, this, "", logicWidth, PinUsage.OUTPUT, width, height / 2)); + setHighLevelStateHandler(new HighLevelStateHandler() + { + @Override + public Object getHighLevelState(String stateID) + { + switch (stateID) + { + case "out": + if (manualSwitch != null) + return manualSwitch.getValues(); + return null; + default: + throw new IllegalArgumentException("No high level state with ID " + stateID); + } + } + + @Override + public void setHighLevelState(String stateID, Object newState) + { + switch (stateID) + { + case "out": + if (manualSwitch != null) + manualSwitch.setState((BitVector) newState); + break; + default: + 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(); } @@ -108,35 +152,6 @@ public class ModelManualSwitch extends ModelComponent return manualSwitch != null; } - @Override - public Object getHighLevelState(String stateID) - { - switch (stateID) - { - case "out": - if (manualSwitch != null) - return manualSwitch.getValues(); - return null; - default: - return super.getHighLevelState(stateID); - } - } - - @Override - public void setHighLevelState(String stateID, Object newState) - { - switch (stateID) - { - case "out": - if (manualSwitch != null) - manualSwitch.setState((BitVector) newState); - break; - default: - super.setHighLevelState(stateID, newState); - break; - } - } - @Override public boolean clicked(double x, double y) { diff --git a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/components/ModelMicroInstructionMemory.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/components/ModelMicroInstructionMemory.java index aeffbd2c..706734f2 100644 --- a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/components/ModelMicroInstructionMemory.java +++ b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/components/ModelMicroInstructionMemory.java @@ -4,6 +4,8 @@ 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.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; @@ -22,6 +24,38 @@ public abstract class ModelMicroInstructionMemory extends ModelMemory 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(); } @@ -50,23 +84,6 @@ public abstract class ModelMicroInstructionMemory extends ModelMemory this.memory = memory; } - @Override - public void setHighLevelState(String stateID, Object newState) - { - if (stateID.equals("memory_binding")) - memory.setMemory((MicroInstructionMemory) newState); - else - super.setHighLevelState(stateID, newState); - } - - @Override - public Object getHighLevelState(String stateID) - { - if (stateID.equals("memory_binding")) - return memory.getMemory(); - return super.getHighLevelState(stateID); - } - static { LogicCoreAdapter.addComponentAdapter(new MicroInstructionMemoryAdapter()); diff --git a/plugins/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelWordAddressableMemory.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelWordAddressableMemory.java index 7490b361..b2498498 100644 --- a/plugins/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelWordAddressableMemory.java +++ b/plugins/net.mograsim.machine/src/net/mograsim/machine/standard/memory/ModelWordAddressableMemory.java @@ -4,6 +4,8 @@ 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.logic.model.modeladapter.LogicCoreAdapter; +import net.mograsim.logic.model.serializing.IdentifyParams; +import net.mograsim.logic.model.snippets.HighLevelStateHandler; import net.mograsim.machine.MainMemory; import net.mograsim.machine.MainMemoryDefinition; import net.mograsim.machine.ModelMemory; @@ -23,6 +25,38 @@ public abstract class ModelWordAddressableMemory extends ModelMemory addPin(dataPin = new Pin(model, this, "D", definition.getCellWidth(), PinUsage.TRISTATE, getWidth(), 50)); addPin(rWPin = new Pin(model, this, "RW", 1, PinUsage.INPUT, getWidth(), 70)); + 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((MainMemory) 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(); } @@ -56,23 +90,6 @@ public abstract class ModelWordAddressableMemory extends ModelMemory return memory; } - @Override - public void setHighLevelState(String stateID, Object newState) - { - if (stateID.equals("memory_binding")) - memory.setMemory((MainMemory) newState); - else - super.setHighLevelState(stateID, newState); - } - - @Override - public Object getHighLevelState(String stateID) - { - if (stateID.equals("memory_binding")) - return memory.getMemory(); - return super.getHighLevelState(stateID); - } - static { LogicCoreAdapter.addComponentAdapter(new WordAddressableMemoryAdapter());