Fixed a bug in Am2900; created dlatch8/80; relayouted some components
[Mograsim.git] / net.mograsim.logic.model / src / net / mograsim / logic / model / snippets / highlevelstatehandlers / standard / atomic / BitVectorSplittingAtomicHighLevelStateHandler.java
index f26c872..7ae2912 100644 (file)
@@ -1,65 +1,79 @@
 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<String> vectorPartTargets;
-       private final List<Integer> vectorPartWidths;
-       private int width;
+       private final List<String> vectorPartTargetsUnmodifiable;
+       private final List<Integer> vectorPartLengthes;
+       private final List<Integer> 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.vectorPartWidths = new ArrayList<>();
+               this.vectorPartTargetsUnmodifiable = Collections.unmodifiableList(vectorPartTargets);
+               this.vectorPartLengthes = new ArrayList<>();
+               this.vectorPartLengthesUnmodifiable = Collections.unmodifiableList(vectorPartLengthes);
                if (params != null)
-                       setVectorParts(params.vectorPartTargets, params.vectorPartWidths);
+                       setVectorParts(params.vectorPartTargets, params.vectorPartLengthes);
        }
 
-       public void set(List<String> targets, List<Integer> widths)
+       public void set(List<String> targets, List<Integer> 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<String> targets, List<Integer> widths)
+       private void setVectorParts(List<String> targets, List<Integer> 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();
+       }
+
+       public List<String> getVectorPartTargets()
+       {
+               return vectorPartTargetsUnmodifiable;
+       }
+
+       public List<Integer> getVectorPartLenghtes()
+       {
+               return vectorPartLengthesUnmodifiable;
        }
 
        @Override
@@ -74,10 +88,10 @@ 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));
-                       result = vectorPart.concat(result);
+                                               "Incorrect vector part length: " + vectorPart.length() + "; expected " + vectorPartLengthes.get(partIndex));
+                       result = result.concat(vectorPart);
                }
                return result;
        }
@@ -86,30 +100,36 @@ 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);
-               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 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;
                }
        }
 
        @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);
-               params.vectorPartWidths = new ArrayList<>(vectorPartWidths);
+               params.vectorPartLengthes = new ArrayList<>(vectorPartLengthes);
                return params;
        }
 
        public static class BitVectorSplittingAtomicHighLevelStateHandlerParams
        {
                public List<String> vectorPartTargets;
-               public List<Integer> vectorPartWidths;
+               public List<Integer> vectorPartLengthes;
        }
 
        static