add Port.getTokensToAbsorb()
authoradam <adam@megacz.com>
Mon, 3 Nov 2008 13:01:31 +0000 (14:01 +0100)
committeradam <adam@megacz.com>
Mon, 3 Nov 2008 13:01:31 +0000 (14:01 +0100)
src/edu/berkeley/fleet/ir/Process.java

index ad27f6a..7527121 100644 (file)
@@ -91,6 +91,8 @@ public class Process {
             public abstract void recvToken(Context.LoopFactory loopfactory_at_output_dock);
             /** this port's peer (an OutPort) invokes this to have "sendWord" or equivalent inserted */
             public abstract void sendWord(Context.LoopFactory loopfactory_at_output_dock);
+
+            public int getTokensToAbsorb() { return 0; }
         }
 
         public abstract class OutPort extends Port {
@@ -129,6 +131,7 @@ public class Process {
             // number-in-flight is considered a property of the input dock in a pair
             //public int getInflight() { return 4; }
             public int getInflight() { return 1; }
+            public int getTokensToAbsorb() { return getInflight(); }
             public void reset(Context ctx, int phase) {
                 if (dock.getShip().getType().equals("Debug")) {
                     return;
@@ -216,13 +219,13 @@ public class Process {
                     case 1: {
                         reset_count++;
                         Context.LoopFactory lf = ctx.new LoopFactory(dock, 1);
-                        if (peer instanceof DockInPort) {
-                            DockInPort dip_peer = (DockInPort)peer;
-                            for(int i=0; i<dip_peer.getInflight(); i++) {
-                                lf.recvToken();
-                            }
-                            //lf.sendToken(dip_peer.dock.getInstructionDestination());
+
+                        //System.out.println("absorbing tokens from " + dip_peer.dock + " to " + dock + "(a "+Module.this.getClass().getName()+")");
+                        for(int i=0; i<peer.getTokensToAbsorb(); i++) {
+                            lf.recvToken();
                         }
+                        //lf.sendToken(dip_peer.dock.getInstructionDestination());
+
                         lf.sendToken(fleet.getShip("Debug",0).getDock("in").getDataDestination());
                         lf = lf.makeNext(0);
                         lf.abortLoopIfTorpedoPresent();
@@ -382,6 +385,7 @@ public class Process {
                     public void recvToken(Context.LoopFactory lf) { lf.recvToken(); }
                     public void sendWord(Context.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) {
                         if (phase==2) {
                             torpedoes.add(ship.getDock("inAddrRead"));
@@ -393,6 +397,7 @@ public class Process {
                     public void recvToken(Context.LoopFactory lf) { lf.recvToken(); }
                     public void sendWord(Context.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) {
                         if (phase==2) {
                             torpedoes.add(ship.getDock("inAddrRead"));