Merge branch 'development' of https://gitlab.lrz.de/lrr-tum/students/eragp-misim...
authorFabian Stemmler <stemmler@in.tum.de>
Mon, 16 Sep 2019 15:56:03 +0000 (17:56 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Mon, 16 Sep 2019 15:56:03 +0000 (17:56 +0200)
16 files changed:
plugins/net.mograsim.machine/src/net/mograsim/machine/mi/MicroInstruction.java
plugins/net.mograsim.machine/src/net/mograsim/machine/mi/MicroInstructionDefinition.java
plugins/net.mograsim.machine/src/net/mograsim/machine/mi/MicroInstructionMemory.java
plugins/net.mograsim.machine/src/net/mograsim/machine/mi/MicroInstructionMemoryParser.java
plugins/net.mograsim.machine/src/net/mograsim/machine/mi/StandardMicroInstruction.java
plugins/net.mograsim.machine/src/net/mograsim/machine/mi/StandardMicroInstructionMemory.java
plugins/net.mograsim.plugin.core/OSGI-INF/l10n/bundle.properties
plugins/net.mograsim.plugin.core/plugin.xml
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/BooleanEditingSupport.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTableContentProvider.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTableRow.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerColumnLabelProvider.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/MnemonicEditingSupport.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ParameterLabelProvider.java

index d45c277..28f8800 100644 (file)
@@ -9,16 +9,16 @@ public interface MicroInstruction
 
        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()
index 6625fa6..e5e3448 100644 (file)
@@ -35,7 +35,7 @@ public interface MicroInstructionDefinition
                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];
@@ -45,7 +45,7 @@ public interface MicroInstructionDefinition
                        ParameterClassification classification = classes[i];
                        params[i] = classification.getDefault();
                }
-               return new StandardMicroInstruction(updateCallback, params);
+               return new StandardMicroInstruction(params);
        }
 
        public Optional<String> getParameterDescription(int index);
index 5d4fac6..6409f78 100644 (file)
@@ -4,5 +4,6 @@ import net.mograsim.machine.Memory;
 
 public interface MicroInstructionMemory extends Memory<MicroInstruction>
 {
+       @Override
        public MicroInstructionMemoryDefinition getDefinition();
 }
index d049e37..1aa518d 100644 (file)
@@ -35,8 +35,7 @@ public class MicroInstructionMemoryParser
                {
                        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)
@@ -46,12 +45,11 @@ public class MicroInstructionMemoryParser
 
                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(",");
@@ -65,7 +63,7 @@ public class MicroInstructionMemoryParser
                        {
                                params[i] = classes[i].parse(strings[i]);
                        }
-                       return new StandardMicroInstruction(updateCallback, params);
+                       return new StandardMicroInstruction(params);
                }
                catch (Exception e)
                {
index c565432..00acd1a 100644 (file)
@@ -4,13 +4,11 @@ import net.mograsim.machine.mi.parameters.MicroInstructionParameter;
 
 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();
        }
 
        /**
@@ -28,14 +26,10 @@ class StandardMicroInstruction implements MicroInstruction
                return parameters.length;
        }
 
-       /**
-        * @throws IndexOutOfBoundsException
-        */
        @Override
-       public void setParameter(int index, MicroInstructionParameter param)
+       public MicroInstructionParameter[] getParameters()
        {
-               parameters[index] = param;
-               updateCallback.run();
+               return parameters.clone();
        }
 
 }
index 519c9b3..7ef53d9 100644 (file)
@@ -30,8 +30,7 @@ public class StandardMicroInstructionMemory implements MicroInstructionMemory
                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;
        }
 
index 856144a..26d588f 100644 (file)
@@ -2,6 +2,8 @@
 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
@@ -30,6 +32,5 @@ colorDefinition.label.10 = Simulation text color
 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
index 87e1ede..cb94fb0 100644 (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">
index c3318b5..fa7a918 100644 (file)
@@ -6,8 +6,10 @@ import org.eclipse.jface.viewers.EditingSupport;
 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
 {
@@ -40,13 +42,17 @@ 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);
        }
 
index b8021b7..6519b62 100644 (file)
@@ -16,7 +16,7 @@ public class InstructionTableContentProvider implements ILazyContentProvider
        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
index 677d166..7cef835 100644 (file)
@@ -1,11 +1,11 @@
 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);
        }
index 5867656..b14e42d 100644 (file)
@@ -5,6 +5,7 @@ import java.io.IOException;
 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;
@@ -15,9 +16,14 @@ import org.eclipse.swt.widgets.Composite;
 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;
@@ -33,7 +39,7 @@ import net.mograsim.plugin.tables.RadixSelector;
 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;
@@ -43,6 +49,7 @@ public class InstructionView extends ViewPart implements ContextObserver
        private DisplaySettings displaySettings;
        private InstructionTableContentProvider provider;
        private int highlighted = 0;
+       private boolean dirty = false;
 
        @SuppressWarnings("unused")
        @Override
@@ -122,6 +129,7 @@ public class InstructionView extends ViewPart implements ContextObserver
                this.memory = memory;
                viewer.setInput(memory);
                this.miDef = memory.getDefinition().getMicroInstructionDefinition();
+               this.memory.registerObserver(this);
                createColumns();
        }
 
@@ -250,17 +258,15 @@ public class InstructionView extends ViewPart implements ContextObserver
                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();
                }
        }
 
@@ -279,4 +285,54 @@ public class InstructionView extends ViewPart implements ContextObserver
                        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);
+       }
 }
index ce61581..7134de1 100644 (file)
@@ -19,7 +19,8 @@ public class IntegerColumnLabelProvider extends NumberColumnLabelProvider
        @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();
        }
 
 }
index d3b48ce..4f5b616 100644 (file)
@@ -4,9 +4,11 @@ import java.math.BigInteger;
 
 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;
 
@@ -29,7 +31,9 @@ public class IntegerEditingSupport extends 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
        }
@@ -37,7 +41,8 @@ public class IntegerEditingSupport extends NumberCellEditingSupport
        @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();
        }
 
 }
index 765e434..1140e68 100644 (file)
@@ -6,7 +6,9 @@ import org.eclipse.jface.viewers.EditingSupport;
 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;
 
@@ -43,14 +45,17 @@ public class MnemonicEditingSupport extends EditingSupport
        @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);
        }
 
index 5e06370..46e3ea7 100644 (file)
@@ -15,6 +15,7 @@ public class ParameterLabelProvider extends ColumnLabelProvider
        @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();
        }
 }