X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Flaunch%2FMachineLaunchConfigType.java;h=a97d2c6f66a9b7ecba84bd893c66251e935c9ec6;hb=79fe4ef5f67bdf3b7a9d8002d1759ce87b3f90be;hp=e9b6531bc537171fb7f37716c10bb7141c5c2a82;hpb=d8d92dba4339e1240e4362046eadbe51c6740780;p=Mograsim.git diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineLaunchConfigType.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineLaunchConfigType.java index e9b6531b..a97d2c6f 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineLaunchConfigType.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineLaunchConfigType.java @@ -1,13 +1,17 @@ package net.mograsim.plugin.launch; +import static org.eclipse.core.resources.IResourceDelta.CHANGED; + import java.io.IOException; import java.io.InputStream; import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResourceChangeEvent; import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.IResourceDelta; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -16,13 +20,18 @@ import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.model.LaunchConfigurationDelegate; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.ui.PlatformUI; import org.eclipse.ui.statushandlers.StatusManager; import net.mograsim.machine.Machine; import net.mograsim.machine.MachineDefinition; +import net.mograsim.machine.MainMemory; +import net.mograsim.machine.MainMemoryDefinition; import net.mograsim.machine.mi.MicroInstructionMemory; import net.mograsim.machine.mi.MicroInstructionMemoryDefinition; import net.mograsim.machine.mi.MicroInstructionMemoryParser; +import net.mograsim.machine.standard.memory.MainMemoryParser; import net.mograsim.plugin.MograsimActivator; import net.mograsim.plugin.nature.MachineContext; import net.mograsim.plugin.nature.MograsimNature; @@ -35,6 +44,8 @@ public class MachineLaunchConfigType extends LaunchConfigurationDelegate public static final String INITIAL_RAM_FILE_ATTR = MograsimActivator.PLUGIN_ID + ".initialram"; private final IResourceChangeListener resChangedListener; + private IFile mpmFile; + private Machine machine; public MachineLaunchConfigType() { @@ -69,13 +80,14 @@ public class MachineLaunchConfigType extends LaunchConfigurationDelegate MachineDefinition machineDefinition = machDefOptional.orElseThrow(); MicroInstructionMemoryDefinition miMemDef = machineDefinition.getMicroInstructionMemoryDefinition(); + MainMemoryDefinition mainMemDef = machineDefinition.getMainMemoryDefinition(); String mpmFileName = configuration.getAttribute(MPM_FILE_ATTR, ""); if ("".equals(mpmFileName)) return showErrorAndReturnFalse("No MPM file specified"); IFile mpmFile = project.getFile(mpmFileName); - if (!mpmFile.isAccessible()) + if (mpmFile == null || !mpmFile.isAccessible()) return showErrorAndReturnFalse("MPM file not accessible"); try (InputStream mpmStream = mpmFile.getContents()) @@ -87,7 +99,23 @@ public class MachineLaunchConfigType extends LaunchConfigurationDelegate throw new CoreException(new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, "Unexpected IO exception reading MPM file", e)); } - // TODO parse RAM + String initialRAMFileName = configuration.getAttribute(INITIAL_RAM_FILE_ATTR, ""); + if (!"".equals(initialRAMFileName)) + { + IFile initialRAMFile = project.getFile(initialRAMFileName); + if (initialRAMFile == null || !initialRAMFile.isAccessible()) + return showErrorAndReturnFalse("Initial RAM file not accessible"); + + try (InputStream initialRAMStream = initialRAMFile.getContents()) + { + MainMemoryParser.parseMemory(mainMemDef, initialRAMStream); + } + catch (IOException e) + { + throw new CoreException( + new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, "Unexpected IO exception reading initial RAM file", e)); + } + } return super.preLaunchCheck(configuration, mode, monitor); } @@ -106,33 +134,54 @@ public class MachineLaunchConfigType extends LaunchConfigurationDelegate MachineContext machineContext = ProjectMachineContext.getMachineContextOf(project); MachineDefinition machineDefinition = machineContext.getMachineDefinition().orElseThrow(); - MicroInstructionMemoryDefinition miMemDef = machineDefinition.getMicroInstructionMemoryDefinition(); + MainMemoryDefinition mainMemDef = machineDefinition.getMainMemoryDefinition(); - IFile mpmFile = project.getFile(configuration.getAttribute(MPM_FILE_ATTR, "")); + mpmFile = project.getFile(configuration.getAttribute(MPM_FILE_ATTR, "")); + + String initialRAMFileName = configuration.getAttribute(INITIAL_RAM_FILE_ATTR, ""); + MainMemory mem; + if (!"".equals(initialRAMFileName)) + { + IFile initialRAMFile = project.getFile(initialRAMFileName); + try (InputStream initialRAMStream = initialRAMFile.getContents()) + { + mem = MainMemoryParser.parseMemory(mainMemDef, initialRAMStream); + } + catch (IOException e) + { + throw new CoreException( + new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, "Unexpected IO exception reading initial RAM file", e)); + } + } else + mem = null; + + MachineDebugTarget debugTarget = new MachineDebugTarget(launch, machineDefinition); + debugTarget.suspend(); + debugTarget.setExecutionSpeed(1); + machine = debugTarget.getMachine(); + assignMicroInstructionMemory(); + if (mem != null) + machine.getMainMemory().bind(mem); + machine.reset(); + } - MicroInstructionMemory mpm; + private void assignMicroInstructionMemory() throws CoreException + { try (InputStream mpmStream = mpmFile.getContents()) { - mpm = MicroInstructionMemoryParser.parseMemory(miMemDef, mpmStream); + MicroInstructionMemory mpm = MicroInstructionMemoryParser + .parseMemory(machine.getDefinition().getMicroInstructionMemoryDefinition(), mpmStream); + machine.getMicroInstructionMemory().bind(mpm); } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, "Unexpected IO exception reading MPM file", e)); } - - // TODO parse RAM - - MachineDebugTarget debugTarget = new MachineDebugTarget(new MachineProcess(launch, machineDefinition)); - debugTarget.setExecutionSpeed(1); - Machine machine = debugTarget.getMachine(); - machine.getMicroInstructionMemory().bind(mpm); - // TODO bind RAM - machine.reset(); } private void resourceChanged(IResourceChangeEvent event) { - // TODO react to MPM changes + // TODO remove Sysout int type = event.getType(); String typeStr; switch (type) @@ -142,6 +191,33 @@ public class MachineLaunchConfigType extends LaunchConfigurationDelegate break; case IResourceChangeEvent.POST_CHANGE: typeStr = "POST_CHANGE"; + IResourceDelta mpmDelta; + if ((mpmDelta = event.getDelta().findMember(mpmFile.getFullPath())) != null && (mpmDelta.getKind() & CHANGED) == CHANGED + && mpmFile.exists()) + { + AtomicBoolean doHotReplace = new AtomicBoolean(); + PlatformUI.getWorkbench().getDisplay().syncExec(() -> + { + 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()) + { + 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())); + } + } + } break; case IResourceChangeEvent.PRE_BUILD: typeStr = "PRE_BUILD";