From: Daniel Kirschten Date: Tue, 27 Aug 2019 08:35:48 +0000 (+0200) Subject: Undo renaming of BitVector's length to width X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=4d7f92457692ef00a591084390dc191f84c99628;p=Mograsim.git Undo renaming of BitVector's length to width --- diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java index 25445ee1..40f0005a 100644 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java @@ -55,8 +55,8 @@ public class ManualSwitch extends Component implements LogicObservable public void setState(BitVector bits) { - if (bits.width() != output.width()) - throw new IllegalArgumentException("Incorrect bit vector width"); + if (bits.length() != output.width()) + throw new IllegalArgumentException("Incorrect bit vector length"); if (bits.equals(output.getInputValues())) return; output.feedSignals(bits); diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/types/Bit.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/types/Bit.java index e6278104..da7b8c91 100644 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/types/Bit.java +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/types/Bit.java @@ -69,9 +69,9 @@ public enum Bit implements StrictLogicType return bits; } - public BitVector toVector(int width) + public BitVector toVector(int length) { - return BitVector.of(this, width); + return BitVector.of(this, length); } @Override diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/types/BitVector.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/types/BitVector.java index aed0288d..b907ce7e 100644 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/types/BitVector.java +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/types/BitVector.java @@ -50,11 +50,11 @@ public final class BitVector implements StrictLogicType, Iterable, Iterable, Iterable op) @@ -227,11 +227,11 @@ public final class BitVector implements StrictLogicType, Iterablewith all bits set to null. Use with care! + * Returns a new mutator of the specified length, with all bits set to null. Use with care! */ - public static BitVectorMutator ofWidth(int width) + public static BitVectorMutator ofLength(int length) { - return new BitVectorMutator(new Bit[width]); + return new BitVectorMutator(new Bit[length]); } /** @@ -344,17 +344,17 @@ public final class BitVector implements StrictLogicType, Iterable, Iterableoffset to the right.
- * Therefore offset + other.width() <= this.wdith() needs to be true. + * Therefore offset + other.length() <= this.wdith() needs to be true. * - * @throws ArrayIndexOutOfBoundsException if offset + other.width() > this.width() + * @throws ArrayIndexOutOfBoundsException if offset + other.length() > this.length() * * @see Object#equals(Object) */ @@ -395,7 +395,7 @@ public final class BitVector implements StrictLogicType, Iterable, Iterable setValues(newValues), travelTime); @@ -422,7 +422,7 @@ public class Wire if (!inputValues.equalsWithOffset(newValues, startingBit)) { Bit[] vals = inputValues.getBits(); - System.arraycopy(newValues.getBits(), 0, vals, startingBit, newValues.width()); + System.arraycopy(newValues.getBits(), 0, vals, startingBit, newValues.length()); inputValues = BitVector.of(vals); Wire.this.recalculate(); } diff --git a/net.mograsim.logic.core/test/net/mograsim/logic/core/types/BitVectorTest.java b/net.mograsim.logic.core/test/net/mograsim/logic/core/types/BitVectorTest.java index b83a5ff9..11b5febf 100644 --- a/net.mograsim.logic.core/test/net/mograsim/logic/core/types/BitVectorTest.java +++ b/net.mograsim.logic.core/test/net/mograsim/logic/core/types/BitVectorTest.java @@ -128,7 +128,7 @@ class BitVectorTest assertEquals(SINGLE_U, SINGLE_0.join(SINGLE_U)); assertEquals(SINGLE_X, SINGLE_X.join(SINGLE_Z)); - // higher width + // higher length var result = BitVector.of(U, X, ZERO, ONE, Z).join(BitVector.of(ONE, ZERO, ZERO, ONE, Z)); assertEquals(BitVector.of(U, X, ZERO, ONE, Z), result); } @@ -146,7 +146,7 @@ class BitVectorTest assertEquals(SINGLE_0, SINGLE_0.and(SINGLE_U)); assertEquals(SINGLE_X, SINGLE_X.and(SINGLE_Z)); - // higher width + // higher length var result = BitVector.of(U, X, ZERO, ONE, ONE).and(BitVector.of(ONE, ONE, ZERO, ZERO, ONE)); assertEquals(BitVector.of(U, X, ZERO, ZERO, ONE), result); } @@ -164,7 +164,7 @@ class BitVectorTest assertEquals(SINGLE_1, SINGLE_1.or(SINGLE_U)); assertEquals(SINGLE_X, SINGLE_X.or(SINGLE_Z)); - // higher width + // higher length var result = BitVector.of(U, X, ZERO, ONE, ZERO).or(BitVector.of(ZERO, ZERO, ZERO, ONE, ONE)); assertEquals(BitVector.of(U, X, ZERO, ONE, ONE), result); } @@ -182,7 +182,7 @@ class BitVectorTest assertEquals(SINGLE_U, SINGLE_0.xor(SINGLE_U)); assertEquals(SINGLE_X, SINGLE_X.xor(SINGLE_Z)); - // higher width + // higher length var result = BitVector.of(U, X, ZERO, ONE, ONE).xor(BitVector.of(ONE, ZERO, ZERO, ZERO, ONE)); assertEquals(BitVector.of(U, X, ZERO, ONE, ZERO), result); } @@ -199,17 +199,17 @@ class BitVectorTest assertEquals(SINGLE_X, SINGLE_X.not()); assertEquals(SINGLE_X, SINGLE_Z.not()); - // higher width + // higher length var result = BitVector.of(U, X, ZERO, ONE, Z).not(); assertEquals(BitVector.of(U, X, ONE, ZERO, X), result); } @Test - void testWidth() + void testLength() { - assertEquals(0, BitVector.of().width()); - assertEquals(1, SINGLE_0.width()); - assertEquals(3, BitVector.of(X, X, Z).width()); + assertEquals(0, BitVector.of().length()); + assertEquals(1, SINGLE_0.length()); + assertEquals(3, BitVector.of(X, X, Z).length()); } @Test diff --git a/net.mograsim.logic.model.am2900/components/GUIdff4.json b/net.mograsim.logic.model.am2900/components/GUIdff4.json index 72b7273d..4064f93e 100644 --- a/net.mograsim.logic.model.am2900/components/GUIdff4.json +++ b/net.mograsim.logic.model.am2900/components/GUIdff4.json @@ -689,7 +689,7 @@ mograsim version: 0.1.3 "q3", "q4" ], - "vectorPartWidths": [ + "vectorPartLengthes": [ 1, 1, 1, diff --git a/net.mograsim.logic.model.am2900/components/GUIdff4_invwe.json b/net.mograsim.logic.model.am2900/components/GUIdff4_invwe.json index 7665a992..cb697d23 100644 --- a/net.mograsim.logic.model.am2900/components/GUIdff4_invwe.json +++ b/net.mograsim.logic.model.am2900/components/GUIdff4_invwe.json @@ -698,7 +698,7 @@ mograsim version: 0.1.3 "q3", "q4" ], - "vectorPartWidths": [ + "vectorPartLengthes": [ 1, 1, 1, diff --git a/net.mograsim.logic.model.am2900/components/GUIdlatch4.json b/net.mograsim.logic.model.am2900/components/GUIdlatch4.json index a836450f..28021dff 100644 --- a/net.mograsim.logic.model.am2900/components/GUIdlatch4.json +++ b/net.mograsim.logic.model.am2900/components/GUIdlatch4.json @@ -368,7 +368,7 @@ mograsim version: 0.1.3 "q3", "q4" ], - "vectorPartWidths": [ + "vectorPartLengthes": [ 1, 1, 1, diff --git a/net.mograsim.logic.model.am2900/components/GUIram2.json b/net.mograsim.logic.model.am2900/components/GUIram2.json index c2919803..31a01fba 100644 --- a/net.mograsim.logic.model.am2900/components/GUIram2.json +++ b/net.mograsim.logic.model.am2900/components/GUIram2.json @@ -2998,7 +2998,7 @@ mograsim version: 0.1.3 "c01.q", "c00.q" ], - "vectorPartWidths": [ + "vectorPartLengthes": [ 4, 4, 4, diff --git a/net.mograsim.logic.model.am2900/components/GUIram4.json b/net.mograsim.logic.model.am2900/components/GUIram4.json index f676b3dd..05bfe9da 100644 --- a/net.mograsim.logic.model.am2900/components/GUIram4.json +++ b/net.mograsim.logic.model.am2900/components/GUIram4.json @@ -3490,7 +3490,7 @@ mograsim version: 0.1.3 "c01.q", "c00.q" ], - "vectorPartWidths": [ + "vectorPartLengthes": [ 16, 16, 16, diff --git a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestUtil.java b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestUtil.java index cd682f28..46a4b92c 100644 --- a/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestUtil.java +++ b/net.mograsim.logic.model.am2900/test/net/mograsim/logic/model/am2900/TestUtil.java @@ -92,11 +92,11 @@ public final class TestUtil return sb.reverse().toString(); } - public static BitVector of(int value, int width) + public static BitVector of(int value, int length) { - BitVectorMutator mutator = BitVectorMutator.ofWidth(width); + BitVectorMutator mutator = BitVectorMutator.ofLength(length); int val = value; - for (int i = width - 1; i >= 0; i--) + for (int i = length - 1; i >= 0; i--) { mutator.setMSBit(i, Bit.lastBitOf(val)); val >>>= 1; diff --git a/net.mograsim.logic.model.editor/components/GUIdff4.json b/net.mograsim.logic.model.editor/components/GUIdff4.json index 72b7273d..4064f93e 100644 --- a/net.mograsim.logic.model.editor/components/GUIdff4.json +++ b/net.mograsim.logic.model.editor/components/GUIdff4.json @@ -689,7 +689,7 @@ mograsim version: 0.1.3 "q3", "q4" ], - "vectorPartWidths": [ + "vectorPartLengthes": [ 1, 1, 1, diff --git a/net.mograsim.logic.model.editor/components/GUIdff4_invwe.json b/net.mograsim.logic.model.editor/components/GUIdff4_invwe.json index 7665a992..cb697d23 100644 --- a/net.mograsim.logic.model.editor/components/GUIdff4_invwe.json +++ b/net.mograsim.logic.model.editor/components/GUIdff4_invwe.json @@ -698,7 +698,7 @@ mograsim version: 0.1.3 "q3", "q4" ], - "vectorPartWidths": [ + "vectorPartLengthes": [ 1, 1, 1, diff --git a/net.mograsim.logic.model.editor/components/GUIdlatch4.json b/net.mograsim.logic.model.editor/components/GUIdlatch4.json index a836450f..28021dff 100644 --- a/net.mograsim.logic.model.editor/components/GUIdlatch4.json +++ b/net.mograsim.logic.model.editor/components/GUIdlatch4.json @@ -368,7 +368,7 @@ mograsim version: 0.1.3 "q3", "q4" ], - "vectorPartWidths": [ + "vectorPartLengthes": [ 1, 1, 1, diff --git a/net.mograsim.logic.model.editor/components/GUIram2.json b/net.mograsim.logic.model.editor/components/GUIram2.json index c2919803..31a01fba 100644 --- a/net.mograsim.logic.model.editor/components/GUIram2.json +++ b/net.mograsim.logic.model.editor/components/GUIram2.json @@ -2998,7 +2998,7 @@ mograsim version: 0.1.3 "c01.q", "c00.q" ], - "vectorPartWidths": [ + "vectorPartLengthes": [ 4, 4, 4, diff --git a/net.mograsim.logic.model.editor/components/GUIram4.json b/net.mograsim.logic.model.editor/components/GUIram4.json index f676b3dd..05bfe9da 100644 --- a/net.mograsim.logic.model.editor/components/GUIram4.json +++ b/net.mograsim.logic.model.editor/components/GUIram4.json @@ -3490,7 +3490,7 @@ mograsim version: 0.1.3 "c01.q", "c00.q" ], - "vectorPartWidths": [ + "vectorPartLengthes": [ 16, 16, 16, diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/highlevelstatehandlers/standard/atomic/BitVectorSplittingAtomicHighLevelStateHandler.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/highlevelstatehandlers/standard/atomic/BitVectorSplittingAtomicHighLevelStateHandler.java index f26c8723..b17af6ff 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/highlevelstatehandlers/standard/atomic/BitVectorSplittingAtomicHighLevelStateHandler.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/highlevelstatehandlers/standard/atomic/BitVectorSplittingAtomicHighLevelStateHandler.java @@ -15,8 +15,8 @@ public class BitVectorSplittingAtomicHighLevelStateHandler implements AtomicHigh { private SubmodelComponent component; private final List vectorPartTargets; - private final List vectorPartWidths; - private int width; + private final List vectorPartLengthes; + private int length; public BitVectorSplittingAtomicHighLevelStateHandler(HighLevelStateHandlerContext context) { @@ -28,38 +28,38 @@ public class BitVectorSplittingAtomicHighLevelStateHandler implements AtomicHigh { this.component = context.component; this.vectorPartTargets = new ArrayList<>(); - this.vectorPartWidths = new ArrayList<>(); + this.vectorPartLengthes = new ArrayList<>(); if (params != null) - setVectorParts(params.vectorPartTargets, params.vectorPartWidths); + setVectorParts(params.vectorPartTargets, params.vectorPartLengthes); } - public void set(List targets, List widths) + public void set(List targets, List lengthes) { - setVectorParts(targets, widths); + setVectorParts(targets, lengthes); } - public void addVectorPart(String target, int width) + public void addVectorPart(String target, int length) { vectorPartTargets.add(target); - vectorPartWidths.add(width); - this.width += width; + vectorPartLengthes.add(length); + this.length += length; } public void clearVectorParts() { vectorPartTargets.clear(); - vectorPartWidths.clear(); - width = 0; + vectorPartLengthes.clear(); + length = 0; } - private void setVectorParts(List targets, List widths) + private void setVectorParts(List targets, List lengthes) { clearVectorParts(); - if (targets.size() != widths.size()) - throw new IllegalArgumentException("Targets list and widths list have different sizes"); + if (targets.size() != lengthes.size()) + throw new IllegalArgumentException("Targets list and lengthes list have different sizes"); vectorPartTargets.addAll(targets); - vectorPartWidths.addAll(widths); - width += widths.stream().mapToInt(Integer::intValue).sum(); + vectorPartLengthes.addAll(lengthes); + length += lengthes.stream().mapToInt(Integer::intValue).sum(); } @Override @@ -74,9 +74,9 @@ public class BitVectorSplittingAtomicHighLevelStateHandler implements AtomicHigh vectorPart = BitVector.of((Bit) subStateUncasted); else vectorPart = (BitVector) subStateUncasted; - if (vectorPart.width() != vectorPartWidths.get(partIndex)) + if (vectorPart.length() != vectorPartLengthes.get(partIndex)) throw new IllegalArgumentException( - "Incorrect vector part width: " + vectorPart.width() + "; expected " + vectorPartWidths.get(partIndex)); + "Incorrect vector part length: " + vectorPart.length() + "; expected " + vectorPartLengthes.get(partIndex)); result = vectorPart.concat(result); } return result; @@ -86,14 +86,14 @@ public class BitVectorSplittingAtomicHighLevelStateHandler implements AtomicHigh public void setHighLevelState(Object newState) { BitVector newStateCasted = (BitVector) newState; - if (newStateCasted.width() != width) - throw new IllegalArgumentException("Incorrect vector width: " + newStateCasted.width() + "; expected " + width); + if (newStateCasted.length() != length) + throw new IllegalArgumentException("Incorrect vector length: " + newStateCasted.length() + "; expected " + length); for (int partIndex = vectorPartTargets.size() - 1, bitIndex = 0; partIndex >= 0; partIndex--) { - int vectorPartWidth = vectorPartWidths.get(partIndex); - BitVector vectorPart = newStateCasted.subVector(bitIndex, bitIndex + vectorPartWidth); + int vectorPartLength = vectorPartLengthes.get(partIndex); + BitVector vectorPart = newStateCasted.subVector(bitIndex, bitIndex + vectorPartLength); component.setHighLevelState(vectorPartTargets.get(partIndex), vectorPart); - bitIndex += vectorPartWidth; + bitIndex += vectorPartLength; } } @@ -102,14 +102,14 @@ public class BitVectorSplittingAtomicHighLevelStateHandler implements AtomicHigh { BitVectorSplittingAtomicHighLevelStateHandlerParams params = new BitVectorSplittingAtomicHighLevelStateHandlerParams(); params.vectorPartTargets = new ArrayList<>(vectorPartTargets); - params.vectorPartWidths = new ArrayList<>(vectorPartWidths); + params.vectorPartLengthes = new ArrayList<>(vectorPartLengthes); return params; } public static class BitVectorSplittingAtomicHighLevelStateHandlerParams { public List vectorPartTargets; - public List vectorPartWidths; + public List vectorPartLengthes; } static diff --git a/net.mograsim.machine/src/net/mograsim/machine/isa/AsmFloatOperand.java b/net.mograsim.machine/src/net/mograsim/machine/isa/AsmFloatOperand.java index a15d9d5a..7a1a6ebf 100644 --- a/net.mograsim.machine/src/net/mograsim/machine/isa/AsmFloatOperand.java +++ b/net.mograsim.machine/src/net/mograsim/machine/isa/AsmFloatOperand.java @@ -90,7 +90,7 @@ public class AsmFloatOperand implements AsmOperand int bitLength = raw.bitLength() - (bi.signum() - 1) / 2; if (bitLength > size) throw new AsmNumberFormatException("Error parsing %s: bit count %d exceeds size %d", bi, bitLength, size); - BitVectorMutator bvm = BitVectorMutator.ofWidth(size); + BitVectorMutator bvm = BitVectorMutator.ofLength(size); for (int i = 0; i < size; i++) bvm.setLSBit(i, Bit.of(raw.testBit(i))); return bvm.toBitVector(); diff --git a/net.mograsim.machine/src/net/mograsim/machine/isa/AsmIntegerOperand.java b/net.mograsim.machine/src/net/mograsim/machine/isa/AsmIntegerOperand.java index 70f5a435..d3ac80f9 100644 --- a/net.mograsim.machine/src/net/mograsim/machine/isa/AsmIntegerOperand.java +++ b/net.mograsim.machine/src/net/mograsim/machine/isa/AsmIntegerOperand.java @@ -55,7 +55,7 @@ public class AsmIntegerOperand implements AsmOperand int bitLength = bi.bitLength() - (bi.signum() - 1) / 2; if (bitLength > size) throw new AsmNumberFormatException("Error parsing %s: bit count %d exceeds size %d", bi, bitLength, size); - BitVectorMutator bvm = BitVectorMutator.ofWidth(size); + BitVectorMutator bvm = BitVectorMutator.ofLength(size); for (int i = 0; i < size; i++) bvm.setLSBit(i, Bit.of(bi.testBit(i))); return bvm.toBitVector(); diff --git a/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/MnemonicFamily.java b/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/MnemonicFamily.java index aa07f808..3724a426 100644 --- a/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/MnemonicFamily.java +++ b/net.mograsim.machine/src/net/mograsim/machine/mi/parameters/MnemonicFamily.java @@ -19,9 +19,9 @@ public class MnemonicFamily implements ParameterClassification vectorLenght = 0; else { - vectorLenght = values[0].getValue().width(); + vectorLenght = values[0].getValue().length(); for(int i = 1; i < values.length; i++) - if(values[i].getValue().width() != vectorLenght) + if(values[i].getValue().length() != vectorLenght) throw new IllegalArgumentException("MnemonicFamily is not of uniform vector length!"); } byText = Arrays.stream(values).collect(Collectors.toMap(m -> m.getText(), m -> m)); diff --git a/net.mograsim.machine/src/net/mograsim/machine/standard/memory/WordAddressableMemory.java b/net.mograsim.machine/src/net/mograsim/machine/standard/memory/WordAddressableMemory.java index 2e209f1c..e828a249 100644 --- a/net.mograsim.machine/src/net/mograsim/machine/standard/memory/WordAddressableMemory.java +++ b/net.mograsim.machine/src/net/mograsim/machine/standard/memory/WordAddressableMemory.java @@ -112,9 +112,9 @@ public class WordAddressableMemory implements MainMemory public void setCell(int index, BitVector bits) { - if (bits.width() != cellWidth) + if (bits.length() != cellWidth) throw new IllegalArgumentException(String.format( - "BitVector to be saved in memory cell has unexpected width. Expected: %d Actual: %d", cellWidth, bits.width())); + "BitVector to be saved in memory cell has unexpected width. Expected: %d Actual: %d", cellWidth, bits.length())); memory[index] = bits; }