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=b17af6ff078993bbf5d148da558a324df663f4ef;hb=4d7f92457692ef00a591084390dc191f84c99628;hp=dd7af34e969c2fdc528d742fa5032a0d7f860775;hpb=3977f16649531ca3ba345c9cd5ec365e0b804783;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..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 @@ -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,21 +42,24 @@ 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) { clearVectorParts(); if (targets.size() != lengthes.size()) - throw new IllegalArgumentException("Targets list and lenghtes list have different sizes"); + throw new IllegalArgumentException("Targets list and lengthes 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);