X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Flaunch%2FMachineLaunchConfigType.java;h=286975a6f1d7109ee0655fb16e6bc07f2e199ed5;hb=23335a13dfcfb22119c5e0184fbcd8d9caac3551;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..286975a6 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 @@ -6,8 +6,6 @@ import java.util.Optional; 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.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -20,9 +18,10 @@ import org.eclipse.ui.statushandlers.StatusManager; import net.mograsim.machine.Machine; import net.mograsim.machine.MachineDefinition; -import net.mograsim.machine.mi.MicroInstructionMemory; +import net.mograsim.machine.MainMemoryDefinition; 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; @@ -34,20 +33,8 @@ public class MachineLaunchConfigType extends LaunchConfigurationDelegate 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; - - public MachineLaunchConfigType() - { - this.resChangedListener = this::resourceChanged; - ResourcesPlugin.getWorkspace().addResourceChangeListener(resChangedListener, - // IResourceChangeEvent.POST_BUILD | - IResourceChangeEvent.POST_CHANGE | - // IResourceChangeEvent.PRE_BUILD | - // IResourceChangeEvent.PRE_CLOSE | - // IResourceChangeEvent.PRE_DELETE | - // IResourceChangeEvent.PRE_REFRESH | - 0); - } + private IFile mpmFile; + private Machine machine; @Override public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException @@ -69,13 +56,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 +75,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,58 +110,21 @@ public class MachineLaunchConfigType extends LaunchConfigurationDelegate MachineContext machineContext = ProjectMachineContext.getMachineContextOf(project); MachineDefinition machineDefinition = machineContext.getMachineDefinition().orElseThrow(); - MicroInstructionMemoryDefinition miMemDef = machineDefinition.getMicroInstructionMemoryDefinition(); - IFile mpmFile = project.getFile(configuration.getAttribute(MPM_FILE_ATTR, "")); + mpmFile = project.getFile(configuration.getAttribute(MPM_FILE_ATTR, "")); - MicroInstructionMemory mpm; - try (InputStream mpmStream = mpmFile.getContents()) + String initialRAMFileName = configuration.getAttribute(INITIAL_RAM_FILE_ATTR, ""); + Optional memFile = Optional.empty(); + if (!"".equals(initialRAMFileName)) { - mpm = MicroInstructionMemoryParser.parseMemory(miMemDef, mpmStream); + memFile = Optional.of(project.getFile(initialRAMFileName)); } - 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)); + MachineDebugTarget debugTarget = new MachineDebugTarget(launch, mpmFile, memFile, machineDefinition); + // TODO make selectable whether the machine starts paused or not + debugTarget.suspend(); debugTarget.setExecutionSpeed(1); - Machine machine = debugTarget.getMachine(); - machine.getMicroInstructionMemory().bind(mpm); - // TODO bind RAM + machine = debugTarget.getMachine(); machine.reset(); } - private void resourceChanged(IResourceChangeEvent event) - { - // TODO react to MPM changes - int type = event.getType(); - String typeStr; - switch (type) - { - case IResourceChangeEvent.POST_BUILD: - typeStr = "POST_BUILD"; - break; - case IResourceChangeEvent.POST_CHANGE: - typeStr = "POST_CHANGE"; - break; - case IResourceChangeEvent.PRE_BUILD: - typeStr = "PRE_BUILD"; - break; - case IResourceChangeEvent.PRE_CLOSE: - typeStr = "PRE_CLOSE"; - break; - case IResourceChangeEvent.PRE_DELETE: - typeStr = "PRE_DELETE"; - break; - case IResourceChangeEvent.PRE_REFRESH: - typeStr = "PRE_REFRESH"; - break; - default: - typeStr = ""; - } - System.out.println(typeStr + ": " + event); - } } \ No newline at end of file