make DataFlowGraph.Node static
authormegacz <adam@megacz.com>
Sun, 15 Mar 2009 01:05:39 +0000 (18:05 -0700)
committermegacz <adam@megacz.com>
Sun, 15 Mar 2009 01:05:39 +0000 (18:05 -0700)
src/edu/berkeley/fleet/dataflow/DataFlowGraph.java

index f7e873f..48a8720 100644 (file)
@@ -50,7 +50,7 @@ public class DataFlowGraph {
             mod.reset(ctx, phase, ackDestination);
     }
 
-    public class Node {
+    public static class Node {
 
         void doReset(Context ctx, int phase, Dock dock, Port peer, Destination ackDestination, boolean peerUsed) {
             if (dock.getShip().getType().equals("Debug")) return;
@@ -130,8 +130,10 @@ public class DataFlowGraph {
             }
         }
 
-        public Node() {
-            DataFlowGraph.this.nodes.add(this);
+        public final DataFlowGraph dfg;
+        public Node(DataFlowGraph dfg) {
+            this.dfg = dfg;
+            dfg.nodes.add(this);
         }
 
         private HashMap<String,Port> ports = new HashMap<String,Port>();
@@ -277,7 +279,7 @@ public class DataFlowGraph {
         }
     }
 
-    private BitVector bv(long l) { return new BitVector(/*FIXME fleet.getWordWidth()*/37).set(l); }
+    private BitVector bv(long l) { return new BitVector(fleet.getWordWidth()).set(l); }
     private BitVector[] bv(long[] l) {
         BitVector[] ret = new BitVector[l.length];
         for(int i=0; i<ret.length; i++) ret[i] = bv(l[i]);
@@ -290,7 +292,7 @@ public class DataFlowGraph {
      *  that every datum sent there is consumed synchronously wiht
      *  data items sent to out.
      */
-    public class ForeverNode extends Node {
+    public static class ForeverNode extends Node {
         private BitVector bv;
         public final OutPort out = new OutPort("out") {
                 public void sendToken(LoopFactory lf) { }
@@ -306,11 +308,11 @@ public class DataFlowGraph {
                     }
                 }
             };
-        public ForeverNode(long l) { this(new BitVector(fleet.getWordWidth()).set(l)); }
-        public ForeverNode(final BitVector bv) { this.bv = bv; }
+        public ForeverNode(DataFlowGraph dfg, long l) { this(dfg, new BitVector(dfg.fleet.getWordWidth()).set(l)); }
+        public ForeverNode(DataFlowGraph dfg, final BitVector bv) { super(dfg); this.bv = bv; }
     }
 
-    public class OnceNode extends Node {
+    public static class OnceNode extends Node {
         private BitVector bv;
         public final OutPort out = new OutPort("out") {
                 public void sendToken(LoopFactory lf) { }
@@ -342,83 +344,84 @@ public class DataFlowGraph {
                     pip.count = 1;
                 }
             };
-        public OnceNode(long l) { this(new BitVector(fleet.getWordWidth()).set(l)); }
-        public OnceNode(final BitVector bv) { this.bv = bv; }
+        public OnceNode(DataFlowGraph dfg, long l) { this(dfg, new BitVector(dfg.fleet.getWordWidth()).set(l)); }
+        public OnceNode(DataFlowGraph dfg, final BitVector bv) { super(dfg); this.bv = bv; }
     }
 
-    public class DebugNode extends Node {
-        public final Ship ship = pool.allocateShip("Debug");
+    public static class DebugNode extends Node {
+        public final Ship ship = dfg.pool.allocateShip("Debug");
         public final InPort in = new DockInPort("in", ship.getDock("in"));
         // NOTE: shutdown needs to treat this specially
-        public DebugNode() { }
+        public DebugNode(DataFlowGraph dfg) { super(dfg); }
     }
 
-    public class UnPunctuatorNode extends Node {
-        private final Ship    ship  = pool.allocateShip("Counter");
+    public static class UnPunctuatorNode extends Node {
+        private final Ship    ship  = dfg.pool.allocateShip("Counter");
         public  final OutPort out   = new DockOutPort("out", ship.getDock("out"));
         public  final InPort  val   = new DockInPort("in1",  ship.getDock("in1"));
-        public  final InPort  count = new DockInPort("in2",  ship.getDock("in2"), 0, new BitVector[] { null, bv(1) });
+        public  final InPort  count = new DockInPort("in2",  ship.getDock("in2"), 0, new BitVector[] { null, dfg.bv(1) });
         public  final InPort  op    = new DockInPort("inOp", ship.getDock("inOp"), 0, new BitVector[] {
                 ship.getDock("inOp").getConstant("PASS_C2_V1"),
                 ship.getDock("inOp").getConstant("DROP_C2_V1") } );
-        public UnPunctuatorNode() { }
+        public UnPunctuatorNode(DataFlowGraph dfg) { super(dfg); }
     }
 
-    public class PunctuatorNode extends Node {
+    public static class PunctuatorNode extends Node {
         private final long    punc;
-        private final Ship    ship  = pool.allocateShip("Counter");
+        private final Ship    ship  = dfg.pool.allocateShip("Counter");
         public  final OutPort out   = new DockOutPort("out", ship.getDock("out"));
         public  final InPort  val   = new DockInPort("in1",  ship.getDock("in1"));
         public  final InPort  op    = new DockInPort("inOp", ship.getDock("inOp"), 0, new BitVector[] {
                 ship.getDock("inOp").getConstant("PASS_C2_V1"),
                 ship.getDock("inOp").getConstant("PASS_C2_V2") } );
         public  final InPort  count;
-        public PunctuatorNode(long punc) {
+        public PunctuatorNode(DataFlowGraph dfg, long punc) {
+            super(dfg);
             this.punc = punc;
-            this.count = new DockInPort("in2",  ship.getDock("in2"), 0, new BitVector[] { null, bv(1), bv(punc) });
+            this.count = new DockInPort("in2",  ship.getDock("in2"), 0, new BitVector[] { null, dfg.bv(1), dfg.bv(punc) });
         }
     }
 
-    public class AluNode extends Node {
-        public final Ship    ship = pool.allocateShip("Alu");
+    public static class AluNode extends Node {
+        public final Ship    ship = dfg.pool.allocateShip("Alu");
         public final InPort  in1 = new DockInPort("in1",  ship.getDock("in1"));
         public final InPort  in2 = new DockInPort("in2",  ship.getDock("in2"));
         public final InPort  inOp = new DockInPort("inOp", ship.getDock("inOp"));
         public final OutPort out  = new DockOutPort("out", ship.getDock("out"));
-        public AluNode() { }
+        public AluNode(DataFlowGraph dfg) { super(dfg); }
     }
 
-    public class DownCounterNode extends Node {
-        public final Ship    ship  = pool.allocateShip("Counter");
+    public static class DownCounterNode extends Node {
+        public final Ship    ship  = dfg.pool.allocateShip("Counter");
         public final InPort  start = new DockInPort("in1",  ship.getDock("in1"));
         public final InPort  incr  = new DockInPort("in2",  ship.getDock("in2"));
         public final InPort  inOp  = new DockInPort("inOp", ship.getDock("inOp"), 0, new BitVector[] {
                 ship.getDock("inOp").getConstant("COUNT") });
         public final OutPort out   = new DockOutPort("out", ship.getDock("out"));
-        public DownCounterNode() { }
+        public DownCounterNode(DataFlowGraph dfg) { super(dfg); }
     }
 
-    public class RepeatNode extends Node {
-        public final Ship    ship   = pool.allocateShip("Counter");
+    public static class RepeatNode extends Node {
+        public final Ship    ship   = dfg.pool.allocateShip("Counter");
         public final InPort  count  = new DockInPort("in1",  ship.getDock("in1"));
         public final InPort  val    = new DockInPort("in2",  ship.getDock("in2"));
         public final InPort  inOP   = new DockInPort("inOp", ship.getDock("inOp"), 0, new BitVector[] {
                 ship.getDock("inOp").getConstant("REPEAT_C1_V2") });
         public final OutPort out    = new DockOutPort("out", ship.getDock("out"));
-        public RepeatNode() { }
+        public RepeatNode(DataFlowGraph dfg) { super(dfg); }
     }
 
-    public class SortedMergeNode extends Node {
-        public final Ship    ship = pool.allocateShip("Alu");
+    public static class SortedMergeNode extends Node {
+        public final Ship    ship = dfg.pool.allocateShip("Alu");
         public final InPort  in1  = new DockInPort("in1",  ship.getDock("in1"));
         public final InPort  in2  = new DockInPort("in2",  ship.getDock("in2"));
         public final InPort  inOp = new DockInPort("inOp", ship.getDock("inOp"), 0, new BitVector[] {
                 ship.getDock("inOp").getConstant("MAXMERGE") });
         public final OutPort out  = new DockOutPort("out", ship.getDock("out"));
-        public SortedMergeNode() { }
+        public SortedMergeNode(DataFlowGraph dfg) { super(dfg); }
     }
 
-    public class MemoryNode extends Node {
+    public static class MemoryNode extends Node {
         public final Ship    ship;
         public final InPort  inCBD;
         public final InPort  inAddrRead1;
@@ -428,7 +431,8 @@ public class DataFlowGraph {
         public final OutPort outRead1;
         public final OutPort outRead2;
         public final OutPort outWrite;
-        public MemoryNode(Ship memoryShip) {
+        public MemoryNode(DataFlowGraph dfg, Ship memoryShip) {
+            super(dfg);
             this.ship = memoryShip;
             this.inCBD        = ship.getType().equals("Memory") ? new DockInPort("inCBD", ship.getDock("inCBD")) : null;
             this.inAddrWrite  = new DockInPort("inAddrWrite", ship.getDock("inAddrWrite"));
@@ -577,51 +581,51 @@ public class DataFlowGraph {
         //////////////////////////////////////////////////////////////////////////////
 
         DataFlowGraph proc = new DataFlowGraph(fleet);
-        DebugNode dm = proc.new DebugNode();
+        DebugNode dm = new DebugNode(proc);
 
         int end_of_data = vals_length;
         int num_strides = end_of_data / (stride_length * 2);
 
-        MemoryNode mm  = proc.new MemoryNode(memoryShip1);
-        SortedMergeNode sm = proc.new SortedMergeNode();
+        MemoryNode mm  = new MemoryNode(proc, memoryShip1);
+        SortedMergeNode sm = new SortedMergeNode(proc);
 
         // So far: we have four spare Counter ships; one can be used for resetting
         for(int i=0; i<2; i++) {
 
-            DownCounterNode c0 = proc.new DownCounterNode();
-            DownCounterNode c1 = proc.new DownCounterNode();
+            DownCounterNode c0 = new DownCounterNode(proc);
+            DownCounterNode c1 = new DownCounterNode(proc);
 
-            c0.start.connect(proc.new ForeverNode(stride_length).out);
-            c0.incr.connect(proc.new ForeverNode(1).out);
+            c0.start.connect(new ForeverNode(proc, stride_length).out);
+            c0.incr.connect(new ForeverNode(proc, 1).out);
 
-            c1.start.connect(proc.new OnceNode(end_of_data + i*stride_length).out);
-            c1.incr.connect(proc.new OnceNode(stride_length*2).out);
+            c1.start.connect(new OnceNode(proc, end_of_data + i*stride_length).out);
+            c1.incr.connect(new OnceNode(proc, stride_length*2).out);
 
-            RepeatNode r1 = proc.new RepeatNode();
+            RepeatNode r1 = new RepeatNode(proc);
             r1.val.connect(c1.out);
-            r1.count.connect(proc.new ForeverNode(stride_length).out);
+            r1.count.connect(new ForeverNode(proc, stride_length).out);
 
-            AluNode alu = proc.new AluNode();
+            AluNode alu = new AluNode(proc);
             alu.in1.connect(r1.out);
             alu.in2.connect(c0.out);
-            alu.inOp.connect(proc.new ForeverNode(((Node.DockInPort)alu.inOp).getConstant("ADD")).out);
+            alu.inOp.connect(new ForeverNode(proc, ((Node.DockInPort)alu.inOp).getConstant("ADD")).out);
             alu.out.connect(i==0 ? mm.inAddrRead1 : mm.inAddrRead2);
 
-            PunctuatorNode punc = proc.new PunctuatorNode(-1);
-            punc.count.connect(proc.new ForeverNode(stride_length).out);
+            PunctuatorNode punc = new PunctuatorNode(proc, -1);
+            punc.count.connect(new ForeverNode(proc, stride_length).out);
             punc.val.connect(i==0 ? mm.outRead1 : mm.outRead2);
             punc.out.connect(i==0 ? sm.in1 : sm.in2);
         }
 
-        UnPunctuatorNode unpunc = proc.new UnPunctuatorNode();
+        UnPunctuatorNode unpunc = new UnPunctuatorNode(proc);
         unpunc.val.connect(sm.out);
-        unpunc.count.connect(proc.new ForeverNode(2*stride_length).out);
+        unpunc.count.connect(new ForeverNode(proc, 2*stride_length).out);
 
-        DownCounterNode cw = proc.new DownCounterNode();
-        cw.start.connect(proc.new OnceNode(end_of_data).out);
-        cw.incr.connect(proc.new OnceNode(1).out);
+        DownCounterNode cw = new DownCounterNode(proc);
+        cw.start.connect(new OnceNode(proc, end_of_data).out);
+        cw.incr.connect(new OnceNode(proc, 1).out);
 
-        MemoryNode mm2 = proc.new MemoryNode(memoryShip2);
+        MemoryNode mm2 = new MemoryNode(proc, memoryShip2);
         mm2.inAddrWrite.connect(cw.out);
         mm2.inDataWrite.connect(unpunc.out);
         mm2.outWrite.connect(dm.in);