From: Daniel Kirschten Date: Fri, 15 Nov 2019 00:16:14 +0000 (+0100) Subject: Changed mnemonic X to use BitVector X; added X for integer immediates X-Git-Url: https://mograsim.net/gitweb/?p=Mograsim.git;a=commitdiff_plain;h=dfc725abca213bdd76fc97fdeb3310f095131f95 Changed mnemonic X to use BitVector X; added X for integer immediates --- diff --git a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MicroInstructionDefinition.java b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MicroInstructionDefinition.java index 2877b7e0..28f4deff 100644 --- a/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MicroInstructionDefinition.java +++ b/plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MicroInstructionDefinition.java @@ -24,7 +24,7 @@ public class Am2900MicroInstructionDefinition implements MicroInstructionDefinit .add("ADD", "SUBR", "SUBS", "OR", "AND", "NOTRS", "EXOR", "EXNOR").build(); private static final MnemonicFamily am2901DestInstructions = new MnemonicFamilyBuilder(3).addX() .add("QREG", "NOP", "RAMA", "RAMF", "RAMQD", "RAMD", "RAMQU", "RAMU").setDefault("NOP").build(); - private static final IntegerClassification register = new IntegerClassification(0, 4); + private static final IntegerClassification register = new IntegerClassification(4); private static final BooleanClassification registerSelect = new BooleanClassification("MR", "IR"); private static final BooleanClassification abus = new BooleanClassification(true, "H", "AB"); private static final BooleanClassification dbus = new BooleanClassification(true, "H", "DB"); @@ -68,8 +68,8 @@ public class Am2900MicroInstructionDefinition implements MicroInstructionDefinit .add("JZ", "CJS", "JMAP", "CJP", "PUSH", "JSRP", "CJV", "JRP", "RFCT", "RPCT", "CRTN", "CJPP", "LDCT", "LOOP", "CONT", "TWB") .setDefault("CONT").build(); - private static final IntegerClassification constant_12bit = new IntegerClassification(0, 12); - private static final IntegerClassification constant_16bit = new IntegerClassification(0, 16); + private static final IntegerClassification constant_12bit = new IntegerClassification(12); + private static final IntegerClassification constant_16bit = new IntegerClassification(16); private static final BooleanClassification hE = new BooleanClassification(true, "H", "E"); private static final BooleanClassification hI = new BooleanClassification(true, "H", "I"); private static final BooleanClassification hL = new BooleanClassification(true, "H", "L"); diff --git a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/BooleanClassification.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/BooleanClassification.java index e1d3e656..fb94a303 100644 --- a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/BooleanClassification.java +++ b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/BooleanClassification.java @@ -1,6 +1,9 @@ package net.mograsim.machine.mi.parameters; -import net.mograsim.logic.core.types.BitVector; +import static net.mograsim.logic.core.types.BitVector.SINGLE_0; +import static net.mograsim.logic.core.types.BitVector.SINGLE_1; +import static net.mograsim.logic.core.types.BitVector.SINGLE_X; + import net.mograsim.machine.mi.parameters.MicroInstructionParameter.ParameterType; public class BooleanClassification extends MnemonicFamily @@ -9,16 +12,15 @@ public class BooleanClassification extends MnemonicFamily public BooleanClassification(boolean defaultValue, String trueName, String falseName) { - super(defaultValue ? trueName : falseName, new MnemonicPair("X", BitVector.SINGLE_0), - new MnemonicPair(trueName, BitVector.SINGLE_1), new MnemonicPair(falseName, BitVector.SINGLE_0)); + super(defaultValue ? trueName : falseName, new MnemonicPair("X", SINGLE_X), new MnemonicPair(trueName, SINGLE_1), + new MnemonicPair(falseName, SINGLE_0)); this.trueName = trueName; this.falseName = falseName; } public BooleanClassification(String trueName, String falseName) { - super("X", new MnemonicPair("X", BitVector.SINGLE_0), new MnemonicPair(trueName, BitVector.SINGLE_1), - new MnemonicPair(falseName, BitVector.SINGLE_0)); + super("X", new MnemonicPair("X", SINGLE_X), new MnemonicPair(trueName, SINGLE_1), new MnemonicPair(falseName, SINGLE_0)); this.trueName = trueName; this.falseName = falseName; } diff --git a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/IntegerClassification.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/IntegerClassification.java index c24cabeb..ef9f6145 100644 --- a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/IntegerClassification.java +++ b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/IntegerClassification.java @@ -10,10 +10,19 @@ public class IntegerClassification implements ParameterClassification private final int bits; private final IntegerImmediate defaultValue; + /** + * The default value is set to X. + */ + public IntegerClassification(int bits) + { + this.bits = bits; + this.defaultValue = new IntegerImmediate(this, null, bits); + } + public IntegerClassification(int defaultValue, int bits) { this.bits = bits; - this.defaultValue = new IntegerImmediate(BitVector.from(defaultValue, bits)); + this.defaultValue = new IntegerImmediate(this, BitVector.from(defaultValue, bits)); } @Override @@ -31,7 +40,7 @@ public class IntegerClassification implements ParameterClassification @Override public IntegerImmediate parse(String toParse) { - return new IntegerImmediate(new BigInteger(toParse), bits); + return new IntegerImmediate(this, toParse.equals("X") ? null : new BigInteger(toParse), bits); } @Override diff --git a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/IntegerImmediate.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/IntegerImmediate.java index 0194766f..dea11d46 100644 --- a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/IntegerImmediate.java +++ b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/IntegerImmediate.java @@ -1,20 +1,27 @@ package net.mograsim.machine.mi.parameters; +import static net.mograsim.logic.core.types.Bit.X; + import java.math.BigInteger; import net.mograsim.logic.core.types.BitVector; public final class IntegerImmediate implements MicroInstructionParameter { + private IntegerClassification owner; private BitVector value; - public IntegerImmediate(BigInteger value, int bits) + /** + * value == null means a vector consisting only of X + */ + public IntegerImmediate(IntegerClassification owner, BigInteger value, int bits) { - this.value = BitVector.from(value, bits); + this(owner, value == null ? BitVector.of(X, bits) : BitVector.from(value, bits)); } - public IntegerImmediate(BitVector value) + public IntegerImmediate(IntegerClassification owner, BitVector value) { + this.owner = owner; this.value = value; } @@ -58,23 +65,28 @@ public final class IntegerImmediate implements MicroInstructionParameter return true; } + public boolean isX() + { + return value.equals(BitVector.of(X, value.length())); + } + /** - * @return The value of this IntegerImmediate as an unsigned BigInteger + * @return The value of this IntegerImmediate as an unsigned BigInteger, or null, if the value is X. */ public BigInteger getValueAsBigInteger() { - return value.getUnsignedValue(); + return isX() ? null : value.getUnsignedValue(); } @Override public String toString() { - return getValueAsBigInteger().toString(); + return isX() ? "X" : getValueAsBigInteger().toString(); } @Override public boolean isDefault() { - return value.getSignedValueLong() == 0; + return equals(owner.getDefault()); } } diff --git a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/MnemonicFamily.java b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/MnemonicFamily.java index aecf7c52..fbdaf764 100644 --- a/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/MnemonicFamily.java +++ b/plugins/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/MnemonicFamily.java @@ -1,12 +1,13 @@ package net.mograsim.machine.mi.parameters; +import static net.mograsim.logic.core.types.Bit.X; + import java.util.Arrays; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import net.mograsim.logic.core.types.Bit; import net.mograsim.logic.core.types.BitVector; import net.mograsim.machine.MachineException; import net.mograsim.machine.mi.parameters.MicroInstructionParameter.ParameterType; @@ -181,7 +182,7 @@ public class MnemonicFamily implements ParameterClassification public MnemonicFamilyBuilder addX() { - pairs.add(new MnemonicPair("X", BitVector.of(Bit.ZERO, bits))); + pairs.add(new MnemonicPair("X", BitVector.of(X, bits))); return this; } diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberCellEditingSupport.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberCellEditingSupport.java index a3582255..e1308530 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberCellEditingSupport.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberCellEditingSupport.java @@ -15,13 +15,13 @@ public abstract class NumberCellEditingSupport extends EditingSupport protected final CellEditor editor; private final DisplaySettings displaySettings; - public NumberCellEditingSupport(TableViewer viewer, DisplaySettings displaySettings) + public NumberCellEditingSupport(TableViewer viewer, DisplaySettings displaySettings, boolean allowX) { super(viewer); this.viewer = viewer; this.displaySettings = displaySettings; editor = new TextCellEditor(viewer.getTable()); - editor.setValidator(new NumberCellEditorValidator()); + editor.setValidator(new NumberCellEditorValidator(allowX)); } @Override @@ -39,25 +39,35 @@ public abstract class NumberCellEditingSupport extends EditingSupport @Override final protected Object getValue(Object element) { - return AsmNumberUtil.toString(getAsBigInteger(element), displaySettings.getDataNumberType(), getBitLength(element)); + BigInteger bi = getAsBigInteger(element); + return bi == null ? "X" : AsmNumberUtil.toString(bi, displaySettings.getDataNumberType(), getBitLength(element)); } @Override final protected void setValue(Object element, Object userInput) { - try - { - setAsBigInteger(element, AsmNumberUtil.valueOf((String) userInput)); - } - catch (@SuppressWarnings("unused") NumberFormatException e) - { - setAsBigInteger(element, BigInteger.valueOf(0)); - } + if (userInput.equals("X") || userInput.equals("x")) + setAsBigInteger(element, null); + else + try + { + setAsBigInteger(element, AsmNumberUtil.valueOf((String) userInput)); + } + catch (@SuppressWarnings("unused") NumberFormatException e) + { + setAsBigInteger(element, BigInteger.valueOf(0)); + } viewer.update(element, null); } + /** + * value==null means X, if this {@link NumberCellEditingSupport} was created with allowX==true + */ protected abstract void setAsBigInteger(Object element, BigInteger value); + /** + * null means X, if this {@link NumberCellEditingSupport} was created with allowX==true + */ protected abstract BigInteger getAsBigInteger(Object element); protected abstract int getBitLength(Object element); diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberCellEditorValidator.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberCellEditorValidator.java index e0b445dd..66c01d91 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberCellEditorValidator.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberCellEditorValidator.java @@ -6,12 +6,18 @@ import net.mograsim.plugin.asm.AsmNumberUtil; public class NumberCellEditorValidator implements ICellEditorValidator { + private final boolean allowX; + + public NumberCellEditorValidator(boolean allowX) + { + this.allowX = allowX; + } @Override public String isValid(Object value) { - return AsmNumberUtil.NumberType.NONE.equals(AsmNumberUtil.getType((String) value)) ? (String) value + "is not a valid number" + return !(allowX && value.equals("X")) && AsmNumberUtil.NumberType.NONE.equals(AsmNumberUtil.getType((String) value)) + ? (String) value + " is not a valid number" : null; } - -} +} \ No newline at end of file diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberColumnLabelProvider.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberColumnLabelProvider.java index a6e84e72..9d8e4da8 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberColumnLabelProvider.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/NumberColumnLabelProvider.java @@ -18,7 +18,8 @@ public abstract class NumberColumnLabelProvider extends ColumnLabelProvider @Override public String getText(Object element) { - return AsmNumberUtil.toString(getAsBigInteger(element), displaySettings.getDataNumberType(), getBitLength(element)); + BigInteger bi = getAsBigInteger(element); + return bi == null ? "X" : AsmNumberUtil.toString(bi, displaySettings.getDataNumberType(), getBitLength(element)); } public abstract BigInteger getAsBigInteger(Object element); diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryCellEditingSupport.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryCellEditingSupport.java index 6f689e7a..ebb8975a 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryCellEditingSupport.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/memory/MemoryCellEditingSupport.java @@ -12,7 +12,8 @@ public class MemoryCellEditingSupport extends NumberCellEditingSupport { public MemoryCellEditingSupport(TableViewer viewer, DisplaySettings displaySettings) { - super(viewer, displaySettings); + // TODO maybe allow X here too? + super(viewer, displaySettings, false); } @Override diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java index 365c6e19..2cc130af 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/tables/mi/IntegerEditingSupport.java @@ -21,7 +21,7 @@ public class IntegerEditingSupport extends NumberCellEditingSupport public IntegerEditingSupport(TableViewer viewer, MicroInstructionDefinition miDef, int index, DisplaySettings displaySettings, InstructionTableContentProvider provider) { - super(viewer, displaySettings); + super(viewer, displaySettings, true); classification = (IntegerClassification) miDef.getParameterClassifications()[index]; this.index = index; this.provider = provider; @@ -32,7 +32,7 @@ public class IntegerEditingSupport extends NumberCellEditingSupport { InstructionTableRow row = ((InstructionTableRow) element); MicroInstructionParameter[] params = row.data.getCell(row.address).getParameters(); - IntegerImmediate newParam = new IntegerImmediate(value, classification.getExpectedBits()); + IntegerImmediate newParam = new IntegerImmediate(classification, value, classification.getExpectedBits()); if (params[index].equals(newParam)) return; params[index] = newParam;