Refactored BitVector methods to resolve ambiguity
[Mograsim.git] / net.mograsim.logic.core / src / net / mograsim / logic / core / wires / Wire.java
index a1361b0..6310d5b 100644 (file)
@@ -51,19 +51,6 @@ public class Wire
                values = U.toVector(length);\r
        }\r
 \r
-       private void recalculateSingleInput()\r
-       {\r
-               setNewValues(inputs.get(0).getInputValues());\r
-       }\r
-\r
-       private void recalculateMultipleInputs()\r
-       {\r
-               BitVectorMutator mutator = BitVectorMutator.empty();\r
-               for (ReadWriteEnd wireArrayEnd : inputs)\r
-                       mutator.join(wireArrayEnd.getInputValues());\r
-               setNewValues(mutator.get());\r
-       }\r
-\r
        private void setNewValues(BitVector newValues)\r
        {\r
                if (values.equals(newValues))\r
@@ -75,19 +62,28 @@ public class Wire
 \r
        void recalculate()\r
        {\r
-               switch (inputs.size())\r
-               {\r
-               case 0:\r
+               if (inputs.size() == 0)\r
                        setNewValues(BitVector.of(Bit.U, length));\r
-                       break;\r
-               case 1:\r
-                       recalculateSingleInput();\r
-                       break;\r
-               default:\r
-                       recalculateMultipleInputs();\r
+               else\r
+               {\r
+                       BitVectorMutator mutator = BitVectorMutator.empty();\r
+                       for (ReadWriteEnd wireArrayEnd : inputs)\r
+                               mutator.join(wireArrayEnd.getInputValues());\r
+                       setNewValues(mutator.toBitVector());\r
                }\r
        }\r
 \r
+       /**\r
+        * Forces a Wire to take on specific values. If the new values differ from the old ones, the observers of the Wire will be notified.\r
+        * WARNING! Use this with care! The preferred way of writing the values is ReadWriteEnd.feedSignals(BitVector)\r
+        * \r
+        * @param values The values the <code>Wire</code> will have immediately after this method is called\r
+        */\r
+       public void forceValues(BitVector values)\r
+       {\r
+               setNewValues(values);\r
+       }\r
+\r
        /**\r
         * The {@link Wire} is interpreted as an unsigned integer with n bits.\r
         * \r
@@ -154,14 +150,20 @@ public class Wire
                return val;\r
        }\r
 \r
+       /**\r
+        * Returns the least significant bit (LSB)\r
+        */\r
        public Bit getValue()\r
        {\r
                return getValue(0);\r
        }\r
 \r
+       /**\r
+        * Returns the least significant bit (LSB) of the given index\r
+        */\r
        public Bit getValue(int index)\r
        {\r
-               return values.getBit(index);\r
+               return values.getLSBit(index);\r
        }\r
 \r
        public BitVector getValues(int start, int end)\r
@@ -450,7 +452,8 @@ public class Wire
                }\r
 \r
                /**\r
-                * @return The value (of bit 0) the {@link ReadEnd} is currently feeding into the associated {@link Wire}.\r
+                * @return The value (of bit 0) the {@link ReadEnd} is currently feeding into the associated {@link Wire}.Returns the least\r
+                *         significant bit (LSB)\r
                 */\r
                public Bit getInputValue()\r
                {\r
@@ -459,10 +462,12 @@ public class Wire
 \r
                /**\r
                 * @return The value which the {@link ReadEnd} is currently feeding into the associated {@link Wire} at the indexed {@link Bit}.\r
+                *         Returns the least significant bit (LSB)\r
+                * \r
                 */\r
                public Bit getInputValue(int index)\r
                {\r
-                       return inputValues.getBit(index);\r
+                       return inputValues.getLSBit(index);\r
                }\r
 \r
                /**\r
@@ -470,7 +475,7 @@ public class Wire
                 */\r
                public BitVector getInputValues()\r
                {\r
-                       return getInputValues(0, length);\r
+                       return inputValues;\r
                }\r
 \r
                public BitVector getInputValues(int start, int end)\r
@@ -495,7 +500,7 @@ public class Wire
                                        continue;\r
                                mutator.join(wireEnd.inputValues);\r
                        }\r
-                       return mutator.get();\r
+                       return mutator.toBitVector();\r
                }\r
 \r
                @Override\r
@@ -556,7 +561,7 @@ public class Wire
         * @param fromB  The first bit of {@link Wire} b to be fused\r
         * @param length The amount of bits to fuse\r
         */\r
-       private static void fuse(Wire a, Wire b, int fromA, int fromB, int length)\r
+       public static void fuse(Wire a, Wire b, int fromA, int fromB, int length)\r
        {\r
                ReadWriteEnd rA = a.createReadWriteEnd(), rB = b.createReadWriteEnd();\r
                rA.setWriting(false);\r