update to AM15
authoradam <adam@megacz.com>
Thu, 25 Jan 2007 13:58:41 +0000 (14:58 +0100)
committeradam <adam@megacz.com>
Thu, 25 Jan 2007 13:58:41 +0000 (14:58 +0100)
21 files changed:
Makefile
contrib/demo.fleet [new file with mode: 0644]
contrib/demo.ships [new file with mode: 0644]
contrib/flow-control-example.fleet [moved from flow-control-example.fleet with 100% similarity]
demo.fleet [deleted file]
demo.ships [deleted file]
fleet.g
src/edu/berkeley/fleet/CodeBag.java
src/edu/berkeley/fleet/DataInbox.java
src/edu/berkeley/fleet/DataOutbox.java
src/edu/berkeley/fleet/Fleet.java
src/edu/berkeley/fleet/FleetParser.java
src/edu/berkeley/fleet/Inbox.java
src/edu/berkeley/fleet/Instruction.java
src/edu/berkeley/fleet/InstructionPort.java
src/edu/berkeley/fleet/Outbox.java
src/edu/berkeley/fleet/Port.java
src/edu/berkeley/fleet/ships/CommandShip.java [new file with mode: 0644]
src/edu/berkeley/fleet/ships/CounterShip.java
src/edu/berkeley/fleet/ships/DebugShip.java
src/edu/berkeley/fleet/ships/FifoShip.java

index 32079e4..1567639 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,11 +3,14 @@ go: fleeterpreter.jar
        java -Xmx500m -cp lib/edu.berkeley.sbp.jar:fleeterpreter.jar edu.berkeley.fleet.FleetParser
 
 code: fleeterpreter.jar
-       java -Xmx500m -cp lib/edu.berkeley.sbp.jar:fleeterpreter.jar edu.berkeley.fleet.FleetParser --dump-code < demo.fleet
+       java -Xmx500m -cp lib/edu.berkeley.sbp.jar:fleeterpreter.jar edu.berkeley.fleet.FleetParser --dump-code < contrib/demo.fleet
 
-fabric: fleeterpreter.jar
-       java -Xmx500m -cp lib/edu.berkeley.sbp.jar:fleeterpreter.jar edu.berkeley.fleet.FleetParser --dump-fabric < demo.fleet > ../fleet/build/fabric.balsa
-       cat ../fleet/build/fabric.balsa
+fabric:
+       make fleeterpreter.jar
+       java -Xmx500m -cp lib/edu.berkeley.sbp.jar:fleeterpreter.jar edu.berkeley.fleet.FleetParser --dump-fabric < contrib/demo.ships | tee ../fleet3/src/fabric.v
+fabric.balsa: fleeterpreter.jar
+       java -Xmx500m -cp lib/edu.berkeley.sbp.jar:fleeterpreter.jar edu.berkeley.fleet.FleetParser --dump-fabric < contrib/demo.ships > fabric.balsa
+       cat fabric.balsa
 
 applet: fleeterpreter.jar
        java -Xmx500m -cp lib/edu.berkeley.sbp.jar:fleeterpreter.jar edu.berkeley.fleet.FleetApplet < test.fleet
diff --git a/contrib/demo.fleet b/contrib/demo.fleet
new file mode 100644 (file)
index 0000000..c16c68b
--- /dev/null
@@ -0,0 +1,47 @@
+#include "contrib/demo.ships"
+
+//22: sendto debug.data
+//22: sendto debug.data
+//alu1.out: ack debug.data
+
+299:        sendto alu2.a
+120:        sendto alu2.b
+0:          sendto alu2.op
+alu2.out:   take, sendto debug.data
+
+
+//22: sendto alu3.b
+
+// route the "max" output to the demux, and that to either
+// the finished-value output (debug.data) or the subtractor
+//sort.max: [*] take, sendto demux1.in
+//                           demux1.false: [*] take, sendto debug.data
+//                           demux1.true:  [*] take, sendto alu.a
+//
+//// route the "min" value to the demux selector to decide if  we are
+//// done; also send copies to the ALU and the secondary sort input
+//sort.min: [*] take, sendto dup3.in
+//                           dup3.a:  [*] take, sendto demux1.select
+//                           dup3.b:  [*] take, sendto alu.b
+//                           dup3.c:  [*] take, sendto sort.b
+//
+//// "plug up" the ALU opcode input with a "1" (subtraction)
+//1: sendto alu.op
+//          alu.op: take [*] accept
+//
+//// route all data emerging from the ALU back to the primary sort input
+//alu.out: [*] take, sendto sort.a
+//
+//// all other inputs are in default mode
+//sort.a:        [*] take, accept
+//sort.b:        [*] take, accept
+//alu.a:         [*] take, accept
+//alu.b:         [*] take, accept
+//dup3.in:       [*] take, accept
+//demux1.select: [*] take, accept
+//demux1.in:     [*] take, accept
+//
+//// gcd(377,221)=13  (we hope!)
+////377: sendto sort.a
+////221: sendto sort.b
+//
diff --git a/contrib/demo.ships b/contrib/demo.ships
new file mode 100644 (file)
index 0000000..f3e1abc
--- /dev/null
@@ -0,0 +1,30 @@
+#import edu.berkeley.fleet.ships
+
+// alu1
+// alu2
+// sort2
+// mux
+// lut
+// dup
+// fifo
+// shifter
+// counter
+
+
+// want: memory, fetch, halt
+
+#ship alu1         : Alu1
+#ship alu2         : Alu2
+#ship debug        : DebugShip
+#ship command      : CommandShip
+
+//#ship command     : CommandShip
+//#ship dup1        : Dup
+//#ship dup2        : Dup
+//#ship dup3        : Dup
+//#ship dup3        : Dup3
+//#ship demux1      : DeMux
+//#ship demux2      : DeMux
+//#ship sort        : Sort2
+
+
diff --git a/demo.fleet b/demo.fleet
deleted file mode 100644 (file)
index 4ca21c5..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#include "demo.ships"
-
-3 -> adder1.a
-3 -> adder1.b
-adder1.out -> adder1.a ; accept adder1.a->()
-3 -> adder1.b
-adder1.out -> debug.data
-accept debug.data -> ()
-
-//4 -> debug.data
-
-
diff --git a/demo.ships b/demo.ships
deleted file mode 100644 (file)
index a255134..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#import edu.berkeley.fleet.ships
-
-#ship debug       : DebugShip
-#ship adder1      : AdderShip
-#ship adder2      : AdderShip
diff --git a/fleet.g b/fleet.g
index 4032e78..5510bff 100644 (file)
--- a/fleet.g
+++ b/fleet.g
@@ -13,25 +13,20 @@ s               = ws! Program ws!
 Program         = Program:: Directive+/ws
                 | Program:: (Directive+/ws) ws! CodeBagBody
 
-Statement       = Instruction:: (Opcode ws!)? Source ws! Arrow ws! Port
+Statement       = Fiber:: Source ws! ":" ws! (Instruction +/ ws)
+                | Literal:: int ":" "sendto" Port /ws
                 | NamedCodeBag:: name ":" "{" CodeBagBody "}" /ws
 
-Opcode          = Triggered::   "triggered" OpcodeBody /ws
-                | UnTriggered::             OpcodeBody
-
-OpcodeBody      = ^"nop"        | ^"wait"     | ^"discard"     
-                | ^"nop+ack"    | ^"wait+ack" | ^"discard+ack" 
-                | ^"copy"       | ^"move"     | ^"accept"
-                | ^"copy+ack"   | ^"move+ack" | ^"accept+ack"
-                | ^"synthesize" | ^"synthesize+ack"
-
-Arrow           = ^"->"
-                | ^"-[*]->"
-                | ^"-[" int "]->"
+Instruction     = Instruction:: ("[" (int|(Star::"*")) "]" ws!)? (Command +/ (ws! "," ws!))
+Command         = Wait::    "wait"
+                | Discard:: "discard"
+                | Take::    "take"
+                | SendTo::  "sendto" ws! Port
+                | Accept::  "accept"
+                | Ack::     "ack" ws! Port
 
 Source         = Port
                | CodeBag
-               | int
                | ShipSpecific
 
 Port           = Port::     shipname "." portname
@@ -41,9 +36,9 @@ CodeBagBody    = Statement +/ (ws (";" ws)?!)
 CodeBag        = CodeBagRef:: CodeBagName
                | AnonymousCodeBag:: "{" CodeBagBody "}" /ws
 
-CodeBagName    = name &~ Opcode
-shipname       = name &~ Opcode
-portname       = name &~ Opcode
+CodeBagName    = name
+shipname       = name
+portname       = name
 name           = Name:: [A-Za-z] [A-Za-z0-9\[\]_]**
 index          = "[" [0-9]+ "]" | [0-9]+
 int            = [\-0-9]++
@@ -55,5 +50,5 @@ ShipSpecific   = ShipSpecific:: "\"" ~[\"]++ "\""
 Directive      = Memory::  "#memory" "{" (int +/ (ws! "," ws!)) "}" /ws
                | Import::  "#import" [A-Za-z_.]++ /ws
                | Include:: "#include" ("\"" (~[\"])+ "\"") /ws
-               | Ship::    "#ship" shipname ":" [A-Za-z_.]++ /ws
+               | Ship::    "#ship" shipname ":" [0-9A-Za-z_.]++ /ws
 
index 0173781..b267ed5 100644 (file)
@@ -2,7 +2,6 @@ package edu.berkeley.fleet;
 
 import java.util.*;
 import java.io.*;
-import static edu.berkeley.fleet.Instruction.IgnoreCopyTake;
 
 /** a codebag */
 public class CodeBag {
@@ -55,46 +54,53 @@ public class CodeBag {
         return parent.getCodeBag(name);
     }
 
-    public void dump(OutputStream os, int data) throws Exception {
+    public void dump(OutputStream os, long data_) throws Exception {
+        int data = (int)data_;
         os.write((byte)data);
-        System.out.print(data+" ");
+        //System.out.println("0x"+Integer.toString(data,16)+" ");
+        System.out.println(data);
     }
     public void dump(Fleet fleet) throws Exception {
         OutputStream os = new FileOutputStream("fleet.bin");
+
         for(Dispatchable d : dispatchables) {
             if (d instanceof Instruction) {
                 Instruction inst = (Instruction)d;
-                dump(os, inst.source.resolve(fleet).instr_bits);
-                dump(os, inst.source.resolve(fleet).instr_addr);
-                dump(os, 1); dump(os, inst.trigger ? 1 : 0);
-                dump(os, 1); dump(os, inst.dataIn != IgnoreCopyTake.IGNORE ? 1 : 0);
-                dump(os, 1); dump(os, inst.dataIn == IgnoreCopyTake.COPY ? 1 : 0);
-                dump(os, 1); dump(os, inst.dataOut ? 1 : 0);
-                dump(os, 1); dump(os, inst.ack ? 1 : 0);
-                if (inst.destination != null) {
-                    dump(os, inst.destination.resolve(fleet).bits);
-                    dump(os, inst.destination.resolve(fleet).addr);
-                }
-                dump(os, 0);
-                System.out.println();
+
+                long instr = inst.destination.resolve(fleet).addr << 1;
+
+                instr |= (((long)inst.count) << (11+1));
+                if (inst.ack)     instr |= (1L << (11+1+7+0));
+                if (inst.dataOut) instr |= (1L << (11+1+7+1));
+                if (inst.latch)   instr |= (1L << (11+1+7+2));
+                if (inst.dataIn)  instr |= (1L << (11+1+7+3));
+                if (inst.trigger) instr |= (1L << (11+1+7+4));
+                instr |= ((long)inst.source.resolve(fleet).instr_addr) << (11+5+7+1);
+                // 1111 00001 0000001 00000001110 0
+                // 1111 00001 0000001 00000001110 0
+                //  110000010000001000000011100
+                long out = 0;
+                out |= new PortReference("command", "data").resolve(fleet).addr;
+                out |= instr << 11;
+                dump(os, (out >> (5*8)) & 0xff);
+                dump(os, (out >> (4*8)) & 0xff);
+                dump(os, (out >> (3*8)) & 0xff);
+                dump(os, (out >> (2*8)) & 0xff);
+                dump(os, (out >> (1*8)) & 0xff);
+                dump(os, (out >> (0*8)) & 0xff);
             } else if (d instanceof Literal.LiteralDatum) {
                 Literal.LiteralDatum ld = (Literal.LiteralDatum)d;
-                dump(os, ld.destination.resolve(fleet).instr_bits);
-                dump(os, ld.destination.resolve(fleet).instr_addr);
-                dump(os, 5);
-                dump(os, 2);
-                dump(os, 32);
-                dump(os, (ld.data >> 24) & 0xff);
-                dump(os, (ld.data >> 16) & 0xff);
-                dump(os, (ld.data >> 8) & 0xff);
-                dump(os, (ld.data >> 0) & 0xff);
-                //dump(os, 0xff);
-                //dump(os, 0xff);
-                //dump(os, 0xff);
-                //dump(os, 0xff);
-                dump(os, 0);
-                System.out.println();
+                long out = 0;
+                out |= ld.destination.resolve(fleet).addr;
+                out |= ((long)ld.data) << 11;
+                dump(os, (out >> (5*8)) & 0xff);
+                dump(os, (out >> (4*8)) & 0xff);
+                dump(os, (out >> (3*8)) & 0xff);
+                dump(os, (out >> (2*8)) & 0xff);
+                dump(os, (out >> (1*8)) & 0xff);
+                dump(os, (out >> (0*8)) & 0xff);
             }
+
         }
         os.flush();
         os.close();
index b0afd28..77f7133 100644 (file)
@@ -1,6 +1,5 @@
 package edu.berkeley.fleet;
 
-import static edu.berkeley.fleet.Instruction.IgnoreCopyTake.*;
 import java.util.*;
 
 public class DataInbox extends Inbox {
@@ -8,6 +7,11 @@ public class DataInbox extends Inbox {
     public DataInbox(Ship ship, String name) {
         super(ship, name);
     }
+    public DataInbox(Ship ship, String name, boolean noInbox, boolean noChannelDef) {
+        super(ship, name);
+        this.noInbox = noInbox;
+        this.noChannelDef = noChannelDef;
+    }
 
     void addDataFromFabric(int data) {
         addItemFromFabric(data);
index 8e2f828..e7859fa 100644 (file)
@@ -1,11 +1,10 @@
 package edu.berkeley.fleet;
-import static edu.berkeley.fleet.Instruction.IgnoreCopyTake.*;
 
 public class DataOutbox extends Outbox {
 
-    public DataOutbox(Ship ship, String name) {
-        super(ship, name);
-    }
+    public DataOutbox(Ship ship, String name) { super(ship, name); }
+    public DataOutbox(Ship ship, String name, boolean special) {
+        super(ship, name); this.special = special; }
 
     public void addDataFromShip(int data) {
         addItemFromShip(data);
index ef2e71f..13e53eb 100644 (file)
@@ -93,17 +93,17 @@ public class Fleet {
         ArrayList instructionports = new ArrayList<Port>();
         for(Ship ship : shiplist)
             for(Port port : ship.portlist)
-                if (!(port.getName().equals("out") && port.getShip() instanceof DebugShip))
+                if (!port.special())
                     instructionports.add(port);
         FabricTree instructions =
             new FabricTree((Port[])instructionports.toArray(new Port[0]),
-                           "horn",
+                           "ihorn",
                            "instruction");
 
         ArrayList inputports = new ArrayList<Port>();
         for(Ship ship : shiplist)
             for(Port port : ship.portlist)
-                if (!(port.getName().equals("out") && port.getShip() instanceof DebugShip))
+                if (!port.special())
                     inputports.add(port);
         FabricTree inputs =
             new FabricTree((Port[])inputports.toArray(new Port[0]),
@@ -113,7 +113,7 @@ public class Fleet {
         ArrayList outputports = new ArrayList<Port>();
         for(Ship ship : shiplist)
             for(Port port : ship.portlist)
-                if (!(port.getName().equals("out") && port.getShip() instanceof DebugShip))
+                if (!port.special())
                     outputports.add(port);
         FabricTree outputs =
             new FabricTree((Port[])outputports.toArray(new Port[0]),
@@ -121,32 +121,39 @@ public class Fleet {
                            "source");
 
         if (quiet) return;
-        System.out.println("import [balsa.sim.portio]");
-        System.out.println("import [xbit]");
-        System.out.println("import [funnel]");
-        System.out.println("import [horn]");
-        System.out.println("import [par2ser]");
-        System.out.println("import [ser2par]");
-
+        System.out.println("`include \"macros.v\"");
+        /*
         HashSet<Class> added = new HashSet<Class>();
         for(Ship ship : shiplist)
             if (!added.contains(ship.getClass())) {
                 added.add(ship.getClass());
                 System.out.println("import ["+ship.getBalsaName()+"]");
             }
+        */
+        System.out.println("module fabric(clk, top_r, top_a, top,");
+        System.out.println("                   data_debug_out_r, data_debug_out_a, data_debug_out);");
+        System.out.println("  input  clk;");
+        System.out.println("  input  top_r;");
+        System.out.println("  output top_a;");
+        System.out.println("  input  [(`PACKET_WIDTH-1):0] top;");
+        //        System.out.println("  wire   [(`PACKET_WIDTH-1):0] dest;");
+        System.out.println("  output data_debug_out_r;");
+        System.out.println("  input  data_debug_out_a;");
+        System.out.println("  output [(`PACKET_WIDTH-1):0] data_debug_out;");
+        System.out.println("  wire   [(`INSTRUCTION_WIDTH-1):0] data_command_out;");
+        System.out.println();
+        
+        System.out.println();
 
-        System.out.println("procedure fabric(input top_in:XBit; output top_out:XBit)");
-        System.out.println("is");
         instructions.dumpChannels(true);
         outputs.dumpChannels(true);
         inputs.dumpChannels(true);
         for(Ship ship : shiplist)
-            for(Port port : ship.portlist)
-                System.out.println("  channel data_"+ship.getName()+"_"+port.getName()+" : XBit");
-        System.out.println("begin");
-        System.out.println("     loop source -> dest end");
-        System.out.println("  || loop top_in -> instruction end");
-        System.out.println("  || loop data_debug_out -> top_out end");
+            for(Port port : ship.portlist) {
+                if (ship instanceof CommandShip && port instanceof Outbox) continue;
+                System.out.println("  wire [(`PACKET_WIDTH-1):0] data_"+ship.getName()+"_"+port.getName()+";");
+            }
+
         System.out.println("");
         instructions.dumpChannels(false);
         System.out.println("");
@@ -155,39 +162,55 @@ public class Fleet {
         inputs.dumpChannels(false);
         System.out.println("");
         for(Ship ship : shiplist) {
-            System.out.print("  || ");
             System.out.print(ship.getBalsaName());
-            System.out.print("(");
+            System.out.print(" ");
+            System.out.print("krunk"+(krunk++));
+            System.out.print("(clk, ");
             boolean first = true;
             for(Port port : ship.portlist) {
                 if (!first) System.out.print(", ");
                 first = false;
+                System.out.print("data_"+port.getShip().getName()+"_"+port.getName()+"_r, ");
+                System.out.print("data_"+port.getShip().getName()+"_"+port.getName()+"_a, ");
                 System.out.print("data_"+port.getShip().getName()+"_"+port.getName());
                 System.out.print(" ");
             }
-            System.out.println(")");
+            System.out.println(");");
 
             for(Port port : ship.portlist) {
-                if (ship instanceof DebugShip && port instanceof Outbox)
-                    continue;
-                System.out.print("  || ");
-                if (port instanceof Inbox)
-                    System.out.print("inbox(");
-                else
-                    System.out.print("outbox(");
-                System.out.print("instruction_"+port.getShip().getName()+"_"+port.getName());
-                System.out.print(", ");
-                System.out.print("dest_"+port.getShip().getName()+"_"+port.getName());
-                System.out.print(", ");
-                System.out.print("source_"+port.getShip().getName()+"_"+port.getName());
-                System.out.print(", ");
+                if (port.special()) continue;
+                if (port instanceof Inbox) {
+                    if (port.noInbox())
+                        System.out.print("stupidinbox");
+                    else
+                        System.out.print("inbox");
+                } else {
+                    System.out.print("outbox");
+                }
+                System.out.print(" krunk"+(krunk++)+"(clk, ");
+                System.out.print("instruction_"+port.getShip().getName()+"_"+port.getName()+"_r, ");
+                System.out.print("instruction_"+port.getShip().getName()+"_"+port.getName()+"_a, ");
+                System.out.print("instruction_"+port.getShip().getName()+"_"+port.getName()+", ");
+                System.out.print("dest_"+port.getShip().getName()+"_"+port.getName()+"_r, ");
+                System.out.print("dest_"+port.getShip().getName()+"_"+port.getName()+"_a, ");
+                System.out.print("dest_"+port.getShip().getName()+"_"+port.getName()+", ");
+                System.out.print("source_"+port.getShip().getName()+"_"+port.getName()+"_r, ");
+                System.out.print("source_"+port.getShip().getName()+"_"+port.getName()+"_a, ");
+                System.out.print("source_"+port.getShip().getName()+"_"+port.getName()+", ");
+                System.out.print("data_"+port.getShip().getName()+"_"+port.getName()+"_r, ");
+                System.out.print("data_"+port.getShip().getName()+"_"+port.getName()+"_a, ");
                 System.out.print("data_"+port.getShip().getName()+"_"+port.getName());
-                System.out.print(")");
+                System.out.print(");");
                 System.out.println();
             }
 
         }
-        System.out.println("end");
+        System.out.println("funnel topfun(clk, dest_r, dest_a, dest, source_r, source_a, source, top_r, top_a, top);");
+        System.out.println("");
+        System.out.println("  assign instruction_r      = data_command_out_r;");
+        System.out.println("  assign data_command_out_a = instruction_a;");
+        System.out.println("  assign instruction        = data_command_out;");
+        System.out.println("endmodule");
     }
 
     private static class FabricTree {
@@ -215,8 +238,8 @@ public class Fleet {
             int len = end-start;
             return new Node(name,
                             component,
-                            mkNode(name+"_0", component, ports, start, start+len/2, (addr<<1)|0, bits+1),
-                            mkNode(name+"_1", component, ports, start+len/2, end, (addr<<1)|1, bits+1),
+                            mkNode(name+"_0", component, ports, start, start+len/2, addr, bits+1),
+                            mkNode(name+"_1", component, ports, start+len/2, end,   addr | (1 << bits), bits+1),
                             addr,
                             bits);
         }
@@ -250,12 +273,22 @@ public class Fleet {
                 String indent = "";
                 for(int i=0; i<indentamount; i++) indent += "  ";
                 if (decl) {
-                    System.out.println("  channel "+indent+describe(prefix)+" : XBit");
+                    String n = describe(prefix).startsWith("instruction") ? "[(`INSTRUCTION_WIDTH-1):0]" : "[(`PACKET_WIDTH-1):0]";
+                    System.out.println("  wire "+n+" "+indent+describe(prefix)+";");
                 } else {
-                    System.out.println("  || "+indent+
-                                       component+"("+describe(prefix)+
-                                       ", "+FabricTree.this.describe(prefix, left)+
-                                       ", "+FabricTree.this.describe(prefix, right)+")");
+                    System.out.println("     "+indent+
+                                       component+" "+
+                                       "krunk"+(krunk++)+"(clk, "+
+                                       describe(prefix)+"_r, "+
+                                       describe(prefix)+"_a, "+
+                                       describe(prefix)+", "+
+                                       FabricTree.this.describe(prefix, left)+"_r, "+
+                                       FabricTree.this.describe(prefix, left)+"_a, "+
+                                       FabricTree.this.describe(prefix, left)+", "+
+                                       FabricTree.this.describe(prefix, right)+"_r, "+
+                                       FabricTree.this.describe(prefix, right)+"_a, "+
+                                       FabricTree.this.describe(prefix, right)+
+                                       ");");
                 }
                 dumpChannels(left, indentamount+1, decl);
                 dumpChannels(right, indentamount+1, decl);
@@ -267,8 +300,11 @@ public class Fleet {
                 } else {
                     String indent = "";
                     for(int i=0; i<indentamount; i++) indent += "  ";
-                    if (decl)
-                        System.out.println("  channel "+indent+FabricTree.this.describe(prefix,o)+" :XBit");
+                    if (decl) {
+                        String n = FabricTree.this.describe(prefix,o).startsWith("instruction")
+                            ? "[(`INSTRUCTION_WIDTH-1):0]" : "[(`PACKET_WIDTH-1):0]";
+                        System.out.println("  wire "+n+" "+indent+FabricTree.this.describe(prefix,o)+";");
+                    }
                 }
             }
             public String describe(String prefix) {
@@ -276,5 +312,5 @@ public class Fleet {
             }
         }
     }
-
+    public static int krunk=0;
 }
index 0448252..209889c 100644 (file)
@@ -8,7 +8,6 @@ import edu.berkeley.sbp.bind.*;
 import edu.berkeley.sbp.util.*;
 import java.util.*;
 import java.io.*;
-import static edu.berkeley.fleet.Instruction.IgnoreCopyTake.*;
 
 /**
  *  @author Adam Megacz <megacz@cs.berkeley.edu>
@@ -37,16 +36,6 @@ public class FleetParser {
                 dump_code = true;
                 continue;
 
-            } else if (s[i].startsWith("--inboxes=")) {
-                String val = s[i].substring(s[i].indexOf('=')+1);
-                if (val.equals("configured")) {
-                    DataInbox.defaultInstruction =
-                        new Instruction(null, null, Integer.MAX_VALUE, TAKE, false, false, true);
-                    continue;
-                } else if (val.equals("unconfigured")) {
-                    DataInbox.defaultInstruction = null;
-                    continue;
-                }
             } else if (s[i].startsWith("--memory=")) {
                 String val = s[i].substring(s[i].indexOf('=')+1);
                 if (val.equals("hide")) {
@@ -184,19 +173,42 @@ public class FleetParser {
             for(Tree<String> statement : t.child(1))
                 fillCodeBag(statement, cb2);
 
-        } else if (t.head().equals("Instruction")) {
-            Tree<String> opcode = t.child(0);
-            boolean trigger = opcode != null && opcode.size()>0 && "Triggered".equals(opcode.child(0).head());
+        } else if (t.head().equals("Literal")) {
+            int literal = Integer.parseInt(string(t.child(0)));
+            PortReference benkobox = portReference(t.child(1));
+            cb.add(new Literal.LiteralDatum(literal, benkobox, false, 1));
 
-            int count = 0;
-            Tree arrow = t.child(2);
-            if      (arrow.head().equals("->"))     count = 1;
-            else if (arrow.head().equals("-[*]->")) count = Integer.MAX_VALUE;
-            else if (arrow.head().equals("-["))     count = Integer.parseInt(string(arrow.child(0)));
-
-            Tree opcodebody = opcode.size()==0 ? null : opcode.child(0).child(opcode.size()-1);
+        } else if (t.head().equals("Fiber")) {
+            PortReference benkobox = portReference(t.child(0));
             
-            PortReference d = portReference(t.child(3));
+            for(Tree tt : t.child(1)) {
+                int count = 1;
+                Tree ttx = null;
+                if (tt.size() > 1 && tt.child(0).size()>0) {
+                    System.out.println(tt.child(0));
+                    if (tt.child(0).size() > 0 && "Star".equals(tt.child(0).child(0).head())) count=Integer.MAX_VALUE;
+                    else count = Integer.parseInt(string(tt.child(0)));
+                }
+                ttx = tt.child(1);
+                boolean tokenIn = false;
+                boolean dataIn = false;
+                boolean latch = false;
+                boolean dataOut = false;
+                boolean tokenOut = false;
+                PortReference dest = null;
+                for(int i=0; i<ttx.size(); i++) {
+                    Tree ttt = ttx.child(i);
+                    if      ("Wait".equals(ttt.head()))    { tokenIn = true; }
+                    else if ("Discard".equals(ttt.head())) { dataIn = true; latch = false; }
+                    else if ("Take".equals(ttt.head()))    { dataIn = true; latch = true; }
+                    else if ("SendTo".equals(ttt.head()))  { dataOut = true; dest = portReference(ttt.child(0)); }
+                    else if ("Accept".equals(ttt.head()))  { dataOut = true;  }
+                    else if ("Ack".equals(ttt.head()))     { tokenOut = true; dest = portReference(ttt.child(0)); }
+                }
+                cb.add(new Instruction(benkobox, dest, count, dataIn, latch, tokenOut, tokenIn, dataOut));
+            }
+        }
+            /*
             if (t.child(1).head() == null) {
                 int literal = Integer.parseInt(string(t.child(1)));
                 cb.add(new Literal.LiteralDatum(literal, d, false, count));
@@ -212,28 +224,6 @@ public class FleetParser {
 
             } else if ("ShipSpecific".equals(t.child(1).head())) {
                 cb.add(new Literal.ShipSpecific(string(t.child(1).child(0)), d, count));
-
-            } else {
-                PortReference s = portReference(t.child(1));
-                Instruction inst = null;
-                if (opcodebody==null)         inst = new Instruction(s, d, count, TAKE,   false,  trigger, true);
-                else if (opcodebody.head().equals("nop"))            inst = new Instruction(s, d, count, IGNORE, false,  trigger, false);
-                else if (opcodebody.head().equals("synthesize"))     inst = new Instruction(s, d, count, IGNORE, false,  trigger, true);
-                else if (opcodebody.head().equals("synthesize+ack")) inst = new Instruction(s, d, count, IGNORE, true,   trigger, true);
-                else if (opcodebody.head().equals("wait"))           inst = new Instruction(s, d, count, COPY,   false,  trigger, false);
-                else if (opcodebody.head().equals("discard"))        inst = new Instruction(s, d, count, TAKE,   false,  trigger, false);
-                else if (opcodebody.head().equals("nop+ack"))        inst = new Instruction(s, d, count, IGNORE, true,   trigger, false);
-                else if (opcodebody.head().equals("wait+ack"))       inst = new Instruction(s, d, count, COPY,   true,   trigger, false);
-                else if (opcodebody.head().equals("discard+ack"))    inst = new Instruction(s, d, count, TAKE,   true,   trigger, false);
-                else if (opcodebody.head().equals("copy"))           inst = new Instruction(s, d, count, COPY,   false,  trigger, true);
-                else if (opcodebody.head().equals("copy+ack"))       inst = new Instruction(s, d, count, COPY,   true,   trigger, true);
-                else if (opcodebody.head().equals("move"))           inst = new Instruction(s, d, count, TAKE,   false,  trigger, true);
-                else if (opcodebody.head().equals("move+ack"))       inst = new Instruction(s, d, count, TAKE,   true,   trigger, true);
-                else if (opcodebody.head().equals("accept"))         inst = new Instruction(s, d, count, TAKE,   false,  trigger, true);
-                else if (opcodebody.head().equals("accept+ack"))     inst = new Instruction(s, d, count, TAKE,   true,   trigger, true);
-                cb.add(inst);
-            }
-        }
+            */
     }
-
 }
index 795fa06..ad8492f 100644 (file)
@@ -1,14 +1,11 @@
 package edu.berkeley.fleet;
 
-import static edu.berkeley.fleet.Instruction.IgnoreCopyTake.*;
 import java.util.*;
 
 /** this is a generic inbox which stores <32-bit items (tokens or data) */
 public class Inbox extends InstructionPort {
 
-    static Instruction defaultInstruction =
-        new Instruction(null, null, Integer.MAX_VALUE, TAKE, false, false, true);
-
+    static Instruction defaultInstruction = null;
 
     // private data //////////////////////////////////////////////////////////////////////////////
 
@@ -16,7 +13,7 @@ public class Inbox extends InstructionPort {
     private Queue<Integer> itemsFromFabric = new LinkedList<Integer>();
 
     /** a datum which has been presented to the ship */
-    private int itemPresentedToShip;
+    //private int itemPresentedToShip;
 
     /** true iff data is currently being presented to the ship */
     private boolean itemReadyForShip = false;
@@ -54,9 +51,10 @@ public class Inbox extends InstructionPort {
             getFleet().sendToken(this, ackDestinationUponAccept);
             ackDestinationUponAccept = null;
         }
-        return itemPresentedToShip;
+        return register;
     }
 
+    int register = 0;
     /** invoked by superclass */
     protected final boolean service(Instruction instruction) {
 
@@ -71,16 +69,14 @@ public class Inbox extends InstructionPort {
         if (instruction.trigger)
             throw new RuntimeException("invalid instruction: " + instruction +
                                        " (attempts to use trigger on an inbox)");
-        if (instruction.dataIn != IGNORE && itemsFromFabric.size()==0) return false;
+        if (instruction.dataIn && itemsFromFabric.size()==0) return false;
 
         // consume inbound data+token
-        switch(instruction.dataIn) {
-            case COPY:
-                itemPresentedToShip = itemsFromFabric.peek();
-                break;
-            case TAKE:
-                itemPresentedToShip = itemsFromFabric.remove();
-                break;
+        if (instruction.dataIn) {
+            if (instruction.latch)
+                register = itemsFromFabric.remove();
+            else
+                itemsFromFabric.remove();
         }
 
         // if dataOut, present data to the ship
@@ -100,10 +96,11 @@ public class Inbox extends InstructionPort {
     }
 
     protected void shutdown() {
+        /*
         if (itemReadyForShip)
-            Log.println(Log.red(" WARNING: a datum ("+itemPresentedToShip+") was left in inbox " +
+            Log.println(Log.red(" WARNING: a datum ("+register+") was left in inbox " +
                                 this + " -- the ship has not consumed it"));
-                        
+        */              
         if (itemsFromFabric.size() > 0) {
             Log.println(Log.red(" WARNING: you left data on the input to inbox " + this + ":"));
             for(int i : itemsFromFabric)
index 369c37e..400b865 100644 (file)
@@ -6,27 +6,42 @@ public class Instruction extends Dispatchable {
     public final PortReference source;
     public final PortReference destination;
     public final int count;
-    public final IgnoreCopyTake dataIn;
-    public final boolean ack;
+
     public final boolean trigger;
+    public final boolean dataIn;
+    public final boolean latch;
     public final boolean dataOut;
-
-    public static enum IgnoreCopyTake { IGNORE, COPY, TAKE };
+    public final boolean ack;
+    public final boolean recycle;
 
     public Instruction(PortReference source,
                        PortReference destination,
                        int count,
-                       IgnoreCopyTake dataIn,
+                       boolean dataIn,
+                       boolean latch,
                        boolean ack,
                        boolean trigger,
                        boolean dataOut) {
+        this(source, destination, count, dataIn, latch, ack, trigger, dataOut, false);
+    }
+    public Instruction(PortReference source,
+                       PortReference destination,
+                       int count,
+                       boolean dataIn,
+                       boolean latch,
+                       boolean ack,
+                       boolean trigger,
+                       boolean dataOut,
+                       boolean recycle) {
         this.source = source;
         this.destination = destination;
         this.count = count;
         this.dataIn = dataIn;
+        this.latch = latch;
         this.ack = ack;
         this.trigger = trigger;
         this.dataOut = dataOut;
+        this.recycle = recycle;
         if (count <= 0)
             throw new RuntimeException("count field of an instruction must be >0");
     }
@@ -40,29 +55,20 @@ public class Instruction extends Dispatchable {
 
     public String toString() {
         StringBuffer ret = new StringBuffer();
-        if (trigger) ret.append("triggered ");
-        switch(dataIn) {
-            case IGNORE:
-                ret.append(dataOut ? "synthesize" : "nop");
-                break;
-            case COPY:
-                ret.append(dataOut ? "copy" : "wait");
-                break;
-            case TAKE:
-                ret.append(dataOut ? "move" : "discard");
-                break;
-        }
-        if (ack) ret.append("+ack");
-        ret.append(" ");
         ret.append(source);
-        ret.append(" ");
+        ret.append(": ");
+        boolean more=false;
         switch(count) {
-            case 1:                 ret.append("->"); break;
-            case Integer.MAX_VALUE: ret.append("-[*]->"); break;
-            default:                ret.append("-["+count+"]->"); break;
+            case 1: break;
+            case Integer.MAX_VALUE: ret.append("[*] ");
+            default: ret.append("["+count+"] ");
         }
-        ret.append(" ");
-        ret.append(destination);
+        if (trigger)               { ret.append("wait"); more=true; }
+        if (dataIn &&  latch)      { if (more) ret.append(", "); ret.append("take"); more = true; }
+        if (dataIn && !latch)      { if (more) ret.append(", "); ret.append("discard"); more = true; }
+        if (dataOut && destination!=null) { if (more) ret.append(", "); ret.append("sendto "+destination); more = true; }
+        if (dataOut && destination==null) { if (more) ret.append(", "); ret.append("accept"); more = true; }
+        if (ack)              { if (more) ret.append(", "); ret.append("ack "+destination); more = true; }
         return ret.toString();
     }
 }
index 14638ce..7f9db45 100644 (file)
@@ -38,6 +38,7 @@ public abstract class InstructionPort extends Port {
                 Log.println(Log.red(" WARNING: you did not leave a standing move on inbox-port " + this));
                 return;
             }
+            /*
             if (currentlyExecuting.count != Integer.MAX_VALUE
                 || currentlyExecuting.dataIn != Instruction.IgnoreCopyTake.TAKE
                 || currentlyExecuting.ack
@@ -48,6 +49,7 @@ public abstract class InstructionPort extends Port {
                             );
                 return;
             }
+            */
             currentlyExecuting = null;
         }
         if (currentlyExecuting != null || instructions.size() > 0) {
index ba089bb..f6fa424 100644 (file)
@@ -1,5 +1,4 @@
 package edu.berkeley.fleet;
-import static edu.berkeley.fleet.Instruction.IgnoreCopyTake.*;
 
 public abstract class Outbox extends InstructionPort {
 
@@ -24,6 +23,7 @@ public abstract class Outbox extends InstructionPort {
         triggersReceived++;
     }
 
+    int register;
     protected final boolean service(Instruction instruction) {
 
         // if no instruction waiting, do nothing
@@ -31,27 +31,22 @@ public abstract class Outbox extends InstructionPort {
 
         // check firing conditions
         if (instruction.trigger && triggersReceived <= 0) return false;
-        if (instruction.dataIn != IGNORE && readyForItemFromShip) return false;
+        if (instruction.dataIn && readyForItemFromShip) return false;
         
         // consume trigger
         if (instruction.trigger) triggersReceived--;
 
         // consume item
-        int data = 0;
-        switch(instruction.dataIn) {
-            case COPY:
-                data = itemPresentedByShip;
-                break;
-            case TAKE:
-                data = itemPresentedByShip;
-                readyForItemFromShip = true;
-                break;
+        if (instruction.dataIn) {
+            readyForItemFromShip = true;
+            if (instruction.latch) 
+                register = itemPresentedByShip;
         }
 
         if (instruction.dataOut) {
 
             // if item to be transmitted, send it
-            send(instruction.destination.resolve(getShip().getFleet()), data);
+            send(instruction.destination.resolve(getShip().getFleet()), register);
             if (instruction.ack)
                 throw new RuntimeException("outboxes may not send acks!");
 
index b8dcabd..5a6bad3 100644 (file)
@@ -12,16 +12,22 @@ public abstract class Port {
         ship.addPort(name, this);
     }
 
+    protected boolean special = false;
+    protected boolean noInbox = false;
+    protected boolean noChannelDef = false;
     void service() { }
+    public boolean special() { return special; }
+    public boolean noInbox() { return noInbox; }
+    public boolean noChannelDef() { return noChannelDef; }
         
     /** adds one token to the port from the switch fabric side */
-    void addTokenFromFabric() { throw new RuntimeException("this should never happen!"); }
+    void addTokenFromFabric() { /*throw new RuntimeException("this should never happen!");*/ addDataFromFabric(0); }
         
     /** adds the included datum to the port from the switch fabric  side */
     void addDataFromFabric(int datum)  { throw new RuntimeException("this should never happen!"); }
 
     /** adds one token to the port from the ship side */
-    public void addTokenFromShip() { throw new RuntimeException("this should never happen!"); }
+    public void addTokenFromShip() { /*throw new RuntimeException("this should never happen!");*/ addDataFromShip(0); }
         
     /** adds the included datum to the port from the switch fabric side */
     public void addDataFromShip(int datum) { throw new RuntimeException("this should never happen!"); }
diff --git a/src/edu/berkeley/fleet/ships/CommandShip.java b/src/edu/berkeley/fleet/ships/CommandShip.java
new file mode 100644 (file)
index 0000000..dc00a0e
--- /dev/null
@@ -0,0 +1,29 @@
+package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.*;
+
+import java.util.*;
+import java.io.*;
+
+public class CommandShip extends Ship {
+
+    DataInbox   data  = new DataInbox(this, "data", true, false);
+    DataOutbox  out   = new DataOutbox(this, "out", true);
+
+    public String getBalsaName() { return "command"; }
+
+    public CommandShip(Fleet fleet, String name) {
+        super(fleet, name);
+    }
+
+    public void service() {
+        /*
+        if (token.tokenReadyForShip()) {
+            Log.println(Log.invert("   COMMAND: got a token"+Log.clreol()));
+            token.removeTokenForShip();
+        }
+        */
+        if (data.dataReadyForShip())
+            Log.println(Log.invert("   COMMAND: got a datum: " +  data.removeDataForShip()+Log.clreol()));
+    }
+
+}
index 70f4901..8022ba6 100644 (file)
@@ -6,38 +6,28 @@ import java.io.*;
 
 public class CounterShip extends Ship {
 
-    private int count = -1;
-    private int loaded = 0;
+    private int count = 0;
 
-    TokenOutbox zero     = new TokenOutbox(this, "zero");
-    TokenOutbox positive = new TokenOutbox(this, "positive");
-    DataInbox    load     = new DataInbox(this, "load");
-    TokenInbox  ask      = new TokenInbox(this, "ask");
+    DataInbox   load      = new DataInbox(this, "load");
+    TokenInbox  decrement = new TokenInbox(this, "decrement");
+    TokenOutbox zero      = new TokenOutbox(this, "zero");
 
     public CounterShip(Fleet fleet, String name) {
         super(fleet, name);
     }
 
+    public String getBalsaName() { return "counter"; }
     public void service() {
         if (!zero.readyForTokenFromShip()) return;
-        if (!positive.readyForTokenFromShip()) return;
-        if (load.dataReadyForShip()) {
-           if(loaded == 0) {
-               count = load.removeDataForShip();
-               loaded = 1;
-           }
+        if (count==0 && load.dataReadyForShip()) {
+            count = load.removeDataForShip();
+            return;
         }
-        if (ask.tokenReadyForShip()) {
-           if(loaded == 1) {
-               ask.removeTokenForShip();
-               if (count > 0) {
-                   count--;
-                   positive.addTokenFromShip();
-               } else if (count<=0) {
-                   zero.addTokenFromShip();
-                   loaded = 0;
-               }
-           }
+        if (count>0 && decrement.tokenReadyForShip()) {
+            decrement.removeTokenForShip();
+            count--;
+            if (count==0)
+                zero.addTokenFromShip();
         }
     }
 
index 2354a8e..43284a8 100644 (file)
@@ -7,15 +7,15 @@ import java.io.*;
 public class DebugShip extends Ship {
 
     //TokenInbox token = new TokenInbox(this, "token");
-    DataInbox   data  = new DataInbox(this, "data");
-    DataOutbox  out   = new DataOutbox(this, "out");
+    DataInbox   data  = new DataInbox(this, "data", true, false);
+    DataOutbox  out   = new DataOutbox(this, "out", true);
 
     public String getBalsaName() { return "debug"; }
 
     public DebugShip(Fleet fleet, String name) {
         super(fleet, name);
     }
-
+    
     public void service() {
         /*
         if (token.tokenReadyForShip()) {
index 44195e9..195444f 100644 (file)
@@ -9,6 +9,8 @@ public class FifoShip extends Ship {
     DataInbox   in  = new DataInbox(this, "in");
     DataOutbox  out = new DataOutbox(this, "out");
 
+    public String getBalsaName() { return "fifoship"; }
+
     private Queue<Integer> fifo = new LinkedList<Integer>();
 
     public FifoShip(Fleet fleet, String name) {