public final ShipPool pool;
private HashSet<Node> nodes = new HashSet<Node>();
- public static int reset_count = 0;
public static HashSet<Dock> torpedoes = new HashSet<Dock>();
public DataFlowGraph(Fleet fleet) {
for(Node mod : nodes)
mod.build(ctx);
}
- public void reset(Context ctx, int phase, Destination ackDestination) {
- reset_count = 0;
+ public int reset(Context ctx, int phase, Destination ackDestination) {
+ int ret = 0;
torpedoes.clear();
for(Node mod : nodes)
- mod.reset(ctx, phase, ackDestination);
+ ret += mod.reset(ctx, phase, ackDestination);
+ return ret;
}
}
public void sendToken(LoopFactory lf) { }
public void recvWord(LoopFactory lf) { }
public void build(Context ctx) { }
- public void reset(Context ctx, int phase, Destination ackDestination) { }
+ public int reset(Context ctx, int phase, Destination ackDestination) { return 0; }
public void setPeer(InPort peer) {
this.peer = peer;
DockInPort pip = ((DockInPort)peer);
public void sendWord(LoopFactory lf) { lf.sendWord(ship.getDock("inAddrRead").getDataDestination(), new BitVector(1).set(0)); }
public void build(Context ctx) { }
public int getTokensToAbsorb() { return outRead1.peer.getTokensToAbsorb(); }
- public void reset(Context ctx, int phase, Destination ackDestination) {
- doReset(ctx, phase, ship.getDock("inAddrRead"), null, ackDestination, false);
+ public int reset(Context ctx, int phase, Destination ackDestination) {
+ return doReset(ctx, phase, ship.getDock("inAddrRead"), null, ackDestination, false);
}
};
this.inAddrRead2 = new InPort("inAddrRead2") {
public void sendWord(LoopFactory lf) { lf.sendWord(ship.getDock("inAddrRead").getDataDestination(), new BitVector(1).set(1)); }
public void build(Context ctx) { }
public int getTokensToAbsorb() { return outRead2.peer.getTokensToAbsorb(); }
- public void reset(Context ctx, int phase, Destination ackDestination) { }
+ public int reset(Context ctx, int phase, Destination ackDestination) { return 0; }
};
this.outRead1 = new OutPort("outRead1") {
public void sendToken(LoopFactory lf) { inAddrRead1.peer.sendToken(lf); }
public void recvWord(LoopFactory lf) { lf.recvWord(); }
public void build(Context ctx) { }
- public void reset(Context ctx, int phase, Destination ackDestination) { }
+ public int reset(Context ctx, int phase, Destination ackDestination) { return 0; }
};
this.outRead2 = new OutPort("outRead2") {
public void sendToken(LoopFactory lf) { inAddrRead2.peer.sendToken(lf); }
public void recvWord(LoopFactory lf) { lf.recvWord(); }
public void build(Context ctx) { }
- public void reset(Context ctx, int phase, Destination ackDestination) { }
+ public int reset(Context ctx, int phase, Destination ackDestination) { return 0; }
};
this.outWrite = new DockOutPort("out", ship.getDock("out")) {
protected void build(Context ctx, LoopFactory lf) {
ctx2 = new Context(fp.getFleet());
Destination ackDestination = counter.getDock("in2").getDataDestination();
- proc.reset(ctx2, phase, ackDestination);
+ int expected_tokens = proc.reset(ctx2, phase, ackDestination);
Context ctx3 = new Context(fp.getFleet());
lf = new LoopFactory(ctx3, counter.getDock("inOp"), 1);
lf.literal(5);
lf.deliver();
lf = new LoopFactory(ctx3, counter.getDock("in1"), 1);
- lf.literal(DataFlowGraph.reset_count-1);
+ lf.literal(expected_tokens-1);
lf.deliver();
lf.literal(1);
lf.deliver();
public class Node {
- void doReset(Context ctx, int phase, Dock dock, Port peer, Destination ackDestination, boolean peerUsed) {
- if (dock.getShip().getType().equals("Debug")) return;
+ int doReset(Context ctx, int phase, Dock dock, Port peer, Destination ackDestination, boolean peerUsed) {
+ int ret = 0;
+ if (dock.getShip().getType().equals("Debug")) return ret;
switch(phase) {
lf = lf.makeNext(0);
lf.abortLoopIfTorpedoPresent();
lf.collectWord();
- DataFlowGraph.reset_count++;
+ ret++;
}
break;
}
((OutPort)peer).recvWord(lf);
((OutPort)peer).sendToken(lf);
}
- DataFlowGraph.reset_count++;
+ ret++;
}
break;
}
for(int i=0; i<((InPort)peer).getTokensToAbsorb(); i++)
lf.recvToken();
lf.sendToken(ackDestination);
- DataFlowGraph.reset_count++;
+ ret++;
}
break;
}
}
LoopFactory lf = new LoopFactory(ctx, dock, 1);
lf.sendToken(ackDestination);
- DataFlowGraph.reset_count++;
+ ret++;
}
break;
}
-
-
}
+ return ret;
}
public final DataFlowGraph dfg;
public OutPort getOutPort(String name) { return (OutPort)ports.get(name); }
public void build(Context ctx) { for(Port p : ports.values()) p.build(ctx); }
- public void reset(Context ctx, int phase, Destination ackDestination) {
- for(Port p : ports.values()) p.reset(ctx, phase, ackDestination);
+ public int reset(Context ctx, int phase, Destination ackDestination) {
+ int ret = 0;
+ for(Port p : ports.values()) ret += p.reset(ctx, phase, ackDestination);
+ return ret;
}
public abstract class Port {
Node.this.ports.put(name,this);
}
public abstract void build(Context ctx);
- public abstract void reset(Context ctx, int phase, Destination ackDestination);
+ public abstract int reset(Context ctx, int phase, Destination ackDestination);
}
public abstract class InPort extends Port {
for(int i=0; i<pattern.length; i++) if (pattern[i]==null) return true;
return false;
}
- public void reset(Context ctx, int phase, Destination ackDestination) {
- doReset(ctx, phase, dock, peer, ackDestination, peerUsed());
+ public int reset(Context ctx, int phase, Destination ackDestination) {
+ return doReset(ctx, phase, dock, peer, ackDestination, peerUsed());
}
protected void build(Context ctx, LoopFactory lf) {
int inflight = (count != 0 && count < getInflight()) ? count : getInflight();
lf.collectWord();
peer.sendWord(lf);
}
- public void reset(Context ctx, int phase, Destination ackDestination) {
- doReset(ctx, phase, dock, peer, ackDestination, true);
+ public int reset(Context ctx, int phase, Destination ackDestination) {
+ return doReset(ctx, phase, dock, peer, ackDestination, true);
}
}
public void sendToken(LoopFactory lf) { }
public void recvWord(LoopFactory lf) { }
public void build(Context ctx) { }
- public void reset(Context ctx, int phase, Destination ackDestination) { }
+ public int reset(Context ctx, int phase, Destination ackDestination) { return 0; }
public void setPeer(InPort peer) {
this.peer = peer;
DockInPort pip = ((DockInPort)peer);