Restructured register system
[Mograsim.git] / plugins / net.mograsim.plugin.core / src / net / mograsim / plugin / launch / MachineStackFrame.java
1 package net.mograsim.plugin.launch;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.List;
6
7 import org.eclipse.core.runtime.PlatformObject;
8 import org.eclipse.debug.core.DebugException;
9 import org.eclipse.debug.core.ILaunch;
10 import org.eclipse.debug.core.model.IDebugTarget;
11 import org.eclipse.debug.core.model.IRegisterGroup;
12 import org.eclipse.debug.core.model.IStackFrame;
13 import org.eclipse.debug.core.model.IThread;
14 import org.eclipse.debug.core.model.IVariable;
15
16 import net.mograsim.machine.Machine;
17 import net.mograsim.machine.MachineDefinition;
18 import net.mograsim.machine.registers.RegisterGroup;
19 import net.mograsim.plugin.MograsimActivator;
20
21 public class MachineStackFrame extends PlatformObject implements IStackFrame
22 {
23         private final MachineThread thread;
24         private final List<MachineRegisterGroup> registerGroups;
25
26         public MachineStackFrame(MachineThread thread)
27         {
28                 this.thread = thread;
29                 List<MachineRegisterGroup> registerGroupsModifiable = new ArrayList<>();
30                 MachineDefinition machDef = getMachine().getDefinition();
31                 if (!machDef.getUnsortedRegisters().isEmpty())
32                         registerGroupsModifiable.add(new MachineRegisterGroup(this, "<unsorted>", machDef.getUnsortedRegisters()));
33                 addRegisterGroups(null, registerGroupsModifiable, machDef.getRegisterGroups());
34                 this.registerGroups = Collections.unmodifiableList(registerGroupsModifiable);
35         }
36
37         private void addRegisterGroups(String base, List<MachineRegisterGroup> target, List<RegisterGroup> registerGroups)
38         {
39                 for (RegisterGroup rg : registerGroups)
40                 {
41                         String name = (base == null ? "" : base + '.') + rg.id();
42                         target.add(new MachineRegisterGroup(this, name, rg.getRegisters()));
43                         addRegisterGroups(name, target, rg.getSubGroups());
44                 }
45         }
46
47         @Override
48         public String getModelIdentifier()
49         {
50                 return MograsimActivator.PLUGIN_ID;
51         }
52
53         public Machine getMachine()
54         {
55                 return thread.getMachine();
56         }
57
58         @Override
59         public IDebugTarget getDebugTarget()
60         {
61                 return thread.getDebugTarget();
62         }
63
64         @Override
65         public ILaunch getLaunch()
66         {
67                 return thread.getLaunch();
68         }
69
70         @Override
71         public boolean canStepInto()
72         {
73                 return thread.canStepInto();
74         }
75
76         @Override
77         public boolean canStepOver()
78         {
79                 return thread.canStepOver();
80         }
81
82         @Override
83         public boolean canStepReturn()
84         {
85                 return thread.canStepReturn();
86         }
87
88         @Override
89         public boolean isStepping()
90         {
91                 return thread.isStepping();
92         }
93
94         @Override
95         public void stepInto() throws DebugException
96         {
97                 thread.stepInto();
98         }
99
100         @Override
101         public void stepOver() throws DebugException
102         {
103                 thread.stepOver();
104         }
105
106         @Override
107         public void stepReturn() throws DebugException
108         {
109                 thread.stepReturn();
110         }
111
112         @Override
113         public boolean canResume()
114         {
115                 return thread.canResume();
116         }
117
118         @Override
119         public boolean canSuspend()
120         {
121                 return thread.canSuspend();
122         }
123
124         @Override
125         public boolean isSuspended()
126         {
127                 return thread.isSuspended();
128         }
129
130         @Override
131         public void resume() throws DebugException
132         {
133                 thread.resume();
134         }
135
136         @Override
137         public void suspend() throws DebugException
138         {
139                 thread.suspend();
140         }
141
142         @Override
143         public boolean canTerminate()
144         {
145                 return thread.canTerminate();
146         }
147
148         @Override
149         public boolean isTerminated()
150         {
151                 return thread.isTerminated();
152         }
153
154         @Override
155         public void terminate() throws DebugException
156         {
157                 thread.terminate();
158         }
159
160         @Override
161         public IThread getThread()
162         {
163                 return thread;
164         }
165
166         @Override
167         public IVariable[] getVariables() throws DebugException
168         {
169                 return new IVariable[0];
170         }
171
172         @Override
173         public boolean hasVariables() throws DebugException
174         {
175                 return false;
176         }
177
178         @Override
179         public int getLineNumber() throws DebugException
180         {
181                 // TODO could we transmit the active microinstruction address using this?
182                 return -1;
183         }
184
185         @Override
186         public int getCharStart() throws DebugException
187         {
188                 return -1;
189         }
190
191         @Override
192         public int getCharEnd() throws DebugException
193         {
194                 return -1;
195         }
196
197         @Override
198         public String getName() throws DebugException
199         {
200                 return "pseudo stack frame";
201         }
202
203         @Override
204         public IRegisterGroup[] getRegisterGroups() throws DebugException
205         {
206                 return registerGroups.toArray(IRegisterGroup[]::new);
207         }
208
209         @Override
210         public boolean hasRegisterGroups() throws DebugException
211         {
212                 return true;
213         }
214 }