+ @Override
+ public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException
+ {
+ String projName = configuration.getAttribute(PROJECT_ATTR, "");
+ if ("".equals(projName))
+ return showErrorAndReturnFalse("No project specified");
+
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projName);
+ if (!project.isAccessible())
+ return showErrorAndReturnFalse("Project not accessible");
+ if (!project.hasNature(MograsimNature.NATURE_ID))
+ return showErrorAndReturnFalse("Project is not a Mograsim project");
+
+ MachineContext machineContext = ProjectMachineContext.getMachineContextOf(project);
+ Optional<MachineDefinition> machDefOptional = machineContext.getMachineDefinition();
+ if (machDefOptional.isEmpty())
+ return showErrorAndReturnFalse("No machine definition set");
+
+ MachineDefinition machineDefinition = machDefOptional.orElseThrow();
+ MicroInstructionMemoryDefinition miMemDef = machineDefinition.getMicroInstructionMemoryDefinition();
+
+ String mpmFileName = configuration.getAttribute(MPM_FILE_ATTR, "");
+ if ("".equals(mpmFileName))
+ return showErrorAndReturnFalse("No MPM file specified");
+
+ IFile mpmFile = project.getFile(mpmFileName);
+ if (!mpmFile.isAccessible())
+ return showErrorAndReturnFalse("MPM file not accessible");
+
+ try (InputStream mpmStream = mpmFile.getContents())
+ {
+ MicroInstructionMemoryParser.parseMemory(miMemDef, mpmStream);
+ }
+ catch (IOException e)
+ {
+ throw new CoreException(new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, "Unexpected IO exception reading MPM file", e));
+ }
+
+ return super.preLaunchCheck(configuration, mode, monitor);
+ }
+
+ private static boolean showErrorAndReturnFalse(String message)
+ {
+ StatusManager.getManager().handle(new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, message, null), StatusManager.SHOW);
+ return false;
+ }
+