public MicroInstructionParameter getParameter(int index);
- public void setParameter(int index, MicroInstructionParameter param);
+ public MicroInstructionParameter[] getParameters();
/**
* @return The amount of {@link Mnemonic}s, the instruction is composed of
*/
public int getSize();
- public static MicroInstruction create(Runnable updateCallback, MicroInstructionParameter... parameters)
+ public static MicroInstruction create(MicroInstructionParameter... parameters)
{
- return new StandardMicroInstruction(updateCallback, parameters);
+ return new StandardMicroInstruction(parameters);
}
default BitVector toBitVector()
return Arrays.stream(getParameterClassifications()).mapToInt(e -> e.getExpectedBits()).reduce(0, (a, b) -> a + b);
}
- public default MicroInstruction createDefaultInstruction(Runnable updateCallback)
+ public default MicroInstruction createDefaultInstruction()
{
int size = size();
MicroInstructionParameter[] params = new MicroInstructionParameter[size];
ParameterClassification classification = classes[i];
params[i] = classification.getDefault();
}
- return new StandardMicroInstruction(updateCallback, params);
+ return new StandardMicroInstruction(params);
}
public Optional<String> getParameterDescription(int index);
public interface MicroInstructionMemory extends Memory<MicroInstruction>
{
+ @Override
public MicroInstructionMemoryDefinition getDefinition();
}
{
for (; i <= maxAddr && input.ready() && !"".equals((line = input.readLine())); i++)
{
- long iFinal = i;
- memory.setCell(i, parse(() -> memory.notifyObservers(iFinal), miDef, line));
+ memory.setCell(i, parse(miDef, line));
}
}
catch (IOException e)
for (; i <= maxAddr; i++)
{
- long iFinal = i;
- memory.setCell(i, miDef.createDefaultInstruction(() -> memory.notifyObservers(iFinal)));
+ memory.setCell(i, miDef.createDefaultInstruction());
}
}
- public static MicroInstruction parse(Runnable updateCallback, MicroInstructionDefinition definition, String toParse)
+ public static MicroInstruction parse(MicroInstructionDefinition definition, String toParse)
{
int size = definition.size();
String[] strings = toParse.split(",");
{
params[i] = classes[i].parse(strings[i]);
}
- return new StandardMicroInstruction(updateCallback, params);
+ return new StandardMicroInstruction(params);
}
catch (Exception e)
{
class StandardMicroInstruction implements MicroInstruction
{
- private final Runnable updateCallback;
private MicroInstructionParameter[] parameters;
- StandardMicroInstruction(Runnable updateCallback, MicroInstructionParameter... parameters)
+ StandardMicroInstruction(MicroInstructionParameter... parameters)
{
- this.updateCallback = updateCallback;
- this.parameters = parameters;
+ this.parameters = parameters.clone();
}
/**
return parameters.length;
}
- /**
- * @throws IndexOutOfBoundsException
- */
@Override
- public void setParameter(int index, MicroInstructionParameter param)
+ public MicroInstructionParameter[] getParameters()
{
- parameters[index] = param;
- updateCallback.run();
+ return parameters.clone();
}
}
int translatedAddress = translate(address);
MicroInstruction actual = data[translatedAddress];
if (actual == null)
- actual = data[translatedAddress] = definition.getMicroInstructionDefinition()
- .createDefaultInstruction(() -> notifyObservers(address));
+ actual = data[translatedAddress] = definition.getMicroInstructionDefinition().createDefaultInstruction();
return actual;
}
Bundle-Vendor = Mograsim Team
Bundle-Name = Mograsim core
content-type.name = Assembler
+content-type.mpm.name = Microprogram Memory
+editor.name.0 = Instruction Editor
category.name = Mograsim
view.name = Sample AsmOpsEdit
e4view.name = Simulation und Visualisierung
fontDefinition.label = Assembler Operation Style
view.name.0 = Simulation View
view.name.1 = Memory
-view.name.1 = Instruction Editor
themeElementCategory.label.0 = Simulation
Bundle-Vendor.0 = Mograsim Team
\ No newline at end of file
name="%content-type.name"
priority="high">
</content-type>
+ <content-type
+ base-type="org.eclipse.core.runtime.text"
+ default-charset="UTF-8"
+ file-extensions="mpm"
+ id="net.mograsim.plugin.mpm"
+ name="%content-type.mpm.name"
+ priority="high">
+ </content-type>
</extension>
<extension
point="org.eclipse.ui.editors">
contentTypeId="net.mograsim.plugin.asm"
editorId="org.eclipse.ui.genericeditor.GenericEditor">
</editorContentTypeBinding>
+ <editorContentTypeBinding
+ contentTypeId="net.mograsim.plugin.mpm"
+ editorId="net.mograsim.plugin.tables.mi.InstructionView">
+ </editorContentTypeBinding>
+ <editor
+ name="%view.name.2"
+ icon="icons/mograsim/blue-orange/icon_blue-orange_7x8.png"
+ class="net.mograsim.plugin.tables.mi.InstructionView"
+ id="net.mograsim.plugin.tables.mi.InstructionView">
+ </editor>
</extension>
<extension
point="org.eclipse.ui.genericeditor.presentationReconcilers">
import org.eclipse.jface.viewers.TableViewer;
import net.mograsim.logic.core.types.Bit;
+import net.mograsim.machine.mi.MicroInstruction;
import net.mograsim.machine.mi.MicroInstructionDefinition;
import net.mograsim.machine.mi.parameters.BooleanClassification;
+import net.mograsim.machine.mi.parameters.MicroInstructionParameter;
public class BooleanEditingSupport extends EditingSupport
{
@Override
protected Object getValue(Object element)
{
- return ((InstructionTableRow) element).data.getParameter(index).getValue().getMSBit(0).equals(Bit.ONE);
+ InstructionTableRow row = (InstructionTableRow) element;
+ return row.data.getCell(row.address).getParameter(index).getValue().getMSBit(0).equals(Bit.ONE);
}
@Override
protected void setValue(Object element, Object value)
{
- ((InstructionTableRow) element).data.setParameter(index, boolClass.get((Boolean) value));
+ InstructionTableRow row = (InstructionTableRow) element;
+ MicroInstructionParameter[] params = row.data.getCell(row.address).getParameters();
+ params[index] = boolClass.get((Boolean) value);
+ row.data.setCell(row.address, MicroInstruction.create(params));
viewer.update(element, null);
}
public void updateElement(int index)
{
long address = memory.getDefinition().getMinimalAddress() + index;
- viewer.replace(new InstructionTableRow(address, memory.getCell(address)), index);
+ viewer.replace(new InstructionTableRow(address, memory), index);
}
@Override
package net.mograsim.plugin.tables.mi;
-import net.mograsim.machine.mi.MicroInstruction;
+import net.mograsim.machine.mi.MicroInstructionMemory;
import net.mograsim.plugin.tables.TableRow;
-public class InstructionTableRow extends TableRow<MicroInstruction>
+public class InstructionTableRow extends TableRow<MicroInstructionMemory>
{
- public InstructionTableRow(long address, MicroInstruction data)
+ public InstructionTableRow(long address, MicroInstructionMemory data)
{
super(address, data);
}
import java.util.Arrays;
import java.util.Optional;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.ui.part.ViewPart;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IPathEditorInput;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.EditorPart;
import net.mograsim.machine.Machine;
+import net.mograsim.machine.MemoryObserver;
import net.mograsim.machine.mi.MicroInstructionDefinition;
import net.mograsim.machine.mi.MicroInstructionMemory;
import net.mograsim.machine.mi.MicroInstructionMemoryParseException;
import net.mograsim.plugin.util.DropDownMenu;
import net.mograsim.plugin.util.DropDownMenu.DropDownEntry;
-public class InstructionView extends ViewPart implements ContextObserver
+public class InstructionView extends EditorPart implements ContextObserver, MemoryObserver
{
private String saveLoc = null;
private LazyTableViewer viewer;
private DisplaySettings displaySettings;
private InstructionTableContentProvider provider;
private int highlighted = 0;
+ private boolean dirty = false;
@SuppressWarnings("unused")
@Override
this.memory = memory;
viewer.setInput(memory);
this.miDef = memory.getDefinition().getMicroInstructionDefinition();
+ this.memory.registerObserver(this);
createColumns();
}
if (memory == null)
{
System.err.println("Failed to write MicroprogrammingMemory to File. No MicroprogrammingMemory assigned.");
+ return;
}
- if (saveLoc != null)
+ try
{
- try
- {
- MicroInstructionMemoryParser.write(memory, file);
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
+ MicroInstructionMemoryParser.write(memory, file);
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
}
}
bindMicroInstructionMemory(actualMachine.getMicroInstructionMemory());
}
}
+
+ @Override
+ public void doSave(IProgressMonitor progressMonitor)
+ {
+ IEditorInput input = getEditorInput();
+ if (input instanceof IPathEditorInput)
+ {
+ IPathEditorInput pathInput = (IPathEditorInput) input;
+ save(pathInput.getPath().toOSString());
+ dirty = false;
+ firePropertyChange(PROP_DIRTY);
+ }
+ }
+
+ @Override
+ public void doSaveAs()
+ {
+ // not allowed
+ }
+
+ @Override
+ public void init(IEditorSite site, IEditorInput input) throws PartInitException
+ {
+ setSite(site);
+ setInput(input);
+ if (input instanceof IPathEditorInput)
+ {
+ IPathEditorInput pathInput = (IPathEditorInput) input;
+ open(pathInput.getPath().toOSString());
+ }
+ }
+
+ @Override
+ public boolean isDirty()
+ {
+ return dirty;
+ }
+
+ @Override
+ public boolean isSaveAsAllowed()
+ {
+ return false;
+ }
+
+ @Override
+ public void update(long address)
+ {
+ dirty = true;
+ firePropertyChange(PROP_DIRTY);
+ }
}
@Override
public BigInteger getAsBigInteger(Object element)
{
- return ((IntegerImmediate) ((InstructionTableRow) element).data.getParameter(index)).getValueAsBigInteger();
+ InstructionTableRow row = (InstructionTableRow) element;
+ return ((IntegerImmediate) row.data.getCell(row.address).getParameter(index)).getValueAsBigInteger();
}
}
import org.eclipse.jface.viewers.TableViewer;
+import net.mograsim.machine.mi.MicroInstruction;
import net.mograsim.machine.mi.MicroInstructionDefinition;
import net.mograsim.machine.mi.parameters.IntegerClassification;
import net.mograsim.machine.mi.parameters.IntegerImmediate;
+import net.mograsim.machine.mi.parameters.MicroInstructionParameter;
import net.mograsim.plugin.tables.DisplaySettings;
import net.mograsim.plugin.tables.NumberCellEditingSupport;
protected void setAsBigInteger(Object element, BigInteger value)
{
InstructionTableRow row = ((InstructionTableRow) element);
- row.data.setParameter(index, new IntegerImmediate(value, classification.getExpectedBits()));
+ MicroInstructionParameter[] params = row.data.getCell(row.address).getParameters();
+ params[index] = new IntegerImmediate(value, classification.getExpectedBits());
+ row.data.setCell(row.address, MicroInstruction.create(params));
provider.update(row.address);
// viewer.update(element, null); Does not do anything for some reason
}
@Override
protected BigInteger getAsBigInteger(Object element)
{
- return ((IntegerImmediate) ((InstructionTableRow) element).data.getParameter(index)).getValueAsBigInteger();
+ InstructionTableRow row = ((InstructionTableRow) element);
+ return ((IntegerImmediate) row.data.getCell(row.address).getParameter(index)).getValueAsBigInteger();
}
}
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
+import net.mograsim.machine.mi.MicroInstruction;
import net.mograsim.machine.mi.MicroInstructionDefinition;
+import net.mograsim.machine.mi.parameters.MicroInstructionParameter;
import net.mograsim.machine.mi.parameters.Mnemonic;
import net.mograsim.machine.mi.parameters.MnemonicFamily;
@Override
protected Object getValue(Object element)
{
- return ((Mnemonic) ((InstructionTableRow) element).data.getParameter(index)).ordinal();
+ InstructionTableRow row = ((InstructionTableRow) element);
+ return ((Mnemonic) row.data.getCell(row.address).getParameter(index)).ordinal();
}
@Override
protected void setValue(Object element, Object value)
{
InstructionTableRow row = ((InstructionTableRow) element);
- row.data.setParameter(index, family.get((Integer) value));
+ MicroInstructionParameter[] params = row.data.getCell(row.address).getParameters();
+ params[index] = family.get((Integer) value);
+ row.data.setCell(row.address, MicroInstruction.create(params));
provider.update(row.address);
}
@Override
public String getText(Object element)
{
- return ((InstructionTableRow) element).data.getParameter(index).toString();
+ InstructionTableRow row = (InstructionTableRow) element;
+ return row.data.getCell(row.address).getParameter(index).toString();
}
}