X-Git-Url: https://mograsim.net/gitweb/?p=Mograsim.git;a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Flaunch%2FMachineDebugTarget.java;h=5bb87a8d4f74ee39a117612bd289760bb3d980eb;hp=ca7480434e927dfb3407954395f14728f9c6b0eb;hb=b5d55c59d7069171bd928e4a945d9185ee4bc2b0;hpb=f098cd47d06be0cc654532a5fad0e5e89f0ef93c diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineDebugTarget.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineDebugTarget.java index ca748043..5bb87a8d 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineDebugTarget.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineDebugTarget.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; +import java.util.function.Function; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarkerDelta; @@ -38,10 +39,15 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.ui.PlatformUI; import net.mograsim.logic.model.LogicExecuter; +import net.mograsim.machine.BitVectorMemory; +import net.mograsim.machine.BitVectorMemoryDefinition; import net.mograsim.machine.Machine; import net.mograsim.machine.MachineDefinition; +import net.mograsim.machine.StandardMainMemory; import net.mograsim.machine.mi.MicroInstructionMemoryParser; -import net.mograsim.machine.standard.memory.MainMemoryParser; +import net.mograsim.machine.mi.StandardMPROM; +import net.mograsim.machine.standard.memory.AbstractAssignableBitVectorMemory; +import net.mograsim.machine.standard.memory.BitVectorBasedMemoryParser; import net.mograsim.plugin.MograsimActivator; public class MachineDebugTarget extends PlatformObject implements IDebugTarget, IMemoryBlockRetrievalExtension @@ -53,6 +59,7 @@ public class MachineDebugTarget extends PlatformObject implements IDebugTarget, private final LogicExecuter exec; private final MachineThread thread; private final IFile mpmFile; + private final Optional mpromFile; private final Optional memFile; private boolean running; @@ -61,8 +68,8 @@ public class MachineDebugTarget extends PlatformObject implements IDebugTarget, private final IResourceChangeListener resChangedListener; - public MachineDebugTarget(ILaunch launch, IFile mpmFile, Optional memFile, MachineDefinition machineDefinition) - throws CoreException + public MachineDebugTarget(ILaunch launch, IFile mpmFile, Optional mpromFile, Optional memFile, + MachineDefinition machineDefinition) throws CoreException { this.launch = launch; this.machine = machineDefinition.createNew(); @@ -70,9 +77,11 @@ public class MachineDebugTarget extends PlatformObject implements IDebugTarget, this.executionSpeedListeners = new ArrayList<>(); this.mpmFile = mpmFile; + this.mpromFile = mpromFile; this.memFile = memFile; assignMicroInstructionMemory(); + assignMPROM(); assignMainMemory(); exec.startLiveExecution(); @@ -371,35 +380,53 @@ public class MachineDebugTarget extends PlatformObject implements IDebugTarget, private void resourceChanged(IResourceChangeEvent event) { - IResourceDelta mpmDelta; - if (event.getType() == IResourceChangeEvent.POST_CHANGE && (mpmDelta = event.getDelta().findMember(mpmFile.getFullPath())) != null - && (mpmDelta.getKind() & CHANGED) == CHANGED && mpmFile.exists()) + if (event.getType() == IResourceChangeEvent.POST_CHANGE) { - AtomicBoolean doHotReplace = new AtomicBoolean(); - PlatformUI.getWorkbench().getDisplay().syncExec(() -> + tryHotReplaceIfChanged(event, mpmFile, this::assignMicroInstructionMemory, "MPM"); + + if (mpromFile.isPresent()) + tryHotReplaceIfChanged(event, mpromFile.get(), this::assignMPROM, "MPROM"); + } + } + + private static void tryHotReplaceIfChanged(IResourceChangeEvent event, IFile memFile, RunnableThrowingCoreException assign, String type) + { + IResourceDelta mpmDelta = event.getDelta().findMember(memFile.getFullPath()); + if (mpmDelta != null && (mpmDelta.getKind() & CHANGED) == CHANGED && memFile.exists()) + tryHotReplace(memFile, assign, type); + } + + private static void tryHotReplace(IFile memFile, RunnableThrowingCoreException assign, String type) + { + AtomicBoolean doHotReplace = new AtomicBoolean(); + PlatformUI.getWorkbench().getDisplay().syncExec(() -> + { + if (MessageDialog.openConfirm(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Hot Replace " + type + "?", + String.format("The " + type + " %s has been modified on the file system. Replace simulated " + type + + " with modified contents?", memFile.getName()))) + doHotReplace.set(true); + }); + if (doHotReplace.get()) + { + try { - if (MessageDialog.openConfirm(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Hot Replace MPM?", - String.format("The MPM %s has been modified on the file system. Replace simulated MPM with modified contents?", - mpmFile.getName()))) - doHotReplace.set(true); - }); - if (doHotReplace.get()) + assign.run(); + } + catch (CoreException e) { - try - { - assignMicroInstructionMemory(); - } - catch (CoreException e) - { - PlatformUI.getWorkbench().getDisplay() - .asyncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), - "Failed Hot Replace!", - "An error occurred trying to read the modified MPM from the file system: " + e.getMessage())); - } + PlatformUI.getWorkbench().getDisplay() + .asyncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), + "Failed Hot Replace!", + "An error occurred trying to read the modified " + type + " from the file system: " + e.getMessage())); } } } + private static interface RunnableThrowingCoreException + { + public void run() throws CoreException; + } + private void assignMicroInstructionMemory() throws CoreException { try (InputStream mpmStream = mpmFile.getContents()) @@ -413,19 +440,32 @@ public class MachineDebugTarget extends PlatformObject implements IDebugTarget, } } + private void assignMPROM() throws CoreException + { + assignMemory(mpromFile, machine.getMPROM(), machine.getDefinition().getMPROMDefinition(), StandardMPROM::new, "MPROM"); + } + private void assignMainMemory() throws CoreException + { + assignMemory(memFile, machine.getMainMemory(), machine.getDefinition().getMainMemoryDefinition(), StandardMainMemory::new, + "initial RAM"); + } + + private static void assignMemory(Optional memFile, + AbstractAssignableBitVectorMemory memoryToAssign, D definition, Function newMemory, String type) throws CoreException { if (memFile.isPresent()) { try (InputStream initialRAMStream = memFile.get().getContents()) { - machine.getMainMemory() - .bind(MainMemoryParser.parseMemory(machine.getDefinition().getMainMemoryDefinition(), initialRAMStream)); + M mem = newMemory.apply(definition); + BitVectorBasedMemoryParser.parseMemory(mem, initialRAMStream); + memoryToAssign.bind(mem); } catch (IOException e) { throw new CoreException( - new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, "Unexpected IO exception reading initial RAM file", e)); + new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, "Unexpected IO exception reading " + type + " file", e)); } } } @@ -435,6 +475,11 @@ public class MachineDebugTarget extends PlatformObject implements IDebugTarget, return mpmFile; } + public Optional getMPROMFile() + { + return mpromFile; + } + public Optional getMEMFile() { return memFile;