move InterpreterDestination serial number into the Interpreter class
authormegacz <adam@megacz.com>
Thu, 8 Jan 2009 03:36:18 +0000 (19:36 -0800)
committermegacz <adam@megacz.com>
Thu, 8 Jan 2009 03:36:18 +0000 (19:36 -0800)
src/edu/berkeley/fleet/interpreter/Interpreter.java
src/edu/berkeley/fleet/interpreter/InterpreterDestination.java
src/edu/berkeley/fleet/interpreter/InterpreterDock.java

index 438855b..752ac72 100644 (file)
@@ -11,6 +11,9 @@ import edu.berkeley.fleet.util.*;
 
 public class Interpreter extends FleetTwoFleet implements Parser.FleetWithDynamicShips {
 
+    /** used to allocate serial numbers; see InterpreterDestination for further detail */
+    int maxAllocatedDestinationSerialNumber = 0;
+
     private InterpreterShip debugShip = null;
     private BlockingQueue<BitVector> debugStream = new LinkedBlockingQueue<BitVector>();
     private HashMap<String,InterpreterShip> ships = new HashMap<String,InterpreterShip>();
@@ -77,7 +80,7 @@ public class Interpreter extends FleetTwoFleet implements Parser.FleetWithDynami
     // Instruction Encoding /////////////////////////////////////////////////////////////////////////
 
     public BitVector getDestAddr(Path path) {
-        long ret = ((InterpreterDestination)path.getDestination()).addr;
+        long ret = ((InterpreterDestination)path.getDestination()).getSerialNumber();
         BitVector sig = path.getSignal();
         BitVector bv = new BitVector(DISPATCH_PATH.valmaskwidth+1);
         bv.set(ret);
index 49b56a6..df86579 100644 (file)
@@ -4,18 +4,10 @@ import java.util.*;
 
 abstract class InterpreterDestination extends Destination {
 
-    private static int max_dest = 0;
-
-    int addr;
-
-    private boolean isInstructionDestination;
-
-    public InterpreterDestination(InterpreterDock d, boolean isInstructionDestination) {
+    public InterpreterDestination(InterpreterDock d) {
         super(d);
-        this.isInstructionDestination = isInstructionDestination;
-        synchronized(InterpreterDestination.class) {
-            this.addr = max_dest;
-            max_dest++;
+        synchronized(d.getInterpreter()) {
+            this.serialNumber = d.getInterpreter().maxAllocatedDestinationSerialNumber++;
         }
     }
 
@@ -23,4 +15,14 @@ abstract class InterpreterDestination extends Destination {
     public abstract void addDataFromFabric(Packet packet);
     public abstract String toString();
 
+    /**
+     *  The Fleet instruction encoding mechanism assumes that each
+     *  source->dest path can be turned into a bitstring, and that the
+     *  bitstring gives sufficient information to route the packet.
+     *  Therefore, the interpreter assigns a "serial number" to every
+     *  InterpreterDestination in a fleet and uses the serial number
+     *  of the destination as the path.
+     */
+    private int serialNumber;
+    int getSerialNumber() { return serialNumber; }
 }
index f24bbdf..11774ef 100644 (file)
@@ -51,7 +51,7 @@ class InterpreterDock extends FleetTwoDock {
     // Destinations //////////////////////////////////////////////////////////////////////////////
 
     /** includes the epilogue fifo */
-    public InterpreterDestination instructionDestination = new InterpreterDestination(this, true) {
+    public InterpreterDestination instructionDestination = new InterpreterDestination(this) {
             public String toString() { return getDock()+":i"; }
             public void addDataFromFabric(Packet p) {
                 if (p.isToken()) {
@@ -67,7 +67,7 @@ class InterpreterDock extends FleetTwoDock {
                 }
             }
         };
-    public InterpreterDestination dataDestination = new InterpreterDestination(this, false) {
+    public InterpreterDestination dataDestination = new InterpreterDestination(this) {
             public String toString() { return getDock()+""; }
             public void addDataFromFabric(Packet packet) { dataPackets.add(packet); }
         };