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
--- /dev/null
+#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
+//
--- /dev/null
+#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
+
+
+++ /dev/null
-#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
-
-
+++ /dev/null
-#import edu.berkeley.fleet.ships
-
-#ship debug : DebugShip
-#ship adder1 : AdderShip
-#ship adder2 : AdderShip
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
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]++
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
import java.util.*;
import java.io.*;
-import static edu.berkeley.fleet.Instruction.IgnoreCopyTake;
/** a codebag */
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();
package edu.berkeley.fleet;
-import static edu.berkeley.fleet.Instruction.IgnoreCopyTake.*;
import java.util.*;
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);
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);
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]),
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]),
"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("");
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 {
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);
}
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);
} 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) {
}
}
}
-
+ public static int krunk=0;
}
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>
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")) {
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));
} 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);
- }
- }
+ */
}
-
}
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 //////////////////////////////////////////////////////////////////////////////
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;
getFleet().sendToken(this, ackDestinationUponAccept);
ackDestinationUponAccept = null;
}
- return itemPresentedToShip;
+ return register;
}
+ int register = 0;
/** invoked by superclass */
protected final boolean service(Instruction instruction) {
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
}
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)
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");
}
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();
}
}
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
);
return;
}
+ */
currentlyExecuting = null;
}
if (currentlyExecuting != null || instructions.size() > 0) {
package edu.berkeley.fleet;
-import static edu.berkeley.fleet.Instruction.IgnoreCopyTake.*;
public abstract class Outbox extends InstructionPort {
triggersReceived++;
}
+ int register;
protected final boolean service(Instruction instruction) {
// if no instruction waiting, do nothing
// 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!");
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!"); }
--- /dev/null
+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()));
+ }
+
+}
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();
}
}
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()) {
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) {