X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fsnippets%2Fhighlevelstatehandlers%2Fstandard%2Fatomic%2FBitVectorSplittingAtomicHighLevelStateHandler.java;h=0e2328aab64c8af154b7a9ae6f8e5ba447ba63e1;hb=2868cae004941a90130db7e0f070c63bf9f2f9d1;hp=dd7af34e969c2fdc528d742fa5032a0d7f860775;hpb=d091dac791bc2b86a035ef78f8aa7c1401a7e0da;p=Mograsim.git 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 dd7af34e..0e2328aa 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 @@ -16,6 +16,7 @@ public class BitVectorSplittingAtomicHighLevelStateHandler implements AtomicHigh private SubmodelComponent component; private final List vectorPartTargets; private final List vectorPartLengthes; + private int length; public BitVectorSplittingAtomicHighLevelStateHandler(HighLevelStateHandlerContext context) { @@ -41,12 +42,14 @@ public class BitVectorSplittingAtomicHighLevelStateHandler implements AtomicHigh { vectorPartTargets.add(target); vectorPartLengthes.add(length); + this.length += length; } public void clearVectorParts() { vectorPartTargets.clear(); vectorPartLengthes.clear(); + length = 0; } private void setVectorParts(List targets, List lengthes) @@ -56,6 +59,7 @@ public class BitVectorSplittingAtomicHighLevelStateHandler implements AtomicHigh throw new IllegalArgumentException("Targets list and lenghtes list have different sizes"); vectorPartTargets.addAll(targets); vectorPartLengthes.addAll(lengthes); + length += lengthes.stream().mapToInt(Integer::intValue).sum(); } @Override @@ -72,7 +76,7 @@ public class BitVectorSplittingAtomicHighLevelStateHandler implements AtomicHigh vectorPart = (BitVector) subStateUncasted; if (vectorPart.length() != vectorPartLengthes.get(partIndex)) throw new IllegalArgumentException( - "Illegal vector part length: " + vectorPart.length() + "; expected " + vectorPartLengthes.get(partIndex)); + "Incorrect vector part length: " + vectorPart.length() + "; expected " + vectorPartLengthes.get(partIndex)); result = vectorPart.concat(result); } return result; @@ -82,6 +86,8 @@ public class BitVectorSplittingAtomicHighLevelStateHandler implements AtomicHigh public void setHighLevelState(Object newState) { BitVector newStateCasted = (BitVector) newState; + 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 vectorPartLength = vectorPartLengthes.get(partIndex);