From: Fabian Stemmler Date: Sat, 7 Sep 2019 14:06:16 +0000 (+0200) Subject: Added address column to instruction editor X-Git-Url: https://mograsim.net/gitweb/?p=Mograsim.git;a=commitdiff_plain;h=a8ba08b067b7c5e449656fca56ac067d5d701270 Added address column to instruction editor --- diff --git a/net.mograsim.plugin.core/META-INF/MANIFEST.MF b/net.mograsim.plugin.core/META-INF/MANIFEST.MF index 5b256d0f..6dfa9547 100644 --- a/net.mograsim.plugin.core/META-INF/MANIFEST.MF +++ b/net.mograsim.plugin.core/META-INF/MANIFEST.MF @@ -27,7 +27,8 @@ Require-Bundle: org.eclipse.core.runtime, net.mograsim.logic.model.am2900;bundle-version="0.1.0";visibility:=reexport, javax.annotation;bundle-version="1.0.0", net.mograsim.preferences;bundle-version="0.1.0", - net.mograsim.machine + net.mograsim.machine, + net.mograsim.plugin.core Bundle-RequiredExecutionEnvironment: JavaSE-11 Automatic-Module-Name: net.mograsim.plugin.core Bundle-Vendor: %Bundle-Vendor.0 diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/AddressLabelProvider.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/AddressLabelProvider.java new file mode 100644 index 00000000..c94e440a --- /dev/null +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/AddressLabelProvider.java @@ -0,0 +1,19 @@ +package net.mograsim.plugin.tables; + +import java.math.BigInteger; + +import org.eclipse.jface.viewers.ColumnLabelProvider; + +import net.mograsim.plugin.asm.AsmNumberUtil; +import net.mograsim.plugin.asm.AsmNumberUtil.NumberType; + +public class AddressLabelProvider extends ColumnLabelProvider +{ + @Override + public String getText(Object element) + { + @SuppressWarnings("rawtypes") + TableRow row = (TableRow) element; + return AsmNumberUtil.toString(BigInteger.valueOf(row.address), NumberType.HEXADECIMAL); + } +} diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/TableRow.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/TableRow.java new file mode 100644 index 00000000..46b7c5c3 --- /dev/null +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/TableRow.java @@ -0,0 +1,23 @@ +package net.mograsim.plugin.tables; + +public class TableRow +{ + public final T data; + public final long address; + + public TableRow(long address, T data) + { + this.data = data; + this.address = address; + } + + public T getData() + { + return data; + } + + public long getAddress() + { + return address; + } +} diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryTableRow.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryTableRow.java index 6f1c3530..81ee6e65 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryTableRow.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryTableRow.java @@ -1,20 +1,17 @@ package net.mograsim.plugin.tables.memory; import net.mograsim.machine.MainMemory; +import net.mograsim.plugin.tables.TableRow; -public class MemoryTableRow +public class MemoryTableRow extends TableRow { - public final long address; - private final MainMemory memory; - public MemoryTableRow(long address, MainMemory memory) { - this.address = address; - this.memory = memory; + super(address, memory); } public MainMemory getMemory() { - return memory; + return getData(); } -} +} \ No newline at end of file diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryView.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryView.java index ef685f4c..3227e9fb 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryView.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryView.java @@ -3,7 +3,6 @@ package net.mograsim.plugin.tables.memory; import java.math.BigInteger; import java.util.Optional; -import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.swt.SWT; @@ -24,6 +23,7 @@ import net.mograsim.machine.standard.memory.WordAddressableMemory; import net.mograsim.plugin.MachineContext; import net.mograsim.plugin.MachineContext.ContextObserver; import net.mograsim.plugin.asm.AsmNumberUtil; +import net.mograsim.plugin.tables.AddressLabelProvider; import net.mograsim.plugin.tables.DisplaySettings; import net.mograsim.plugin.tables.NumberColumnLabelProvider; import net.mograsim.plugin.tables.RadixSelector; @@ -33,7 +33,6 @@ public class MemoryView extends ViewPart implements ContextObserver private TableViewer viewer; private MemoryTableContentProvider provider; private DisplaySettings displaySettings; - private String addressFormat; @Override public void createPartControl(Composite parent) @@ -123,15 +122,7 @@ public class MemoryView extends ViewPart implements ContextObserver int[] bounds = { 100, 100 }; TableViewerColumn col = createTableViewerColumn(titles[0], bounds[0]); - col.setLabelProvider(new ColumnLabelProvider() - { - @Override - public String getText(Object element) - { - MemoryTableRow row = (MemoryTableRow) element; - return String.format(addressFormat, row.address); - } - }); + col.setLabelProvider(new AddressLabelProvider()); col = createTableViewerColumn(titles[1], bounds[1]); col.setLabelProvider(new NumberColumnLabelProvider(displaySettings) @@ -166,8 +157,6 @@ public class MemoryView extends ViewPart implements ContextObserver private void bindMainMemory(MainMemory m) { - int hexAddressLength = Long.toUnsignedString(m.getDefinition().getMaximalAddress(), 16).length(); - addressFormat = "0x%0" + hexAddressLength + "X"; viewer.setInput(m); } diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/BooleanEditingSupport.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/BooleanEditingSupport.java index 813857d9..c3318b58 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/BooleanEditingSupport.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/BooleanEditingSupport.java @@ -6,7 +6,6 @@ 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; @@ -41,13 +40,13 @@ public class BooleanEditingSupport extends EditingSupport @Override protected Object getValue(Object element) { - return ((MicroInstruction) element).getParameter(index).getValue().getMSBit(0).equals(Bit.ONE); + return ((InstructionTableRow) element).data.getParameter(index).getValue().getMSBit(0).equals(Bit.ONE); } @Override protected void setValue(Object element, Object value) { - ((MicroInstruction) element).setParameter(index, boolClass.get((Boolean) value)); + ((InstructionTableRow) element).data.setParameter(index, boolClass.get((Boolean) value)); viewer.update(element, null); } diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTableContentProvider.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTableContentProvider.java index 605e26d4..ddca5787 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTableContentProvider.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTableContentProvider.java @@ -14,7 +14,8 @@ public class InstructionTableContentProvider implements ILazyContentProvider @Override public void updateElement(int index) { - viewer.replace(memory.getCell(index), index); + long address = memory.getDefinition().getMinimalAddress() + index; + viewer.replace(new InstructionTableRow(address, memory.getCell(address)), index); } @Override diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTableRow.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTableRow.java new file mode 100644 index 00000000..677d1668 --- /dev/null +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionTableRow.java @@ -0,0 +1,12 @@ +package net.mograsim.plugin.tables.mi; + +import net.mograsim.machine.mi.MicroInstruction; +import net.mograsim.plugin.tables.TableRow; + +public class InstructionTableRow extends TableRow +{ + public InstructionTableRow(long address, MicroInstruction data) + { + super(address, data); + } +} diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java index 931d1a60..f0db46fe 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/InstructionView.java @@ -26,6 +26,7 @@ import net.mograsim.machine.mi.parameters.ParameterClassification; import net.mograsim.plugin.MachineContext; import net.mograsim.plugin.MachineContext.ContextObserver; import net.mograsim.plugin.asm.AsmNumberUtil.NumberType; +import net.mograsim.plugin.tables.AddressLabelProvider; import net.mograsim.plugin.tables.DisplaySettings; import net.mograsim.plugin.tables.RadixSelector; import net.mograsim.plugin.util.DropDownMenu; @@ -119,6 +120,9 @@ public class InstructionView extends ViewPart implements ContextObserver private void createColumns() { + TableViewerColumn col = createTableViewerColumn("Address", 200); + col.setLabelProvider(new AddressLabelProvider()); + int size = miDef.size(); int bit = 0; columns = new TableViewerColumn[size]; @@ -131,8 +135,7 @@ public class InstructionView extends ViewPart implements ContextObserver String name = startBit == endBit ? Integer.toString(startBit) : startBit + "..." + endBit; int bounds = 20 + 20 * classes[i].getExpectedBits(); - TableViewerColumn col = createTableViewerColumn(name, bounds); - createEditingAndLabel(col, miDef, i); + createEditingAndLabel(createTableViewerColumn(name, bounds), miDef, i); } } diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerColumnLabelProvider.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerColumnLabelProvider.java index 4455f4a0..ce61581f 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerColumnLabelProvider.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerColumnLabelProvider.java @@ -2,7 +2,6 @@ package net.mograsim.plugin.tables.mi; import java.math.BigInteger; -import net.mograsim.machine.mi.MicroInstruction; import net.mograsim.machine.mi.parameters.IntegerImmediate; import net.mograsim.plugin.tables.DisplaySettings; import net.mograsim.plugin.tables.NumberColumnLabelProvider; @@ -20,7 +19,7 @@ public class IntegerColumnLabelProvider extends NumberColumnLabelProvider @Override public BigInteger getAsBigInteger(Object element) { - return ((IntegerImmediate) ((MicroInstruction) element).getParameter(index)).getValueAsBigInteger(); + return ((IntegerImmediate) ((InstructionTableRow) element).data.getParameter(index)).getValueAsBigInteger(); } } diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java index db86ab07..0a7ad281 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java @@ -4,7 +4,6 @@ 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; @@ -26,13 +25,13 @@ public class IntegerEditingSupport extends NumberCellEditingSupport @Override protected void setAsBigInteger(Object element, BigInteger value) { - ((MicroInstruction) element).setParameter(index, new IntegerImmediate(value, classification.getExpectedBits())); + ((InstructionTableRow) element).data.setParameter(index, new IntegerImmediate(value, classification.getExpectedBits())); } @Override protected BigInteger getAsBigInteger(Object element) { - return ((IntegerImmediate) ((MicroInstruction) element).getParameter(index)).getValueAsBigInteger(); + return ((IntegerImmediate) ((InstructionTableRow) element).data.getParameter(index)).getValueAsBigInteger(); } } diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/MnemonicEditingSupport.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/MnemonicEditingSupport.java index 9530c209..910fefa5 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/MnemonicEditingSupport.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/MnemonicEditingSupport.java @@ -6,7 +6,6 @@ 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.Mnemonic; import net.mograsim.machine.mi.parameters.MnemonicFamily; @@ -43,13 +42,13 @@ public class MnemonicEditingSupport extends EditingSupport @Override protected Object getValue(Object element) { - return ((Mnemonic) ((MicroInstruction) element).getParameter(index)).ordinal(); + return ((Mnemonic) ((InstructionTableRow) element).data.getParameter(index)).ordinal(); } @Override protected void setValue(Object element, Object value) { - ((MicroInstruction) element).setParameter(index, family.get((Integer) value)); + ((InstructionTableRow) element).data.setParameter(index, family.get((Integer) value)); viewer.update(element, null); } diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ParameterLabelProvider.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ParameterLabelProvider.java index b4acd155..5e06370a 100644 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ParameterLabelProvider.java +++ b/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/ParameterLabelProvider.java @@ -2,8 +2,6 @@ package net.mograsim.plugin.tables.mi; import org.eclipse.jface.viewers.ColumnLabelProvider; -import net.mograsim.machine.mi.MicroInstruction; - public class ParameterLabelProvider extends ColumnLabelProvider { private final int index; @@ -17,6 +15,6 @@ public class ParameterLabelProvider extends ColumnLabelProvider @Override public String getText(Object element) { - return ((MicroInstruction) element).getParameter(index).toString(); + return ((InstructionTableRow) element).data.getParameter(index).toString(); } }