move the packet queue out of InterpreterDestination and into InterpreterDock
authormegacz <adam@megacz.com>
Thu, 8 Jan 2009 03:30:56 +0000 (19:30 -0800)
committermegacz <adam@megacz.com>
Thu, 8 Jan 2009 03:30:56 +0000 (19:30 -0800)
src/edu/berkeley/fleet/interpreter/DebugDock.java
src/edu/berkeley/fleet/interpreter/InterpreterDestination.java
src/edu/berkeley/fleet/interpreter/InterpreterDock.java

index e286ea5..75fb8ec 100644 (file)
@@ -30,7 +30,7 @@ public class DebugDock {
     public BitVector getDataLatch()         { return dock.dataLatch; }
     public Queue<BitVector> getDataDestPackets() {
         Queue<BitVector> values = new LinkedList<BitVector>();
-        for (Packet p : dock.dataDestination.packets) {
+        for (Packet p : dock.dataPackets) {
             if (p.isToken())
                 continue;
             values.add(p.getValue());
@@ -40,17 +40,7 @@ public class DebugDock {
     public Queue<Instruction> getInstructionsInFabric() {
         Queue<Instruction> instr = new LinkedList<Instruction>();
 
-        for (Packet p : dock.instructionDestination.packets) {
-            if (p.isToken())
-                continue;
-
-            BitVector bv = p.getValue();
-            long val = 0;
-            for(int i=0; i<bv.length(); i++)
-                if (bv.get(i))
-                    val |= (1L << i);
-            instr.add(dock.getInterpreter().readInstruction(val, dock));
-        }
+        for (Instruction inst : dock.epilogue) instr.add(inst);
 
         return instr;
     }
index 189e2e1..49b56a6 100644 (file)
@@ -2,14 +2,12 @@ package edu.berkeley.fleet.interpreter;
 import edu.berkeley.fleet.api.*;
 import java.util.*;
 
-class InterpreterDestination extends Destination {
+abstract class InterpreterDestination extends Destination {
 
     private static int max_dest = 0;
 
     int addr;
 
-    Queue<Packet> packets = new LinkedList<Packet>();
-
     private boolean isInstructionDestination;
 
     public InterpreterDestination(InterpreterDock d, boolean isInstructionDestination) {
@@ -22,12 +20,7 @@ class InterpreterDestination extends Destination {
     }
 
     /** adds the included datum to the port from the switch fabric side */
-    public void addDataFromFabric(Packet packet) {
-        packets.add(packet);
-    }
-
-    public String toString() {
-        return getDock()+(isInstructionDestination ? ":i" : "");
-    }
+    public abstract void addDataFromFabric(Packet packet);
+    public abstract String toString();
 
 }
index 9e4a692..f24bbdf 100644 (file)
@@ -24,6 +24,7 @@ class InterpreterDock extends FleetTwoDock {
     Instruction executing = null;
     Queue<Instruction> instructions = new LinkedList<Instruction>();
     Queue<Instruction> epilogue = new LinkedList<Instruction>();
+    Queue<Packet> dataPackets = new LinkedList<Packet>();
     boolean dataReadyForShip = false;
     boolean readyForDataFromShip = true;
     long dataFromShip;
@@ -50,8 +51,26 @@ class InterpreterDock extends FleetTwoDock {
     // Destinations //////////////////////////////////////////////////////////////////////////////
 
     /** includes the epilogue fifo */
-    public InterpreterDestination instructionDestination = new InterpreterDestination(this, true);
-    public InterpreterDestination dataDestination = new InterpreterDestination(this, false);
+    public InterpreterDestination instructionDestination = new InterpreterDestination(this, true) {
+            public String toString() { return getDock()+":i"; }
+            public void addDataFromFabric(Packet p) {
+                if (p.isToken()) {
+                    if (torpedoWaiting) throw new RuntimeException("two torpedoes collided!");
+                    torpedoWaiting = true;
+                } else {
+                    BitVector bv = p.getValue();
+                    long val = 0;
+                    for(int i=0; i<bv.length(); i++)
+                        if (bv.get(i))
+                            val |= (1L << i);
+                    epilogue.add(getInterpreter().readInstruction(val, InterpreterDock.this));    
+                }
+            }
+        };
+    public InterpreterDestination dataDestination = new InterpreterDestination(this, false) {
+            public String toString() { return getDock()+""; }
+            public void addDataFromFabric(Packet packet) { dataPackets.add(packet); }
+        };
 
     InterpreterDock(InterpreterShip ship, DockDescription bbd) {
         super(ship, bbd);
@@ -93,21 +112,6 @@ class InterpreterDock extends FleetTwoDock {
 
     protected final void service() {
 
-        if (instructionDestination.packets.size() > 0) {
-            Packet p = instructionDestination.packets.remove();
-            if (p.isToken()) {
-                if (torpedoWaiting) throw new RuntimeException("two torpedoes collided!");
-                torpedoWaiting = true;
-            } else {
-                BitVector bv = p.getValue();
-                long val = 0;
-                for(int i=0; i<bv.length(); i++)
-                    if (bv.get(i))
-                        val |= (1L << i);
-                epilogue.add(getInterpreter().readInstruction(val, this));
-            }
-        }
-
         if (hatchIsOpen && epilogue.size() > 0) {
             Instruction inst = epilogue.remove();
             if (inst instanceof Instruction.Head) {
@@ -165,8 +169,8 @@ class InterpreterDock extends FleetTwoDock {
             }
 
             if (move.dataIn  && !isInputDock() && readyForDataFromShip) return;
-            if (move.dataIn  &&  isInputDock() && dataDestination.packets.size()==0) return;
-            if (move.tokenIn &&                   dataDestination.packets.size()==0) return;
+            if (move.dataIn  &&  isInputDock() && dataPackets.size()==0) return;
+            if (move.tokenIn &&                   dataPackets.size()==0) return;
         }
 
         if (executing.looping && olc>0)
@@ -274,13 +278,13 @@ class InterpreterDock extends FleetTwoDock {
 
         Packet p = null;
         if (move.tokenIn) {
-            p = dataDestination.packets.remove();
+            p = dataPackets.remove();
             if (p.getSignal() != null) flag_c = p.getSignal().get(0);
         }
         if (move.dataIn) {
             BitVector bv = null;
             if (isInputDock()) {
-                p = dataDestination.packets.remove();
+                p = dataPackets.remove();
                 bv = new BitVector(p.getValue());
                 if (p.getSignal() != null) flag_c = p.getSignal().get(0);
             } else {