X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Ftables%2Fmi%2FInstructionView.java;h=214bd8ce1bae257b89db149b047619db96c365a2;hb=648fc6e69e09fe4467cb6bac47934be1a7dcf0d6;hp=e354c8f6ee6c7ad0a60eb297e01cb0501d3ce4f1;hpb=a60db0eb036058aa47c928653da0b504452aa595;p=Mograsim.git diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java index e354c8f6..214bd8ce 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java @@ -2,29 +2,33 @@ package net.mograsim.plugin.tables.mi; import java.io.IOException; import java.io.InputStream; +import java.util.Optional; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.swt.SWT; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.contexts.IDebugContextManager; +import org.eclipse.debug.ui.contexts.IDebugContextService; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorSite; import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.EditorPart; +import net.mograsim.machine.Machine; +import net.mograsim.machine.Machine.ActiveMicroInstructionChangedListener; import net.mograsim.machine.Memory.MemoryCellModifiedListener; -import net.mograsim.machine.mi.AssignableMicroInstructionMemory.MIMemoryReassignedListener; import net.mograsim.machine.mi.MicroInstructionMemory; -import net.mograsim.machine.mi.MicroInstructionMemory.ActiveMicroInstructionChangedListener; import net.mograsim.machine.mi.MicroInstructionMemoryParseException; import net.mograsim.machine.mi.MicroInstructionMemoryParser; +import net.mograsim.plugin.launch.MachineDebugContextListener; +import net.mograsim.plugin.launch.MachineDebugTarget; import net.mograsim.plugin.nature.MachineContext; -import net.mograsim.plugin.nature.MachineContext.ActiveMachineListener; import net.mograsim.plugin.nature.ProjectMachineContext; import net.mograsim.plugin.tables.DisplaySettings; import net.mograsim.plugin.tables.RadixSelector; @@ -37,6 +41,8 @@ public class InstructionView extends EditorPart private InstructionTable table; private MachineContext context; + private IFile file; + // Listeners private MemoryCellModifiedListener cellModifiedListener = address -> { @@ -44,23 +50,28 @@ public class InstructionView extends EditorPart table.refresh(); }; - private ActiveMicroInstructionChangedListener activeInstructionChangedListener = address -> highlight( - (int) (address - memory.getDefinition().getMinimalAddress())); - - private MIMemoryReassignedListener reassignedListener = newAssignee -> + private ActiveMicroInstructionChangedListener instChangeListener = (oldAddress, newAddress) -> { - // clear highlighting if the memory is reassigned - if (newAssignee != memory) - highlight(-1); + highlight((int) (newAddress - memory.getDefinition().getMinimalAddress())); }; - private ActiveMachineListener activeMachineListener = (oldMachine, newMachine) -> + private MachineDebugContextListener debugContextListener = new MachineDebugContextListener() { - // clear highlighting if the active machine changes - if (newMachine.isEmpty() || !newMachine.equals(oldMachine)) + @Override + public void machineDebugContextChanged(Optional oldTarget, Optional newTarget) { - highlight(-1); - oldMachine.ifPresent(m -> m.getMicroInstructionMemory().deregisterMemoryReassignedListener(reassignedListener)); + instChangeListener.instructionChanged(-1, -1); + oldTarget.ifPresent(target -> target.getMachine().removeActiveMicroInstructionChangedListener(instChangeListener)); + + newTarget.ifPresent(target -> + { + if (file.equals(target.getMPMFile())) + { + Machine m = target.getMachine(); + target.getMachine().addActiveMicroInstructionChangedListener(instChangeListener); + instChangeListener.instructionChanged(-1, m.getActiveMicroInstructionAddress()); + } + }); } }; @@ -75,7 +86,6 @@ public class InstructionView extends EditorPart DisplaySettings displaySettings = new DisplaySettings(); new RadixSelector(parent, displaySettings); - addActivationButton(parent); table = new InstructionTable(parent, displaySettings, getSite().getWorkbenchWindow().getWorkbench().getThemeManager()); table.setContentProvider(provider); table.bindMicroInstructionMemory(memory); @@ -83,6 +93,12 @@ public class InstructionView extends EditorPart GridData viewerData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH); viewerData.horizontalSpan = 3; table.getTableViewer().getTable().setLayoutData(viewerData); + + IDebugContextManager debugCManager = DebugUITools.getDebugContextManager(); + IDebugContextService contextService = debugCManager.getContextService(PlatformUI.getWorkbench().getActiveWorkbenchWindow()); + contextService.addDebugContextListener(debugContextListener); + debugContextListener.debugContextChanged(contextService.getActiveContext()); + parent.addDisposeListener(e -> contextService.removeDebugContextListener(debugContextListener)); } public void highlight(int row) @@ -90,30 +106,16 @@ public class InstructionView extends EditorPart table.highlight(row); } - private void addActivationButton(Composite parent) - { - Button activationButton = new Button(parent, SWT.PUSH); - activationButton.setText("Set Active"); - activationButton.addListener(SWT.Selection, e -> context.getActiveMachine().ifPresent(m -> - { - m.getMicroInstructionMemory().registerMemoryReassignedListener(reassignedListener); - context.addActiveMachineListener(activeMachineListener); - m.getMicroInstructionMemory().bind(memory); - })); - } - public void bindMicroInstructionMemory(MicroInstructionMemory memory) { if (this.memory != null) { this.memory.deregisterCellModifiedListener(cellModifiedListener); - this.memory.deregisterActiveMicroInstructionChangedListener(activeInstructionChangedListener); } this.memory = memory; if (memory != null) { this.memory.registerCellModifiedListener(cellModifiedListener); - this.memory.registerActiveMicroInstructionChangedListener(activeInstructionChangedListener); } if (table != null) table.bindMicroInstructionMemory(memory); @@ -195,17 +197,18 @@ public class InstructionView extends EditorPart if (input instanceof IFileEditorInput) { IFileEditorInput fileInput = (IFileEditorInput) input; - context = ProjectMachineContext.getMachineContextOf(fileInput.getFile().getProject()); - context.activateMachine(); + file = fileInput.getFile(); + context = ProjectMachineContext.getMachineContextOf(file.getProject()); + setPartName(fileInput.getName()); - open(fileInput.getFile()); - } + open(file); + } else + throw new IllegalArgumentException("Expected IFileEditorInput!"); } catch (Exception e) { throw new PartInitException("Failed to read input!", e); } - } @Override @@ -229,10 +232,13 @@ public class InstructionView extends EditorPart @Override public void dispose() { - memory.deregisterActiveMicroInstructionChangedListener(activeInstructionChangedListener); - memory.deregisterCellModifiedListener(cellModifiedListener); - context.getActiveMachine().ifPresent(m -> m.getMicroInstructionMemory().deregisterMemoryReassignedListener(reassignedListener)); - context.removeActiveMachineListener(activeMachineListener); + if (memory != null) + memory.deregisterCellModifiedListener(cellModifiedListener); super.dispose(); } + + public IFile getFile() + { + return file; + } }