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.get());
- }
-
private void setNewValues(BitVector newValues)
{
if (values.equals(newValues))
void recalculate()
{
- switch (inputs.size())
+ if (inputs.size() == 0)
+ setNewValues(BitVector.of(Bit.U, length));
+ else
{
- case 0:
- return;
- case 1:
- recalculateSingleInput();
- break;
- default:
- recalculateMultipleInputs();
+ 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 <code>Wire</code> 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.
*
return val;
}
+ /**
+ * Returns the least significant bit (LSB)
+ */
public Bit getValue()
{
return getValue(0);
}
+ /**
+ * Returns the least significant bit (LSB) of the given index
+ */
public Bit getValue(int index)
{
- return values.getBit(index);
+ return values.getLSBit(index);
}
public BitVector getValues(int start, int end)
return Wire.this.getValue(index);
}
- /**
- * @param index Index of the requested bit.
- * @return The value of the indexed bit.
- *
- * @author Fabian Stemmler
- */
public BitVector getValues()
{
return Wire.this.getValues();
public class ReadWriteEnd extends ReadEnd
{
- private boolean open;
+ private boolean open, isWriting;
private BitVector inputValues;
ReadWriteEnd()
{
super();
open = true;
+ isWriting = true;
initValues();
registerInput(this);
}
}
/**
- * @return The value (of bit 0) the {@link ReadEnd} is currently feeding into the associated {@link Wire}.
+ * @return The value (of bit 0) the {@link ReadEnd} is currently feeding into the associated {@link Wire}.Returns the least
+ * significant bit (LSB)
*/
public Bit getInputValue()
{
/**
* @return The value which the {@link ReadEnd} is currently feeding into the associated {@link Wire} at the indexed {@link Bit}.
+ * Returns the least significant bit (LSB)
+ *
*/
public Bit getInputValue(int index)
{
- return inputValues.getBit(index);
+ return inputValues.getLSBit(index);
}
/**
*/
public BitVector getInputValues()
{
- return getInputValues(0, length);
+ return inputValues;
}
public BitVector getInputValues(int start, int end)
continue;
mutator.join(wireEnd.inputValues);
}
- return mutator.get();
+ return mutator.toBitVector();
}
@Override
{
return inputValues.toString();
}
+
+ @Override
+ public void close()
+ {
+ super.close();
+ open = false;
+ }
+
+ void setWriting(boolean isWriting)
+ {
+ if (this.isWriting != isWriting)
+ {
+ this.isWriting = isWriting;
+ if (isWriting)
+ inputs.add(this);
+ else
+ inputs.remove(this);
+ Wire.this.recalculate();
+ }
+ }
+
+ boolean isWriting()
+ {
+ return isWriting;
+ }
}
@Override
return inputs;
}
+ // TODO Fix ReadWriteEnd feeding signals to entire Wire (Z) instead of only selected Bits
/**
- * @formatter:off
- * Fuses the selected bits of two wires together. If the bits change in one Wire, the other is changed accordingly immediately.
- * Warning: The bits are permanently fused together.
- * @formatter:on
- * @param a The {@link Wire} to be (partially) fused with b
- * @param b The {@link Wire} to be (partially) fused with a
- * @param fromA The first bit of {@link Wire} a to be fused
- * @param fromB The first bit of {@link Wire} b to be fused
+ * Fuses the selected bits of two wires together. If the bits change in one Wire, the other is changed accordingly immediately. Warning:
+ * The bits are permanently fused together.
+ *
+ * @param a The {@link Wire} to be (partially) fused with b
+ * @param b The {@link Wire} to be (partially) fused with a
+ * @param fromA The first bit of {@link Wire} a to be fused
+ * @param fromB The first bit of {@link Wire} b to be fused
* @param length The amount of bits to fuse
*/
public static void fuse(Wire a, Wire b, int fromA, int fromB, int length)
{
ReadWriteEnd rA = a.createReadWriteEnd(), rB = b.createReadWriteEnd();
+ rA.setWriting(false);
+ rB.setWriting(false);
rA.setValues(BitVector.of(Bit.Z, a.length));
rB.setValues(BitVector.of(Bit.Z, b.length));
- rA.registerObserver(new Fusion(rB, fromA, fromB, length));
- rB.registerObserver(new Fusion(rA, fromB, fromA, length));
+ Fusion aF = new Fusion(rB, fromA, fromB, length), bF = new Fusion(rA, fromB, fromA, length);
+ rA.registerObserver(aF);
+ rB.registerObserver(bF);
+ aF.update(rA);
+ bF.update(rB);
}
/**
- * @formatter:off
- * Fuses the selected bits of two wires together. If the bits change in one Wire, the other is changed accordingly immediately.
- * Warning: The bits are permanently fused together.
- * @formatter:on
+ *
+ * Fuses two wires together. If the bits change in one Wire, the other is changed accordingly immediately. Warning: The bits are
+ * permanently fused together.
+ *
* @param a The {@link Wire} to be fused with b
* @param b The {@link Wire} to be fused with a
*/
@Override
public void update(LogicObservable initiator)
{
- ReadWriteEnd read = (ReadWriteEnd) initiator;
- target.setValues(fromTarget, read.wireValuesExcludingMe().subVector(fromSource, fromSource + length));
+ ReadWriteEnd source = (ReadWriteEnd) initiator;
+ if (source.getWire().inputs.size() - (source.isWriting() ? 1 : 0) == 0)
+ target.setWriting(false);
+ else
+ {
+ target.setWriting(true);
+ BitVector targetInput = source.wireValuesExcludingMe().subVector(fromSource, fromSource + length);
+ target.setValues(fromTarget, targetInput);
+ }
}
}
}
\ No newline at end of file