@Override
public Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
{
- Bit[] QC = (Bit[]) lastState;
- if (QC == null)
- {
- QC = new Bit[13];
- Arrays.fill(QC, U);
- }
+ Bit[] QC = castAndInitState(lastState);
Bit CVal = readEnds.get("C").getValue();
@Override
protected Object getHighLevelState(Object state, String stateID)
{
+ Bit[] QC = castAndInitState(state);
+
switch (stateID)
{
case "q":
- return BitVector.of(Arrays.copyOfRange((Bit[]) state, 0, 12));
+ return BitVector.of(Arrays.copyOfRange(QC, 0, 12));
default:
- return super.getHighLevelState(state, stateID);
+ return super.getHighLevelState(QC, stateID);
}
}
@Override
protected Object setHighLevelState(Object lastState, String stateID, Object newHighLevelState)
{
+ Bit[] QC = castAndInitState(lastState);
+
switch (stateID)
{
case "q":
BitVector newHighLevelStateCasted = (BitVector) newHighLevelState;
if (newHighLevelStateCasted.length() != 12)
throw new IllegalArgumentException("Expected BitVector of length 12, not " + newHighLevelStateCasted.length());
- System.arraycopy(newHighLevelStateCasted.getBits(), 0, lastState, 0, 12);
- return lastState;
+ System.arraycopy(newHighLevelStateCasted.getBits(), 0, QC, 0, 12);
+ return QC;
default:
- return super.setHighLevelState(lastState, stateID, newHighLevelState);
+ return super.setHighLevelState(QC, stateID, newHighLevelState);
+ }
+ }
+
+ private static Bit[] castAndInitState(Object state)
+ {
+ Bit[] QC = (Bit[]) state;
+ if (QC == null)
+ {
+ QC = new Bit[13];
+ Arrays.fill(QC, U);
}
+ return QC;
}
static
@Override
public Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
{
- BitVector[] memC = (BitVector[]) lastState;
- if (memC == null)
- {
- memC = new BitVector[6];
- Arrays.fill(memC, 0, 5, BitVector.of(U, 12));
- memC[5] = BitVector.of(U);
- }
+ BitVector[] memC = castAndInitState(lastState);
+
BitVector CVal = readEnds.get("C").getValues();
BitVector oldC = memC[5];
// TODO is the timing right?
@Override
protected Object getHighLevelState(Object state, String stateID)
{
+ BitVector[] memC = castAndInitState(state);
+
Matcher m = stateIDPattern.matcher(stateID);
if (m.matches())
- return ((BitVector[]) state)[Integer.parseInt(m.group(1), 2)];
- return super.getHighLevelState(state, stateID);
+ return memC[Integer.parseInt(m.group(1), 2)];
+ return super.getHighLevelState(memC, stateID);
}
@Override
protected Object setHighLevelState(Object lastState, String stateID, Object newHighLevelState)
{
+ BitVector[] memC = castAndInitState(lastState);
+
Matcher m = stateIDPattern.matcher(stateID);
if (m.matches())
{
BitVector newHighLevelStateCasted = (BitVector) newHighLevelState;
if (newHighLevelStateCasted.length() != 12)
throw new IllegalArgumentException("Expected BitVector of length 12, not " + newHighLevelStateCasted.length());
- BitVector[] memC = (BitVector[]) lastState;
memC[addr] = newHighLevelStateCasted;
return memC;
}
- return super.setHighLevelState(lastState, stateID, newHighLevelState);
+ return super.setHighLevelState(memC, stateID, newHighLevelState);
+ }
+
+ private static BitVector[] castAndInitState(Object state)
+ {
+ BitVector[] memC = (BitVector[]) state;
+ if (memC == null)
+ {
+ memC = new BitVector[6];
+ Arrays.fill(memC, 0, 5, BitVector.of(U, 12));
+ memC[5] = BitVector.of(U);
+ }
+ return memC;
}
static
@Override
public Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
{
- Bit[] QC = (Bit[]) lastState;
- if (QC == null)
- {
- QC = new Bit[13];
- Arrays.fill(QC, U);
- }
+ Bit[] QC = castAndInitState(lastState);
ReadEnd D = readEnds.get("D");
ReadEnd _RLD = readEnds.get("_RLD");
@Override
protected Object getHighLevelState(Object state, String stateID)
{
+ Bit[] QC = castAndInitState(state);
+
switch (stateID)
{
case "q":
- return BitVector.of(Arrays.copyOfRange((Bit[]) state, 0, 12));
+ return BitVector.of(Arrays.copyOfRange(QC, 0, 12));
default:
- return super.getHighLevelState(state, stateID);
+ return super.getHighLevelState(QC, stateID);
}
}
@Override
protected Object setHighLevelState(Object lastState, String stateID, Object newHighLevelState)
{
+ Bit[] QC = castAndInitState(lastState);
+
switch (stateID)
{
case "q":
BitVector newHighLevelStateCasted = (BitVector) newHighLevelState;
if (newHighLevelStateCasted.length() != 12)
throw new IllegalArgumentException("Expected BitVector of length 12, not " + newHighLevelStateCasted.length());
- System.arraycopy(newHighLevelStateCasted.getBits(), 0, lastState, 0, 12);
- return lastState;
+ System.arraycopy(newHighLevelStateCasted.getBits(), 0, QC, 0, 12);
+ return QC;
default:
- return super.setHighLevelState(lastState, stateID, newHighLevelState);
+ return super.setHighLevelState(QC, stateID, newHighLevelState);
+ }
+ }
+
+ private static Bit[] castAndInitState(Object lastState)
+ {
+ Bit[] QC = (Bit[]) lastState;
+ if (QC == null)
+ {
+ QC = new Bit[13];
+ Arrays.fill(QC, U);
}
+ return QC;
}
static
@Override
public Object recalculate(Object lastState, Map<String, ReadEnd> readEnds, Map<String, ReadWriteEnd> readWriteEnds)
{
- BitAndInt SPC = (BitAndInt) lastState;
- if (SPC == null)
- {
- SPC = new BitAndInt();
- SPC.bit = U;
- SPC.i = -2;
- }
+ BitAndInt SPC = castAndInitState(lastState);
int SP = SPC.i;
Bit STKI0Val = readEnds.get("STKI0").getValue();
@Override
protected Object getHighLevelState(Object state, String stateID)
{
+ BitAndInt SPC = castAndInitState(state);
+
switch (stateID)
{
case "q":
- return getAsBitVector(((BitAndInt) state).i);
+ return getAsBitVector(SPC.i);
default:
- return super.getHighLevelState(state, stateID);
+ return super.getHighLevelState(SPC, stateID);
}
}
@Override
protected Object setHighLevelState(Object lastState, String stateID, Object newHighLevelState)
{
+ BitAndInt SPC = castAndInitState(lastState);
+
switch (stateID)
{
case "q":
i = -1;// this makes setting to U impossible
if (i > 5)
throw new IllegalArgumentException("Given value not in range (0-5 incl.): " + i);
- ((BitAndInt) lastState).i = i;
- return lastState;
+ SPC.i = i;
+ return SPC;
default:
- return super.setHighLevelState(lastState, stateID, newHighLevelState);
+ return super.setHighLevelState(SPC, stateID, newHighLevelState);
+ }
+ }
+
+ private static BitAndInt castAndInitState(Object lastState)
+ {
+ BitAndInt SPC = (BitAndInt) lastState;
+ if (SPC == null)
+ {
+ SPC = new BitAndInt();
+ SPC.bit = U;
+ SPC.i = -2;
}
+ return SPC;
}
private static class BitAndInt