Numbers in MemoryView and mpm editor now have leading zeros
authorFabian Stemmler <stemmler@in.tum.de>
Tue, 24 Sep 2019 18:18:19 +0000 (20:18 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Tue, 24 Sep 2019 18:18:19 +0000 (20:18 +0200)
plugins/net.mograsim.machine/src/net/mograsim/machine/MainMemory.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/asm/AsmNumberUtil.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberCellEditingSupport.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberColumnLabelProvider.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryCellEditingSupport.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryView.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

index 909113c..33ad260 100644 (file)
@@ -9,4 +9,7 @@ public interface MainMemory extends Memory<BitVector>
        public BigInteger getCellAsBigInteger(long address);
 
        public void setCellAsBigInteger(long address, BigInteger word);
+
+       @Override
+       public MainMemoryDefinition getDefinition();
 }
\ No newline at end of file
index 580c324..38323fa 100644 (file)
@@ -172,6 +172,14 @@ public final class AsmNumberUtil
         * Formats a {@link BigInteger} in accordance with the pattern associated with the supplied {@link NumberType}
         */
        public static String toString(BigInteger number, NumberType type)
+       {
+               return toString(number, type, 0);
+       }
+
+       /**
+        * Formats a {@link BigInteger} in accordance with the pattern associated with the supplied {@link NumberType}
+        */
+       public static String toString(BigInteger number, NumberType type, int minBits)
        {
                String pattern;
                switch (type)
@@ -189,9 +197,36 @@ public final class AsmNumberUtil
                case HEXADECIMAL:
                        pattern = preferredHexPat;
                }
+
+               int digits;
+
+               switch (type.radix)
+               {
+               case 2:
+                       digits = minBits;
+                       break;
+               case 8:
+                       digits = minBits / 3;
+                       break;
+               case 16:
+                       digits = minBits / 4;
+                       break;
+               default:
+                       digits = 0;
+               }
+
+               String numberString, sign;
                if (number.signum() < 0)
-                       return String.format(pattern, "-", number.abs().toString(type.radix));
-               return String.format(pattern, "", number.toString(type.radix));
+               {
+                       sign = "-";
+                       numberString = number.abs().toString(type.radix);
+               } else
+               {
+                       sign = "";
+                       numberString = number.toString(type.radix);
+               }
+               numberString = "0".repeat(Integer.max(0, digits - numberString.length())) + numberString;
+               return String.format(pattern, sign, numberString);
        }
 
        public enum NumberType
index a1d8107..b28c5b9 100644 (file)
@@ -39,7 +39,7 @@ public abstract class NumberCellEditingSupport extends EditingSupport
        @Override
        final protected Object getValue(Object element)
        {
-               return AsmNumberUtil.toString(getAsBigInteger(element), displaySettings.getDataNumberType());
+               return AsmNumberUtil.toString(getAsBigInteger(element), displaySettings.getDataNumberType(), getBitLength(element));
        }
 
        @Override
@@ -59,4 +59,6 @@ public abstract class NumberCellEditingSupport extends EditingSupport
        protected abstract void setAsBigInteger(Object element, BigInteger value);
 
        protected abstract BigInteger getAsBigInteger(Object element);
+
+       protected abstract int getBitLength(Object element);
 }
index 6ee2c2b..a6e84e7 100644 (file)
@@ -8,7 +8,7 @@ import net.mograsim.plugin.asm.AsmNumberUtil;
 
 public abstract class NumberColumnLabelProvider extends ColumnLabelProvider
 {
-       private DisplaySettings displaySettings;
+       private final DisplaySettings displaySettings;
 
        public NumberColumnLabelProvider(DisplaySettings displaySettings)
        {
@@ -18,8 +18,10 @@ public abstract class NumberColumnLabelProvider extends ColumnLabelProvider
        @Override
        public String getText(Object element)
        {
-               return AsmNumberUtil.toString(getAsBigInteger(element), displaySettings.getDataNumberType());
+               return AsmNumberUtil.toString(getAsBigInteger(element), displaySettings.getDataNumberType(), getBitLength(element));
        }
 
        public abstract BigInteger getAsBigInteger(Object element);
+
+       public abstract int getBitLength(Object element);
 }
\ No newline at end of file
index 46eefcd..deaabe2 100644 (file)
@@ -27,4 +27,10 @@ public class MemoryCellEditingSupport extends NumberCellEditingSupport
                MemoryTableRow row = (MemoryTableRow) element;
                return row.getMemory().getCellAsBigInteger(row.address);
        }
+
+       @Override
+       public int getBitLength(Object element)
+       {
+               return ((MemoryTableRow) element).getMemory().getDefinition().getCellWidth();
+       }
 }
\ No newline at end of file
index 0936880..e490bd0 100644 (file)
@@ -134,6 +134,12 @@ public class MemoryView extends ViewPart implements ContextObserver
                                return row.getMemory().getCellAsBigInteger(row.address);
                        }
 
+                       @Override
+                       public int getBitLength(Object element)
+                       {
+                               return ((MemoryTableRow) element).getMemory().getDefinition().getCellWidth();
+                       }
+
                });
                col.setEditingSupport(new MemoryCellEditingSupport(viewer, displaySettings));
        }
index 7134de1..a2d5087 100644 (file)
@@ -23,4 +23,11 @@ public class IntegerColumnLabelProvider extends NumberColumnLabelProvider
                return ((IntegerImmediate) row.data.getCell(row.address).getParameter(index)).getValueAsBigInteger();
        }
 
+       @Override
+       public int getBitLength(Object element)
+       {
+               return ((InstructionTableRow) element).getData().getDefinition().getMicroInstructionDefinition().getParameterClassification(index)
+                               .getExpectedBits();
+       }
+
 }
index a821a76..365c6e1 100644 (file)
@@ -48,4 +48,11 @@ public class IntegerEditingSupport extends NumberCellEditingSupport
                return ((IntegerImmediate) row.data.getCell(row.address).getParameter(index)).getValueAsBigInteger();
        }
 
+       @Override
+       public int getBitLength(Object element)
+       {
+               return ((InstructionTableRow) element).getData().getDefinition().getMicroInstructionDefinition().getParameterClassification(index)
+                               .getExpectedBits();
+       }
+
 }