From d8d92dba4339e1240e4362046eadbe51c6740780 Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Sun, 29 Sep 2019 23:30:14 +0200 Subject: [PATCH] The user can now specify a RAM file (but doesn't have to) --- .../launch/MachineLaunchConfigType.java | 10 +++- .../launch/MainMachineLaunchConfigTab.java | 47 +++++++++++++++++-- 2 files changed, 52 insertions(+), 5 deletions(-) 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 32ea8325..e9b6531b 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 @@ -30,8 +30,9 @@ import net.mograsim.plugin.nature.ProjectMachineContext; public class MachineLaunchConfigType extends LaunchConfigurationDelegate { - public static final String PROJECT_ATTR = MograsimActivator.PLUGIN_ID + "project"; - public static final String MPM_FILE_ATTR = MograsimActivator.PLUGIN_ID + "mpm"; + public static final String PROJECT_ATTR = MograsimActivator.PLUGIN_ID + ".project"; + public static final String MPM_FILE_ATTR = MograsimActivator.PLUGIN_ID + ".mpm"; + public static final String INITIAL_RAM_FILE_ATTR = MograsimActivator.PLUGIN_ID + ".initialram"; private final IResourceChangeListener resChangedListener; @@ -86,6 +87,8 @@ 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 + return super.preLaunchCheck(configuration, mode, monitor); } @@ -117,10 +120,13 @@ 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 + MachineDebugTarget debugTarget = new MachineDebugTarget(new MachineProcess(launch, machineDefinition)); debugTarget.setExecutionSpeed(1); Machine machine = debugTarget.getMachine(); machine.getMicroInstructionMemory().bind(mpm); + // TODO bind RAM machine.reset(); } diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MainMachineLaunchConfigTab.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MainMachineLaunchConfigTab.java index 6f3c2937..7671827d 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MainMachineLaunchConfigTab.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MainMachineLaunchConfigTab.java @@ -43,6 +43,7 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab { private Text projSelText; private Text mpmFileSelText; + private Text initialRAMFileSelText; @Override public void createControl(Composite parent) @@ -57,7 +58,7 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab this.mpmFileSelText = createResourceSelectorGroup(innerParent, "&MPM:", this::chooseMPMFile); - // TODO RAM selector + this.initialRAMFileSelText = createResourceSelectorGroup(innerParent, "Initial &RAM (optional):", this::chooseInitialRAMFile); } private Text createResourceSelectorGroup(Composite innerParent, String groupName, Supplier chooser) @@ -122,6 +123,8 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab } }; ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), renderer, new WorkbenchContentProvider()); + dialog.setTitle("MPM Selection"); + dialog.setMessage("Select a MPM file"); dialog.setInput(getSelectedProject()); dialog.addFilter(new FileExtensionViewerFilter("mpm")); @@ -130,6 +133,27 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab return null; } + private String chooseInitialRAMFile() + { + WorkbenchLabelProvider renderer = new WorkbenchLabelProvider() + { + @Override + protected ImageDescriptor decorateImage(ImageDescriptor input, Object element) + { + return new ImageDescriptorWithMargins(input, new Point(22, 16)); + } + }; + ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), renderer, new WorkbenchContentProvider()); + dialog.setTitle("Initial RAM Selection"); + dialog.setMessage("Select a RAM file"); + dialog.setInput(getSelectedProject()); + dialog.addFilter(new FileExtensionViewerFilter("mem")); + + if (dialog.open() == Window.OK) + return ((IResource) dialog.getResult()[0]).getProjectRelativePath().toPortableString(); + return null; + } + private IProject getSelectedProject() { String projName = projSelText.getText().trim(); @@ -165,6 +189,7 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab { projSelText.setText(getStringAttribSafe(configuration, MachineLaunchConfigType.PROJECT_ATTR, "")); mpmFileSelText.setText(getStringAttribSafe(configuration, MachineLaunchConfigType.MPM_FILE_ATTR, "")); + initialRAMFileSelText.setText(getStringAttribSafe(configuration, MachineLaunchConfigType.INITIAL_RAM_FILE_ATTR, "")); } private String getStringAttribSafe(ILaunchConfiguration configuration, String attrib, String defaultValue) @@ -185,6 +210,7 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab { String projName = projSelText.getText().trim(); String mpmFileName = mpmFileSelText.getText().trim(); + String initialRAMFileName = initialRAMFileSelText.getText().trim(); Set associatedResources = new HashSet<>(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); @@ -195,11 +221,15 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab { if (project != null && project.isAccessible() && project.hasNature(MograsimNature.NATURE_ID)) { + associatedResources.add(project); + IResource mpmFile = project.findMember(mpmFileName); if (mpmFile != null && mpmFile.exists() && mpmFile.getType() == IResource.FILE) associatedResources.add(mpmFile); - else - associatedResources.add(project); + + IResource ramFile = project.findMember(initialRAMFileName); + if (ramFile != null && ramFile.exists() && ramFile.getType() == IResource.FILE) + associatedResources.add(ramFile); } } catch (CoreException e) @@ -210,6 +240,7 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab configuration.setMappedResources(associatedResources.toArray(IResource[]::new)); configuration.setAttribute(MachineLaunchConfigType.PROJECT_ATTR, projName); configuration.setAttribute(MachineLaunchConfigType.MPM_FILE_ATTR, mpmFileName); + configuration.setAttribute(MachineLaunchConfigType.INITIAL_RAM_FILE_ATTR, initialRAMFileName); } @Override @@ -250,6 +281,16 @@ public class MainMachineLaunchConfigTab extends AbstractLaunchConfigurationTab if (mpmResource.getType() != IResource.FILE) return setErrorAndReturnFalse("MPM file {0} is not a file", mpmFileName); + String initialRAMFileName = initialRAMFileSelText.getText().trim(); + if (initialRAMFileName.length() > 0) + { + IResource initialRAMResource = project.findMember(initialRAMFileName); + if (initialRAMResource == null || !initialRAMResource.exists()) + return setErrorAndReturnFalse("Initial RAM file {0} does not exist", initialRAMFileName); + if (initialRAMResource.getType() != IResource.FILE) + return setErrorAndReturnFalse("Initial RAM file {0} is not a file", initialRAMFileName); + } + return true; } -- 2.17.1