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=7ae29128c6c923b718b56f21a65ecde70a355fb4;hb=8bed58cd47f4e53a0a83e066d38864aa6875502f;hp=dd7af34e969c2fdc528d742fa5032a0d7f860775;hpb=a47c9b1f38bbb6d2f5a3c482f3b09d1f42270401;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..7ae29128 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 @@ -1,33 +1,38 @@ package net.mograsim.logic.model.snippets.highlevelstatehandlers.standard.atomic; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import net.mograsim.logic.core.types.Bit; import net.mograsim.logic.core.types.BitVector; import net.mograsim.logic.model.model.components.submodels.SubmodelComponent; -import net.mograsim.logic.model.serializing.IdentifierGetter; +import net.mograsim.logic.model.serializing.IdentifyParams; import net.mograsim.logic.model.snippets.SnippetDefinintion; -import net.mograsim.logic.model.snippets.highlevelstatehandlers.standard.HighLevelStateHandlerContext; import net.mograsim.logic.model.snippets.highlevelstatehandlers.standard.StandardHighLevelStateHandlerSnippetSuppliers; public class BitVectorSplittingAtomicHighLevelStateHandler implements AtomicHighLevelStateHandler { - private SubmodelComponent component; + private final SubmodelComponent component; private final List vectorPartTargets; + private final List vectorPartTargetsUnmodifiable; private final List vectorPartLengthes; + private final List vectorPartLengthesUnmodifiable; + private int length; - public BitVectorSplittingAtomicHighLevelStateHandler(HighLevelStateHandlerContext context) + public BitVectorSplittingAtomicHighLevelStateHandler(SubmodelComponent component) { - this(context, null); + this(component, null); } - public BitVectorSplittingAtomicHighLevelStateHandler(HighLevelStateHandlerContext context, + public BitVectorSplittingAtomicHighLevelStateHandler(SubmodelComponent component, BitVectorSplittingAtomicHighLevelStateHandlerParams params) { - this.component = context.component; + this.component = component; this.vectorPartTargets = new ArrayList<>(); + this.vectorPartTargetsUnmodifiable = Collections.unmodifiableList(vectorPartTargets); this.vectorPartLengthes = new ArrayList<>(); + this.vectorPartLengthesUnmodifiable = Collections.unmodifiableList(vectorPartLengthes); if (params != null) setVectorParts(params.vectorPartTargets, params.vectorPartLengthes); } @@ -41,21 +46,34 @@ 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(); + } + + public List getVectorPartTargets() + { + return vectorPartTargetsUnmodifiable; + } + + public List getVectorPartLenghtes() + { + return vectorPartLengthesUnmodifiable; } @Override @@ -72,8 +90,8 @@ 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)); - result = vectorPart.concat(result); + "Incorrect vector part length: " + vectorPart.length() + "; expected " + vectorPartLengthes.get(partIndex)); + result = result.concat(vectorPart); } return result; } @@ -82,7 +100,9 @@ public class BitVectorSplittingAtomicHighLevelStateHandler implements AtomicHigh public void setHighLevelState(Object newState) { BitVector newStateCasted = (BitVector) newState; - for (int partIndex = vectorPartTargets.size() - 1, bitIndex = 0; partIndex >= 0; partIndex--) + if (newStateCasted.length() != length) + throw new IllegalArgumentException("Incorrect vector length: " + newStateCasted.length() + "; expected " + length); + for (int partIndex = 0, bitIndex = 0; partIndex < vectorPartTargets.size(); partIndex++) { int vectorPartLength = vectorPartLengthes.get(partIndex); BitVector vectorPart = newStateCasted.subVector(bitIndex, bitIndex + vectorPartLength); @@ -92,7 +112,13 @@ public class BitVectorSplittingAtomicHighLevelStateHandler implements AtomicHigh } @Override - public BitVectorSplittingAtomicHighLevelStateHandlerParams getParamsForSerializing(IdentifierGetter idGetter) + public String getIDForSerializing(IdentifyParams idParams) + { + return "bitVectorSplitting"; + } + + @Override + public BitVectorSplittingAtomicHighLevelStateHandlerParams getParamsForSerializing(IdentifyParams idParams) { BitVectorSplittingAtomicHighLevelStateHandlerParams params = new BitVectorSplittingAtomicHighLevelStateHandlerParams(); params.vectorPartTargets = new ArrayList<>(vectorPartTargets);