+
+ 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())
+ {
+ 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()));
+ }
+ }
+ }
+ }
+
+ private void assignMicroInstructionMemory() throws CoreException
+ {
+ try (InputStream mpmStream = mpmFile.getContents())
+ {
+ machine.getMicroInstructionMemory().bind(
+ MicroInstructionMemoryParser.parseMemory(machine.getDefinition().getMicroInstructionMemoryDefinition(), mpmStream));
+ }
+ catch (IOException e)
+ {
+ throw new CoreException(new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, "Unexpected IO exception reading MPM file", e));
+ }
+ }
+
+ private void assignMainMemory() throws CoreException
+ {
+ if (memFile.isPresent())
+ {
+ try (InputStream initialRAMStream = memFile.get().getContents())
+ {
+ machine.getMainMemory()
+ .bind(MainMemoryParser.parseMemory(machine.getDefinition().getMainMemoryDefinition(), initialRAMStream));
+ }
+ catch (IOException e)
+ {
+ throw new CoreException(
+ new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, "Unexpected IO exception reading initial RAM file", e));
+ }
+ }
+ }
+
+ public IFile getMPMFile()
+ {
+ return mpmFile;
+ }
+
+ public Optional<IFile> getMEMFile()
+ {
+ return memFile;
+ }