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
1 package net.mograsim.machine.mi.components;
2
3 import net.mograsim.logic.model.model.LogicModelModifiable;
4 import net.mograsim.logic.model.model.wires.Pin;
5 import net.mograsim.logic.model.model.wires.PinUsage;
6 import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
7 import net.mograsim.logic.model.serializing.IdentifyParams;
8 import net.mograsim.logic.model.snippets.HighLevelStateHandler;
9 import net.mograsim.machine.ModelMemory;
10 import net.mograsim.machine.mi.MicroInstructionMemory;
11 import net.mograsim.machine.mi.MicroInstructionMemoryDefinition;
12
13 public abstract class ModelMicroInstructionMemory extends ModelMemory
14 {
15         private final Pin addrPin, dataPin;
16         private CoreMicroInstructionMemory memory;
17         private final MicroInstructionMemoryDefinition definition;
18
19         public ModelMicroInstructionMemory(LogicModelModifiable model, MicroInstructionMemoryDefinition definition, String name)
20         {
21                 super(model, 120, 150, name, "MPM", false);
22                 this.definition = definition;
23                 addPin(addrPin = new Pin(model, this, "A", definition.getMemoryAddressBits(), PinUsage.INPUT, getWidth(), 30));
24                 addPin(dataPin = new Pin(model, this, "D", definition.getMicroInstructionDefinition().sizeInBits(), PinUsage.OUTPUT, getWidth(),
25                                 50));
26
27                 setHighLevelStateHandler(new HighLevelStateHandler()
28                 {
29                         @Override
30                         public Object getHighLevelState(String stateID)
31                         {
32                                 if (stateID.equals("memory_binding"))
33                                         return memory.getMemory();
34                                 throw new IllegalArgumentException("No high level state with ID " + stateID);
35                         }
36
37                         @Override
38                         public void setHighLevelState(String stateID, Object newState)
39                         {
40                                 if (stateID.equals("memory_binding"))
41                                         memory.setMemory((MicroInstructionMemory) newState);
42                                 else
43                                         throw new IllegalArgumentException("No high level state with ID " + stateID);
44                         }
45
46                         @Override
47                         public String getIDForSerializing(IdentifyParams idParams)
48                         {
49                                 return null;
50                         }
51
52                         @Override
53                         public Object getParamsForSerializing(IdentifyParams idParams)
54                         {
55                                 return null;
56                         }
57                 });
58
59                 init();
60         }
61
62         public MicroInstructionMemoryDefinition getDefinition()
63         {
64                 return definition;
65         }
66
67         public Pin getAddressPin()
68         {
69                 return addrPin;
70         }
71
72         public Pin getDataPin()
73         {
74                 return dataPin;
75         }
76
77         public CoreMicroInstructionMemory getCoreMemory()
78         {
79                 return memory;
80         }
81
82         public void setCoreModelBinding(CoreMicroInstructionMemory memory)
83         {
84                 this.memory = memory;
85         }
86
87         static
88         {
89                 LogicCoreAdapter.addComponentAdapter(new MicroInstructionMemoryAdapter());
90         }
91 }