From: Fabian Stemmler Date: Wed, 26 Jun 2019 13:51:57 +0000 (+0200) Subject: Added forceValues(...) method to Wire X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=847dd0a23c86ddd67c16c47170ae7e7732682140;p=Mograsim.git Added forceValues(...) method to Wire --- diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/wires/Wire.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/wires/Wire.java index 8eff2efa..a14efb08 100644 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/wires/Wire.java +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/wires/Wire.java @@ -51,19 +51,6 @@ public class Wire values = U.toVector(length); } - private void recalculateSingleInput() - { - setNewValues(inputs.get(0).getInputValues()); - } - - private void recalculateMultipleInputs() - { - BitVectorMutator mutator = BitVectorMutator.empty(); - for (ReadWriteEnd wireArrayEnd : inputs) - mutator.join(wireArrayEnd.getInputValues()); - setNewValues(mutator.toBitVector()); - } - private void setNewValues(BitVector newValues) { if (values.equals(newValues)) @@ -75,19 +62,28 @@ public class Wire void recalculate() { - switch (inputs.size()) - { - case 0: + if (inputs.size() == 0) setNewValues(BitVector.of(Bit.U, length)); - break; - case 1: - recalculateSingleInput(); - break; - default: - recalculateMultipleInputs(); + else + { + BitVectorMutator mutator = BitVectorMutator.empty(); + for (ReadWriteEnd wireArrayEnd : inputs) + mutator.join(wireArrayEnd.getInputValues()); + setNewValues(mutator.toBitVector()); } } + /** + * 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. + * WARNING! Use this with care! The preferred way of writing the values is ReadWriteEnd.feedSignals(BitVector) + * + * @param values The values the Wire will have immediately after this method is called + */ + public void forceValues(BitVector values) + { + setNewValues(values); + } + /** * The {@link Wire} is interpreted as an unsigned integer with n bits. *