go: fleeterpreter.jar
- java -Xmx500m -cp lib/edu.berkeley.sbp.jar:fleeterpreter.jar edu.berkeley.fleet.FleetParser
+ java -Xmx500m -cp lib/edu.berkeley.sbp.jar:fleeterpreter.jar edu.berkeley.fleet.interpreter.Main
+
+run: fleeterpreter.jar
+ java -Xmx500m -cp lib/edu.berkeley.sbp.jar:fleeterpreter.jar edu.berkeley.fleet.interpreter.Main < contrib/demo.fleet
code: fleeterpreter.jar
- java -Xmx500m -cp lib/edu.berkeley.sbp.jar:fleeterpreter.jar edu.berkeley.fleet.FleetParser --dump-code < contrib/demo.fleet
+ java -Xmx500m -cp lib/edu.berkeley.sbp.jar:fleeterpreter.jar edu.berkeley.fleet.interpreter.Main --dump-code < contrib/demo.fleet
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
+ java -Xmx500m -cp lib/edu.berkeley.sbp.jar:fleeterpreter.jar edu.berkeley.fleet.interpreter.Main --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
+ java -Xmx500m -cp lib/edu.berkeley.sbp.jar:fleeterpreter.jar edu.berkeley.fleet.interpreter.Main --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
-fleeterpreter.jar: $(shell find src -name \*.java) fleet.g
- mkdir -p bin
- cp fleet.g bin
+fleeterpreter.jar: $(shell find src -name \*.java) src/edu/berkeley/fleet/parser/fleet.g
+ mkdir -p bin/edu/berkeley/fleet/parser/
+ cp src/edu/berkeley/fleet/parser/fleet.g bin/edu/berkeley/fleet/parser/
javac -cp lib/edu.berkeley.sbp.jar -d bin $(shell find src -name \*.java)
cd bin; jar xvf ../lib/edu.berkeley.sbp.jar
- echo 'Main-Class: edu.berkeley.fleet.FleetParser' > bin/manifest
+ echo 'Main-Class: edu.berkeley.fleet.interpreter.Main' > bin/manifest
cd bin; jar cvmf manifest ../$@ .
program:
make code
scp fleet.bin root@bee441.cs.berkeley.edu:
-# ssh root@bee441.cs.berkeley.edu 'user_unprogram 1;user_program 1 main.bit; echo ok; ./a.out /dev/selectmap1 fleet.bin'
\ No newline at end of file
+# ssh root@bee441.cs.berkeley.edu 'user_unprogram 1;user_program 1 main.bit; echo ok; ./a.out /dev/selectmap1 fleet.bin'
+
+clean:; rm -rf bin fleeterpreter.jar
+
+javadoc:
+ mkdir -p doc/api
+ javadoc \
+ -classpath lib/edu.berkeley.sbp.jar \
+ -linksource \
+ -windowtitle "Fleet API" \
+ -sourcepath src \
+ -header "<b>Fleet</b><br>API" \
+ -public \
+ -notree \
+ -noindex \
+ -nonavbar \
+ -stylesheetfile doc/javadoc.css \
+ -noqualifier all \
+ -d doc/api \
+ edu.berkeley.fleet.api \
+ edu.berkeley.fleet.parser
#include "contrib/demo.ships"
-//22: sendto debug.data
-//22: sendto debug.data
-//alu1.out: ack debug.data
+0: sendto alu2.a;
+1: sendto alu2.b;
+2: sendto alu2.b;
+3: sendto alu2.b;
-299: sendto alu2.a
-120: sendto alu2.b
-0: sendto alu2.op
-alu2.out: take, sendto debug.data
+0: sendto alu2.op;
+alu2.op:
+ take;
+ [*] deliver;
+alu2.out:
+ [*r] take, sendto debug.data;
+ [*r] sendto alu2.a;
-//22: sendto alu3.b
+alu2.a: [*] take, deliver;
+alu2.b: [*] take, deliver;
-// 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
-//
+debug.data: [*] take, deliver;
#ship alu1 : Alu1
#ship alu2 : Alu2
-#ship debug : DebugShip
-#ship command : CommandShip
+#ship debug : Debug
+#ship command : Command
//#ship command : CommandShip
//#ship dup1 : Dup
--- /dev/null
+//22: sendto debug.data
+//22: sendto debug.data
+//alu1.out: ack 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
-package edu.berkeley.fleet;
-
-import java.util.*;
-import java.io.*;
-
-/** a codebag */
-public class CodeBag {
-
- private static int max_allocated_descriptor = 1;
- private static HashMap<Integer,CodeBag> codeBagsByDescriptor = new HashMap<Integer,CodeBag>();
-
- public static CodeBag getCodeBagByDescriptor(int descriptor) {
- return codeBagsByDescriptor.get(descriptor);
- }
-
- private final int descriptor;
- private final CodeBag parent;
- private final String name;
- private ArrayList<Dispatchable> dispatchables = new ArrayList<Dispatchable>();
- private HashMap<String,CodeBag> codeBags = new HashMap<String,CodeBag>();
-
- public CodeBag(CodeBag parent, String name) {
- this.parent = parent;
- this.name = name;
- this.descriptor = max_allocated_descriptor++;
- codeBagsByDescriptor.put(descriptor, this);
- if (parent != null && name != null)
- parent.add(name, this);
- }
-
- public void dispatch(Fleet fleet) {
- for(Dispatchable d : dispatchables) {
- Log.dispatch(d);
- d.dispatch(fleet);
- }
- }
-
- public void add(Dispatchable instr) {
- dispatchables.add(instr);
- }
-
- public void add(String name, CodeBag instr) {
- codeBags.put(name, instr);
- }
-
- public int getDescriptor() {
- return descriptor;
- }
-
- public CodeBag getCodeBag(String name) {
- CodeBag ret = codeBags.get(name);
- if (ret != null) return ret;
- if (parent==null) return null;
- return parent.getCodeBag(name);
- }
-
- public void dump(OutputStream os, long data_) throws Exception {
- int data = (int)data_;
- os.write((byte)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;
-
- 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;
- 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();
- }
-
- public String toString() {
- if (name != null) return name;
- StringBuffer ret = new StringBuffer();
- for(Dispatchable d : dispatchables) {
- ret.append(d);
- ret.append("\n");
- }
- for(String n : codeBags.keySet()) {
- ret.append(n + ": ");
- ret.append(codeBags.get(n));
- ret.append("\n");
- }
- return "{\n "+Log.indent(ret.toString(), " ")+"\n}";
- }
-
-
-}
+++ /dev/null
-package edu.berkeley.fleet;
-
-public class DataOutbox extends Outbox {
-
- 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);
- }
-
- public boolean readyForDataFromShip() {
- return super.readyForItemFromShip();
- }
-
- protected void send(Port port, int data) {
- getFleet().sendData(this, data, port);
- }
-}
+++ /dev/null
-package edu.berkeley.fleet;
-
-import edu.berkeley.sbp.*;
-import edu.berkeley.sbp.chr.*;
-import edu.berkeley.sbp.misc.*;
-import edu.berkeley.sbp.meta.*;
-import edu.berkeley.sbp.bind.*;
-import edu.berkeley.sbp.util.*;
-import java.util.*;
-import java.io.*;
-
-/**
- * @author Adam Megacz <megacz@cs.berkeley.edu>
- * @author Thomas Kho <tkho@eecs.berkeley.edu>
- */
-public class FleetParser {
-
- public static boolean dump_fabric = false;
- public static boolean dump_code = false;
-
- public static void main(String[] s) throws Exception {
- for(int i=0; i<s.length; i++) {
- if (s[i].startsWith("--color=")) {
- String val = s[i].substring(s[i].indexOf('=')+1);
- if (val.equals("on")) {
- Log.ansi_color = true;
- continue;
- } else if (val.equals("off")) {
- Log.ansi_color = false;
- continue;
- }
- } else if (s[i].startsWith("--dump-fabric")) {
- dump_fabric = true;
- continue;
- } else if (s[i].startsWith("--dump-code")) {
- dump_code = true;
- continue;
-
- } else if (s[i].startsWith("--memory=")) {
- String val = s[i].substring(s[i].indexOf('=')+1);
- if (val.equals("hide")) {
- debugMemory = false;
- continue;
- } else if (val.equals("show")) {
- debugMemory = true;
- continue;
- }
- }
- System.out.println("Fleeterpreter usage:");
- System.out.println("");
- System.out.println(" --dump-fabric");
- System.out.println(" --dump-code");
- System.out.println(" --color={on|off}");
- System.out.println(" --inboxes={configured|unconfigured}");
- System.out.println(" --memory={hide|show}");
- System.exit(-1);
- }
- go(new InputStreamReader(System.in));
- }
-
- public static void go(Reader r) throws Exception {
- Fleet fleet = new Fleet();
- FleetParser fp = new FleetParser(fleet);
- fp.walk((Tree<String>)parse(r));
- fp.done();
- }
-
- public static Tree<String> parse(Reader r) throws Exception {
- InputStream grammarStream =
- FleetParser.class.getClassLoader().getResourceAsStream("fleet.g");
- Parser metaGrammarParser = new CharParser(MetaGrammar.newInstance());
- Tree<String> parsedGrammar = metaGrammarParser.parse(new CharInput(grammarStream)).expand1();
- Union grammar = Grammar.create(parsedGrammar, "s", new Grammar.Bindings() { });
- Parser parser = new CharParser(grammar);
- Tree tree = parser.parse(new CharInput(r)).expand1();
- return tree;
- }
-
- private Fleet fleet;
- private ArrayList<String> imports = new ArrayList<String>();
- private CodeBag rootCodeBag;
- private static boolean debugMemory = true;
-
- public FleetParser(Fleet fleet) {
- this.fleet = fleet;
- }
-
- public void done() {
- if (dump_fabric) {
- fleet.dumpFabric(false);
-
- } else if (dump_code) {
- fleet.dumpFabric(true);
- try {
- rootCodeBag.dump(fleet);
- } catch (Exception e) { throw new RuntimeException(e); }
-
- } else if (rootCodeBag != null) {
- if (debugMemory) { fleet.dumpMem(); }
- System.out.println(rootCodeBag);
- rootCodeBag.dispatch(fleet);
- fleet.go();
- if (debugMemory) { fleet.dumpMem(); }
- }
- }
-
- public void walk(Tree<String> t) {
- String head = t.head();
- if (head==null) {
- } else if (head.equals("Program")) {
- for(Tree<String> tc : t.child(0))
- walk(tc);
- CodeBag cb = new CodeBag(null, null);
- if (t.size()>1)
- for(Tree<String> statement : t.child(1))
- fillCodeBag(statement, cb);
- rootCodeBag = cb;
-
- } else if (head.equals("Import")) {
- imports.add(string(t.child(0)));
-
- } else if (head.equals("Ship")) {
- String name = name(t.child(0));
- String classname = string(t.child(1));
- boolean good = false;
- for(String s : imports)
- if (fleet.tryCreate(s+"."+classname, name)) {
- good = true;
- break;
- }
- if (!good)
- throw new RuntimeException("couldn't find a ship called \""+classname+"\"");
-
- } else if (head.equals("Include")) {
- try {
- walk(parse(new InputStreamReader(new FileInputStream(string(t.child(0))))));
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
- } else if (head.equals("Memory")) {
- if (fleet.mem.length != 0)
- throw new RuntimeException("multiple memory directives found");
- Tree<String> m = t.child(0);
- int[] mem = new int[m.size()];
- for(int i=0; i<mem.length; i++)
- mem[i] = Integer.parseInt(string(m.child(i)));
- fleet.mem = mem;
- }
- }
-
- public String string(Tree<String> t) {
- String ret = "";
- if (t.head() != null) ret += t.head();
- for(Tree<String> c : t)
- ret += string(c);
- return ret;
- }
-
- public String name(Tree<String> t) {
- return string(t.child(0))+string(t.child(1));
- }
-
- public PortReference portReference(Tree<String> t) {
- if (!"Port".equals(t.head())) return null;
- return new PortReference(name(t.child(0)), name(t.child(1)));
- }
-
- public void fillCodeBag(Tree<String> t, CodeBag cb) {
- if (t.head()==null) return;
- else if (t.head().equals("NamedCodeBag")) {
- CodeBag cb2 = new CodeBag(cb, name(t.child(0)));
- for(Tree<String> statement : t.child(1))
- fillCodeBag(statement, cb2);
-
- } 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));
-
- } else if (t.head().equals("Fiber")) {
- PortReference benkobox = portReference(t.child(0));
-
- 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 ("AnonymousCodeBag".equals(t.child(1).head())) {
- CodeBag cb3 = new CodeBag(cb, null);
- for(Tree<String> tc : t.child(1).child(0))
- fillCodeBag(tc, cb3);
- cb.add(new Literal.LiteralDatum(cb3.getDescriptor(), d, true));
-
- } else if ("CodeBagRef".equals(t.child(1).head())) {
- cb.add(new Literal.CodeBagRef(name(t.child(1).child(0)), cb, d));
-
- } else if ("ShipSpecific".equals(t.child(1).head())) {
- cb.add(new Literal.ShipSpecific(string(t.child(1).child(0)), d, count));
- */
- }
-}
+++ /dev/null
-package edu.berkeley.fleet;
-
-/** an instruction within a codebag, as specified in am10; this class is immutable */
-public class Instruction extends Dispatchable {
-
- public final PortReference source;
- public final PortReference destination;
- public final int count;
-
- public final boolean trigger;
- public final boolean dataIn;
- public final boolean latch;
- public final boolean dataOut;
- public final boolean ack;
- public final boolean recycle;
-
- public Instruction(PortReference source,
- PortReference destination,
- int count,
- 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 void dispatch(Fleet fleet) {
- Port sourcePort = source.resolve(fleet);
- if (!(sourcePort instanceof InstructionPort))
- throw new RuntimeException(sourcePort + " is not an InstructionPort!");
- ((InstructionPort)sourcePort).addInstruction(this);
- }
-
- public String toString() {
- StringBuffer ret = new StringBuffer();
- ret.append(source);
- ret.append(": ");
- boolean more=false;
- switch(count) {
- case 1: break;
- case Integer.MAX_VALUE: ret.append("[*] ");
- default: ret.append("["+count+"] ");
- }
- 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();
- }
-}
+++ /dev/null
-package edu.berkeley.fleet;
-
-import java.util.*;
-
-/** anything that has a source (instruction horn) address on the switch fabric */
-public abstract class InstructionPort extends Port {
-
- /** the currently executing instruction */
- Instruction currentlyExecuting = null;
-
- /** all instructions waiting to be executed (excludes currentlyExecuting) */
- Queue<Instruction> instructions = new LinkedList<Instruction>();
-
- /** the count field of currentlyExecuting, taking into account actions already performed */
- int currentlyExecutingCount;
-
- InstructionPort(Ship ship, String name) {
- super(ship, name);
- }
-
- /** an instruction arrives from the instruction horn */
- void addInstruction(Instruction instr) {
- if (currentlyExecuting != null && currentlyExecuting.count == Integer.MAX_VALUE) {
- currentlyExecuting = null;
- currentlyExecutingCount = 0;
- }
- if (currentlyExecuting == null) {
- currentlyExecuting = instr;
- currentlyExecutingCount = currentlyExecuting.count;
- } else {
- instructions.add(instr);
- }
- }
-
- protected void shutdown(boolean leaveAsInbox) {
- if (leaveAsInbox && DataInbox.defaultInstruction != null) {
- if (currentlyExecuting == null) {
- 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
- || currentlyExecuting.trigger
- || !currentlyExecuting.dataOut) {
- Log.println(Log.red(" WARNING: you did not leave the correct standing move on inbox-port " + this)+
- "\n found: " + currentlyExecuting
- );
- return;
- }
- */
- currentlyExecuting = null;
- }
- if (currentlyExecuting != null || instructions.size() > 0) {
- Log.println(Log.red(" WARNING: you left instructions on the instruction queue of port " +
- this + "; they are:"));
- if (currentlyExecuting != null)
- Log.println(" " + currentlyExecuting);
- for(Instruction i : instructions)
- Log.println(" " + i);
- }
- }
-
- // interface to subclass ///////////////////////////////////////////////////////////////////////
-
- /** this will be invoked periodically; should return true to "consume" an instruction, false to leave it executing */
- protected abstract boolean service(Instruction instr);
-
- protected final void service() {
- if (currentlyExecutingCount <= 0)
- currentlyExecuting = null;
- if (currentlyExecuting == null && instructions.size() > 0) {
- currentlyExecuting = instructions.remove();
- currentlyExecutingCount = currentlyExecuting.count;
- }
- boolean ret = service(currentlyExecuting);
- if (ret && currentlyExecuting != null && currentlyExecutingCount != Integer.MAX_VALUE)
- currentlyExecutingCount--;
- }
-
-
-}
+++ /dev/null
-package edu.berkeley.fleet;
-
-/** represents a literal; currently handled in an extremely hoakey fashion */
-public class Literal {
-
- public static class LiteralDatum extends Dispatchable {
- int data;
- PortReference destination;
- private boolean isCodeBag;
- private int count;
- public LiteralDatum(int data, PortReference destination, boolean isCodeBag) { this(data, destination, isCodeBag, 1); }
- public LiteralDatum(int data, PortReference destination, boolean isCodeBag, int count) {
- this.data = data;
- this.destination = destination;
- this.isCodeBag = isCodeBag;
- this.count = count;
- }
- protected int getData() { return data; }
- public void dispatch(Fleet fleet) {
- for(int i=0; i<count; i++) {
- Port port = destination.resolve(fleet);
- Log.data((isCodeBag?(CodeBag.getCodeBagByDescriptor(getData())+""):(getData()+"")), null, port);
- port.addDataFromFabric(getData());
- }
- }
- public String toString() {
- return (isCodeBag?(CodeBag.getCodeBagByDescriptor(getData())+""):(getData()+""))+" -"+(count==1?"":("["+count+"]-"))+"> "+destination;
- }
- }
-
- public static class CodeBagRef extends LiteralDatum {
- private String name;
- private CodeBag parent;
- public CodeBagRef(String name, CodeBag parent, PortReference destination) {
- super(0, destination, true);
- this.parent = parent;
- this.name = name;
- }
- protected int getData() {
- if (parent.getCodeBag(name)==null)
- throw new RuntimeException("[invalid codebag, name="+name+"]");
- return parent.getCodeBag(name).getDescriptor();
- }
- }
-
- public static class LiteralToken extends Dispatchable {
- private PortReference destination;
- public LiteralToken(PortReference destination) {
- this.destination = destination;
- }
- public void dispatch(Fleet fleet) {
- destination.resolve(fleet).addTokenFromFabric();
- }
- public String toString() {
- return "token -> "+destination;
- }
- }
-
- public static class ShipSpecific extends Dispatchable {
- private String data;
- private PortReference destination;
- private int count;
- public ShipSpecific(String data, PortReference destination, int count) {
- this.data = data;
- this.destination = destination;
- this.count = count;
- }
- public void dispatch(Fleet fleet) {
- for(int i=0; i<count; i++) {
- Port port = destination.resolve(fleet);
- Log.data("\""+data+"\"", null, port);
- int dat = port.getShip().resolveShipSpecificConstant(data);
- port.addDataFromFabric(dat);
- }
- }
- public String toString() {
- return ("\""+data+"\""+" -"+(count==1?"":("["+count+"]-"))+"> "+destination);
- }
- }
-}
+++ /dev/null
-package edu.berkeley.fleet;
-
-/** an "unresolved" reference to a port -- one which may not exist */
-public class PortReference {
-
- public final String portname;
- public final String shipname;
-
- public PortReference(String shipname, String portname) {
- this.shipname = shipname;
- this.portname = portname;
- }
-
- public Port resolve(Fleet fleet) {
- return fleet.getShip(shipname).getPort(portname);
- }
-
- public String toString() {
- return shipname+"."+portname;
- }
-
-}
+++ /dev/null
-package edu.berkeley.fleet;
-
-import edu.berkeley.sbp.chr.*;
-import edu.berkeley.sbp.misc.*;
-import edu.berkeley.sbp.meta.*;
-import edu.berkeley.sbp.bind.*;
-import edu.berkeley.sbp.util.*;
-import java.util.*;
-import java.io.*;
-
-/** a ship, which belongs to a fleet and which may have many ports */
-public abstract class Ship {
-
- ArrayList<Port> portlist = new ArrayList<Port>();
- private HashMap<String,Port> ports = new HashMap<String,Port>();
-
- private String name;
- private Fleet fleet;
-
- /** You should instantiate a bunch of Inboxes and Outboxes in your constructor */
- public Ship(Fleet fleet, String name) {
- this.name = name;
- this.fleet = fleet;
- fleet.shiplist.add(this);
- fleet.ships.put(name, this);
- }
-
- public Port getPort(String s) {
- Port p = ports.get(s);
- if (p == null) throw new RuntimeException("unknown port \""+name+"."+s+"\"");
- return p;
- }
-
- public String getBalsaName() { return name; }
- public String getName() { return name; }
- public String toString() { return name; }
-
- public Fleet getFleet() { return fleet; }
-
- /**
- * Override this method, check inboxes for the data you need, and
- * if you find it, deposit results in an outbox; we'll take care
- * of the rest.
- */
- public abstract void service();
-
- public final void _service() {
- for(Port p : ports.values()) p.service();
- service();
- }
-
- void addPort(String name, Port port) {
- portlist.add(port);
- ports.put(name, port);
- }
-
- public void shutdown() {
- for(Port p : ports.values())
- p.shutdown();
- }
-
- public int resolveShipSpecificConstant(String shipSpecificData) {
- throw new RuntimeException("don't know how to resolve \""+shipSpecificData+"\"");
- }
-}
+++ /dev/null
-package edu.berkeley.fleet;
-
-/** a port which outputs only tokens */
-public class TokenOutbox extends Outbox {
-
- public TokenOutbox(Ship ship, String name) {
- super(ship, name);
- }
-
- protected void send(Port port, int data) {
- getFleet().sendToken(this, port);
- }
-
- public boolean readyForTokenFromShip() {
- return super.readyForItemFromShip();
- }
-
- public void addTokenFromShip() {
- addItemFromShip(0);
- }
-
-}
public abstract class BenkoBox {
/** you should extend subclasses, not this class directly */
- BenkoBox() { }
+ //FIXME
+ public BenkoBox() { }
/** the descriptive name of this benkobox (relative to its ship) */
public abstract String getName();
-
+
+ /** return the Ship to which this BenkoBox belongs */
+ public abstract Ship getShip();
+
/** the maximum number of instructions we can put in the BenkoBox instruction fifo,
* or Integer.MAX_VALUE if unbounded */
public abstract int getInstructionFifoLength();
}
- public static class Normal extends Instruction {
+ public static class Executable extends Instruction {
public final BenkoBox benkoBox;
public final BenkoBox dest;
public final int count;
- public final boolean wait;
+ public final boolean tokenIn;
public final boolean dataIn;
public final boolean latch;
public final boolean dataOut;
- public final boolean ack;
+ public final boolean tokenOut;
public final boolean recycle;
- public Normal(BenkoBox benkoBox,
- BenkoBox dest,
- int count,
- boolean dataIn,
- boolean latch,
- boolean ack,
- boolean wait,
- boolean dataOut,
- boolean recycle) {
+ /** count=0 denotes a standing move */
+ public Executable(BenkoBox benkoBox,
+ BenkoBox dest,
+ int count,
+ boolean tokenIn,
+ boolean dataIn,
+ boolean latch,
+ boolean dataOut,
+ boolean tokenOut,
+ boolean recycle) {
this.benkoBox = benkoBox;
this.dest = dest;
this.count = count;
+ this.tokenIn = tokenIn;
this.dataIn = dataIn;
this.latch = latch;
- this.ack = ack;
- this.wait = wait;
this.dataOut = dataOut;
+ this.tokenOut = tokenOut;
this.recycle = recycle;
- if (count <= 0)
- throw new RuntimeException("count field of an instruction must be >0");
+ if (count < 0)
+ throw new RuntimeException("count field of an instruction must be >=0");
+ }
+
+ public Instruction.Executable decrementCount() {
+ if (count==1) return null;
+ return new Executable(benkoBox, dest, count==0 ? 0 : count-0, tokenIn, dataIn, latch, dataOut, tokenOut, recycle);
+ }
+
+ public String toString() {
+ String ret = "";
+ if (count==0 || count>1 || recycle) {
+ ret += "[";
+ if (count>1) ret += count;
+ if (count==0) ret += "*";
+ if (recycle) ret += "r";
+ ret += "] ";
+ }
+ boolean needcomma = false;
+ if (tokenIn) { ret += (needcomma ? ", " : "") + "wait"; needcomma = true; }
+ if (dataIn && latch) { ret += (needcomma ? ", " : "") + "take"; needcomma = true; }
+ if (dataIn && !latch) { ret += (needcomma ? ", " : "") + "discard"; needcomma = true; }
+ if (dataOut) {
+ if (benkoBox instanceof BenkoBox.Inbox || dest==null)
+ ret += (needcomma ? ", " : "") + "deliver";
+ else
+ ret += (needcomma ? ", " : "") + "sendto "+dest;
+ needcomma = true;
+ }
+ if (tokenOut) { ret += (needcomma ? ", " : "") + "ack "+dest; needcomma = true; }
+ return ret;
}
}
public abstract class Ship {
+ /** return the Fleet that this Ship belongs to */
+ public abstract Fleet getFleet();
+
/** returns the type of the ship ("Fetch", "ALU", etc) */
public abstract String getType();
/** return all benkoboxes which feed this ship; order is NOT significant */
public abstract Iterable<BenkoBox> getBenkoBoxes();
+ public BenkoBox getBenkoBox(String s) {
+ for(BenkoBox b : getBenkoBoxes())
+ if (b.getName().equals(s))
+ return b;
+ throw new RuntimeException("unknown port \""+getType()+"."+s+"\"");
+ }
+
+ public int getOrdinal() {
+ int ord = 0;
+ for(Ship s : getFleet()) {
+ if (s==this) return ord;
+ if (s.getType() != null && s.getType().equals(getType())) ord++;
+ }
+ throw new RuntimeException("inconsistency: Ship does not belong to its own Fleet!");
+ }
+
+ public String toString() { return getType() + "[" + getOrdinal() + "]"; }
+
}
--- /dev/null
+package edu.berkeley.fleet.interpreter;
+import edu.berkeley.fleet.api.*;
+import edu.berkeley.fleet.api.Instruction;
+
+import java.util.*;
+import java.io.*;
+
+/** a codebag */
+public class CodeBag {
+
+ private static int max_allocated_descriptor = 1;
+ private static HashMap<Integer,CodeBag> codeBagsByDescriptor = new HashMap<Integer,CodeBag>();
+
+ public static CodeBag getCodeBagByDescriptor(int descriptor) {
+ return codeBagsByDescriptor.get(descriptor);
+ }
+
+ private final int descriptor;
+ private final CodeBag parent;
+ private final String name;
+ private ArrayList<Instruction> dispatchables = new ArrayList<Instruction>();
+ private HashMap<String,CodeBag> codeBags = new HashMap<String,CodeBag>();
+
+ public CodeBag(CodeBag parent, String name) {
+ this.parent = parent;
+ this.name = name;
+ this.descriptor = max_allocated_descriptor++;
+ codeBagsByDescriptor.put(descriptor, this);
+ if (parent != null && name != null)
+ parent.add(name, this);
+ }
+
+ public void dispatch(Fleet fleet) {
+ for(Instruction d : dispatchables) {
+ Log.dispatch(d);
+ ((Interpreter)fleet).dispatch(d);
+ }
+ }
+
+ public void add(Instruction instr) {
+ dispatchables.add(instr);
+ }
+
+ public void add(String name, CodeBag instr) {
+ codeBags.put(name, instr);
+ }
+
+ public int getDescriptor() {
+ return descriptor;
+ }
+
+ public CodeBag getCodeBag(String name) {
+ CodeBag ret = codeBags.get(name);
+ if (ret != null) return ret;
+ if (parent==null) return null;
+ return parent.getCodeBag(name);
+ }
+
+ public void dump(Fleet fleet) throws Exception {
+ DataOutputStream os = new DataOutputStream(new FileOutputStream("fleet.bin"));
+ for(Instruction i : dispatchables)
+ fleet.writeInstruction(os, i);
+ os.flush();
+ os.close();
+ }
+
+ public String toString() {
+ if (name != null) return name;
+ StringBuffer ret = new StringBuffer();
+ for(Instruction d : dispatchables) {
+ ret.append(d);
+ ret.append("\n");
+ }
+ for(String n : codeBags.keySet()) {
+ ret.append(n + ": ");
+ ret.append(codeBags.get(n));
+ ret.append("\n");
+ }
+ return "{\n "+Log.indent(ret.toString(), " ")+"\n}";
+ }
+
+
+}
-package edu.berkeley.fleet;
+package edu.berkeley.fleet.interpreter;
+import edu.berkeley.fleet.api.*;
import java.util.*;
public class DataInbox extends Inbox {
- public DataInbox(Ship ship, String name) {
+ public DataInbox(InterpreterShip ship, String name) {
super(ship, name);
}
- public DataInbox(Ship ship, String name, boolean noInbox, boolean noChannelDef) {
+ public DataInbox(InterpreterShip ship, String name, boolean noInbox, boolean noChannelDef) {
super(ship, name);
this.noInbox = noInbox;
this.noChannelDef = noChannelDef;
--- /dev/null
+package edu.berkeley.fleet.interpreter;
+import edu.berkeley.fleet.api.*;
+
+public class DataOutbox extends Outbox {
+
+ public DataOutbox(InterpreterShip ship, String name) { super(ship, name); }
+ public DataOutbox(InterpreterShip ship, String name, boolean special) {
+ super(ship, name); this.special = special; }
+
+ private Interpreter getInterpreter() { return ((InterpreterShip)getShip()).getInterpreter(); }
+ public void addDataFromShip(int data) {
+ addItemFromShip(data);
+ }
+
+ public boolean readyForDataFromShip() {
+ return super.readyForItemFromShip();
+ }
+
+ protected void send(InterpreterBenkoBox port, int data) {
+ getInterpreter().sendData(this, data, port);
+ }
+}
-package edu.berkeley.fleet;
+package edu.berkeley.fleet.interpreter;
+import edu.berkeley.fleet.api.*;
public abstract class Dispatchable {
public abstract void dispatch(Fleet fleet);
-package edu.berkeley.fleet;
+package edu.berkeley.fleet.interpreter;
+import edu.berkeley.fleet.api.*;
+import edu.berkeley.fleet.api.Instruction;
import java.util.*;
/** this is a generic inbox which stores <32-bit items (tokens or data) */
public class Inbox extends InstructionPort {
- static Instruction defaultInstruction = null;
-
// private data //////////////////////////////////////////////////////////////////////////////
/** data which has arrived from the switch fabric but not been acted on */
private boolean itemReadyForShip = false;
/** if an ack token is pending, this is where it should be sent once the item is accepted */
- private Port ackDestinationUponAccept;
+ private InterpreterBenkoBox ackDestinationUponAccept;
// protected methods /////////////////////////////////////////////////////////////////////////
- Inbox(Ship ship, String name) {
- super(ship, name);
-
- // default standing move
- if (defaultInstruction != null)
- addInstruction(defaultInstruction);
- }
+ Inbox(InterpreterShip ship, String name) { super(ship, name); }
/** subclasses invoke this when items arrive from the fabric */
protected final void addItemFromFabric(int data) {
return itemReadyForShip;
}
+ private Interpreter getInterpreter() { return ((InterpreterShip)getShip()).getInterpreter(); }
+
/** accpets (removes) an item -- invoked by the ship */
protected final int accept() {
if (!itemReadyForShip)
throw new RuntimeException("invoked accept() on an inbox which does not have items ready; your ship is buggy");
itemReadyForShip = false;
if (ackDestinationUponAccept != null) {
- getFleet().sendToken(this, ackDestinationUponAccept);
+ getInterpreter().sendToken(this, ackDestinationUponAccept);
ackDestinationUponAccept = null;
}
return register;
int register = 0;
/** invoked by superclass */
- protected final boolean service(Instruction instruction) {
+ protected final boolean service(Instruction.Executable instruction) {
// if data is stuck on itemPresentedToShip, wait for it to go somewhere before
// considering additional instructions
if (instruction == null) return false;
// check firing conditions
- if (instruction.trigger)
+ if (instruction.tokenIn)
throw new RuntimeException("invalid instruction: " + instruction +
" (attempts to use trigger on an inbox)");
if (instruction.dataIn && itemsFromFabric.size()==0) return false;
itemReadyForShip = true;
// and make note of the fact that we need to send an ack (if requested)
- if (instruction.ack)
- ackDestinationUponAccept = instruction.destination.resolve(getShip().getFleet());
+ if (instruction.tokenIn)
+ ackDestinationUponAccept = (InterpreterBenkoBox)instruction.dest;
- } else if (instruction.ack) {
+ } else if (instruction.tokenIn) {
// if dataOut is not set, we can send the data immediately
- getFleet().sendToken(this, instruction.destination.resolve(getShip().getFleet()));
+ getInterpreter().sendToken(this, (InterpreterBenkoBox)instruction.dest);
}
return true;
}
--- /dev/null
+package edu.berkeley.fleet.interpreter;
+import edu.berkeley.fleet.api.*;
+import edu.berkeley.fleet.api.Instruction;
+
+import java.util.*;
+
+/** anything that has a source (instruction horn) address on the switch fabric */
+public abstract class InstructionPort extends InterpreterBenkoBox {
+
+ /** the currently executing instruction */
+ Instruction.Executable currentlyExecuting = null;
+
+ /** all instructions waiting to be executed (excludes currentlyExecuting) */
+ Queue<Instruction.Executable> instructions = new LinkedList<Instruction.Executable>();
+
+ /** the count field of currentlyExecuting, taking into account actions already performed */
+ int currentlyExecutingCount;
+
+ InstructionPort(InterpreterShip ship, String name) {
+ super(ship, name);
+ }
+
+ public void kill(int count) {
+ if (currentlyExecuting != null) {
+ currentlyExecuting = null;
+ count--;
+ }
+ for(; count > 0; count--) {
+ if (instructions.size() == 0) {
+ if (currentlyExecuting == null) {
+ Log.error("You have deadlocked ship " + this +
+ " by sending a kill to an empty ififo. I feel sorry for you.");
+ return;
+ }
+ } else {
+ instructions.remove();
+ }
+ }
+ }
+
+ /** an instruction arrives from the instruction horn */
+ void addInstruction(Instruction.Executable instr) {
+ instructions.add(instr);
+ }
+
+ protected void shutdown(boolean leaveAsInbox) {
+ if (currentlyExecuting != null || instructions.size() > 0) {
+ Log.println(Log.red(" WARNING: you left instructions on the instruction queue of port " +
+ this + "; they are:"));
+ if (currentlyExecuting != null)
+ Log.println(" " + currentlyExecuting);
+ for(Instruction.Executable i : instructions)
+ Log.println(" " + i);
+ }
+ }
+
+ // interface to subclass ///////////////////////////////////////////////////////////////////////
+
+ /** this will be invoked periodically; should return true to "consume" an instruction, false to leave it executing */
+ protected abstract boolean service(Instruction.Executable instr);
+
+ protected final void service() {
+ if (currentlyExecutingCount <= 0)
+ currentlyExecuting = null;
+ if (currentlyExecuting == null && instructions.size() > 0) {
+ currentlyExecuting = instructions.remove();
+ currentlyExecutingCount = currentlyExecuting.count;
+ if (currentlyExecutingCount == 0) currentlyExecutingCount = Integer.MAX_VALUE;
+ }
+
+ boolean ret = service(currentlyExecuting);
+ if (!ret) return;
+ if (currentlyExecuting.recycle) {
+ currentlyExecuting = currentlyExecuting.decrementCount();
+ if (currentlyExecuting != null)
+ addInstruction(currentlyExecuting);
+ currentlyExecuting = null;
+
+ } else {
+ if (currentlyExecuting != null && currentlyExecutingCount != Integer.MAX_VALUE)
+ currentlyExecutingCount--;
+ }
+ }
+
+
+}
-package edu.berkeley.fleet;
+package edu.berkeley.fleet.interpreter;
+import edu.berkeley.fleet.api.*;
+import edu.berkeley.fleet.api.*;
+import edu.berkeley.fleet.*;
import java.lang.reflect.*;
import edu.berkeley.sbp.chr.*;
import edu.berkeley.sbp.misc.*;
import java.io.*;
import edu.berkeley.fleet.ships.*;
-public class Fleet {
+public class Interpreter extends Fleet implements Iterable<Ship> {
+
+ public InterpreterBenkoBox resolve(edu.berkeley.fleet.api.BenkoBox bb) { return (InterpreterBenkoBox)bb; }
+
+ public void dispatch(Instruction i) {
+
+ if (i instanceof Instruction.Executable) {
+ InterpreterBenkoBox sourceBenkoBox = resolve(((Instruction.Executable)i).benkoBox);
+ if (!(sourceBenkoBox instanceof InstructionPort))
+ throw new RuntimeException(sourceBenkoBox + " is not an InstructionPort!");
+ ((InstructionPort)sourceBenkoBox).addInstruction(((Instruction.Executable)i));
+
+ } else if (i instanceof Instruction.Literal.Absolute) {
+ InterpreterBenkoBox destBenkoBox = resolve(((Instruction.Literal.Absolute)i).dest);
+ Log.data(((Instruction.Literal.Absolute)i).value+"", null, destBenkoBox);
+ destBenkoBox.addDataFromFabric((int)((Instruction.Literal.Absolute)i).value);
+
+ } else if (i instanceof Instruction.Kill) {
+ InterpreterBenkoBox benkoBox = resolve(((Instruction.Kill)i).benkoBox);
+ if (!(benkoBox instanceof InstructionPort))
+ throw new RuntimeException(benkoBox + " is not an InstructionPort!");
+ ((InstructionPort)benkoBox).kill(((Instruction.Kill)i).count);
+
+ } else {
+ throw new Error("unsupported!");
+ }
+ }
/** some "halt ship" can turn this on to stop the interpreter */
public boolean halt = false;
public int[] mem = new int[0];
public ArrayList<String> imports = new ArrayList<String>();
- public ArrayList<Ship> shiplist = new ArrayList<Ship>();
- public HashMap<String,Ship> ships = new HashMap<String,Ship>();
+ private static String getUniqueName(Ship ship) {
+ return ship.getType() + ship.getOrdinal();
+ }
+
+ public ArrayList<InterpreterShip> shiplist = new ArrayList<InterpreterShip>();
+ public HashMap<String,InterpreterShip> ships = new HashMap<String,InterpreterShip>();
+
+ /** read a machine-formatted instruction from a file (into a Java object) */
+ public Instruction readInstruction(DataInputStream is) throws IOException {
+ // FIXME
+ return null;
+ }
+
+ public void writeInstruction(DataOutputStream os, Instruction d) throws IOException {
+ if (d instanceof Instruction.Executable) {
+ Instruction.Executable inst = (Instruction.Executable)d;
+
+ InterpreterBenkoBox dest = resolve(inst.dest);
+ long instr = dest==null ? 0 : (dest.addr << 1);
+
+ instr |= (((long)inst.count) << (11+1));
+ if (inst.tokenIn) 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.tokenOut) instr |= (1L << (11+1+7+4));
+ instr |= ((long)resolve(inst.benkoBox).instr_addr) << (11+5+7+1);
+ long out = 0;
+ out |= ((InterpreterBenkoBox)ships.get("command").getBenkoBox("data")).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 Instruction.Literal.Absolute) {
+ Instruction.Literal.Absolute ld = (Instruction.Literal.Absolute)d;
+ long out = 0;
+ out |= resolve(ld.dest).addr;
+ out |= ((long)ld.value) << 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);
+ }
+ }
+ public void dump(OutputStream os, long data_) throws IOException {
+ int data = (int)data_;
+ os.write((byte)data);
+ System.out.println(data);
+ }
+
+ public Iterator<Ship> iterator() {
+ return (Iterator<Ship>)(Object)shiplist.iterator();
+ }
public void go() {
while(!halt)
- for(Ship ship : ships.values())
+ for(InterpreterShip ship : ships.values())
for(int j=0; j<10; j++)
ship._service();
// run the ships a bit longer for good measure
for(int i=0; i<100; i++)
- for(Ship ship : ships.values())
+ for(InterpreterShip ship : ships.values())
for(int j=0; j<10; j++)
ship._service();
// check the state of the ships
- for(Ship ship : ships.values())
+ for(InterpreterShip ship : ships.values())
ship.shutdown();
Log.println(Log.yellow(" DONE: ====== FLEET is halted. Have a nice day. ======"));
mem[addr] = data;
}
- public Ship getShip(String name) {
- Ship s = ships.get(name);
+ public InterpreterShip getShip(String name) {
+ InterpreterShip s = ships.get(name);
if (s == null) throw new RuntimeException("unknown ship \""+name+"\"");
return s;
}
- boolean tryCreate(String classname, String shipname) {
+ public InterpreterShip tryCreate(String classname, String shipname) {
try {
Class c = Class.forName(classname);
- Constructor con = c.getConstructor(new Class[] { Fleet.class, String.class });
- con.newInstance(new Object[] { this, shipname });
- return true;
+ Constructor con = c.getConstructor(new Class[] { Interpreter.class, String.class });
+ InterpreterShip ret = (InterpreterShip)con.newInstance(new Object[] { this, shipname });
+ ships.put(shipname, ret);
+ shiplist.add(ret);
+ return ret;
} catch (Exception e) {
- return false;
+ return null;
}
}
- public void sendToken(Port source, Port dest) {
+ public void sendToken(InterpreterBenkoBox source, InterpreterBenkoBox dest) {
Log.token(source, dest);
dest.addTokenFromFabric();
}
- public void sendData(Port source, int data, Port dest) {
+ public void sendData(InterpreterBenkoBox source, int data, InterpreterBenkoBox dest) {
Log.data(data+"", source, dest);
dest.addDataFromFabric(data);
}
// FIXME: this is really ugly: the order of port declarations in
// the XXXShip.java file must match the order in the .balsa file!
- ArrayList instructionports = new ArrayList<Port>();
- for(Ship ship : shiplist)
- for(Port port : ship.portlist)
- if (!port.special())
+ ArrayList instructionports = new ArrayList<InterpreterBenkoBox>();
+ for(InterpreterShip ship : shiplist)
+ for(BenkoBox port : ship.getBenkoBoxes())
+ if (!((InterpreterBenkoBox)port).special())
instructionports.add(port);
FabricTree instructions =
- new FabricTree((Port[])instructionports.toArray(new Port[0]),
+ new FabricTree((InterpreterBenkoBox[])instructionports.toArray(new InterpreterBenkoBox[0]),
"ihorn",
"instruction");
- ArrayList inputports = new ArrayList<Port>();
- for(Ship ship : shiplist)
- for(Port port : ship.portlist)
- if (!port.special())
+ ArrayList inputports = new ArrayList<InterpreterBenkoBox>();
+ for(InterpreterShip ship : shiplist)
+ for(BenkoBox port : ship.getBenkoBoxes())
+ if (!((InterpreterBenkoBox)port).special())
inputports.add(port);
FabricTree inputs =
- new FabricTree((Port[])inputports.toArray(new Port[0]),
+ new FabricTree((InterpreterBenkoBox[])inputports.toArray(new InterpreterBenkoBox[0]),
"horn",
"dest");
- ArrayList outputports = new ArrayList<Port>();
- for(Ship ship : shiplist)
- for(Port port : ship.portlist)
- if (!port.special())
+ ArrayList outputports = new ArrayList<InterpreterBenkoBox>();
+ for(InterpreterShip ship : shiplist)
+ for(BenkoBox port : ship.getBenkoBoxes())
+ if (!((InterpreterBenkoBox)port).special())
outputports.add(port);
FabricTree outputs =
- new FabricTree((Port[])outputports.toArray(new Port[0]),
+ new FabricTree((InterpreterBenkoBox[])outputports.toArray(new InterpreterBenkoBox[0]),
"funnel",
"source");
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;");
instructions.dumpChannels(true);
outputs.dumpChannels(true);
inputs.dumpChannels(true);
- for(Ship ship : shiplist)
- 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()+";");
+ for(InterpreterShip ship : shiplist)
+ for(BenkoBox port : ship.getBenkoBoxes()) {
+ if (ship instanceof Command && port instanceof Outbox) continue;
+ System.out.println(" wire [(`PACKET_WIDTH-1):0] data_"+getUniqueName(ship)+"_"+port.getName()+";");
}
System.out.println("");
System.out.println("");
inputs.dumpChannels(false);
System.out.println("");
- for(Ship ship : shiplist) {
- System.out.print(ship.getBalsaName());
+ for(InterpreterShip ship : shiplist) {
+ System.out.print(ship.getClass().getSimpleName().toLowerCase());
System.out.print(" ");
System.out.print("krunk"+(krunk++));
System.out.print("(clk, ");
boolean first = true;
- for(Port port : ship.portlist) {
+ for(BenkoBox port : ship.getBenkoBoxes()) {
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("data_"+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
+ System.out.print("data_"+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
+ System.out.print("data_"+getUniqueName(port.getShip())+"_"+port.getName());
System.out.print(" ");
}
System.out.println(");");
- for(Port port : ship.portlist) {
- if (port.special()) continue;
+ for(BenkoBox port : ship.getBenkoBoxes()) {
+ if (((InterpreterBenkoBox)port).special()) continue;
if (port instanceof Inbox) {
- if (port.noInbox())
+ if (((InterpreterBenkoBox)port).noInbox())
System.out.print("stupidinbox");
else
System.out.print("inbox");
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("instruction_"+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
+ System.out.print("instruction_"+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
+ System.out.print("instruction_"+getUniqueName(port.getShip())+"_"+port.getName()+", ");
+ System.out.print("dest_"+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
+ System.out.print("dest_"+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
+ System.out.print("dest_"+getUniqueName(port.getShip())+"_"+port.getName()+", ");
+ System.out.print("source_"+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
+ System.out.print("source_"+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
+ System.out.print("source_"+getUniqueName(port.getShip())+"_"+port.getName()+", ");
+ System.out.print("data_"+getUniqueName(port.getShip())+"_"+port.getName()+"_r, ");
+ System.out.print("data_"+getUniqueName(port.getShip())+"_"+port.getName()+"_a, ");
+ System.out.print("data_"+getUniqueName(port.getShip())+"_"+port.getName());
System.out.print(");");
System.out.println();
}
String prefix;
Node root;
public void dumpChannels(boolean decl) { root.dumpChannels(0, decl); }
- public FabricTree(Port[] ports, String component, String prefix) {
+ public FabricTree(InterpreterBenkoBox[] ports, String component, String prefix) {
this.prefix = prefix;
root = (Node)mkNode("", component, ports, 0, ports.length, 0, 0);
}
- private Object mkNode(String name, String component, Port[] ports, int start, int end, int addr, int bits) {
+ private Object mkNode(String name, String component, InterpreterBenkoBox[] ports, int start, int end, int addr, int bits) {
if (end-start == 0) return null;
if (end-start == 1) {
- Port p = ports[start];
+ InterpreterBenkoBox p = ports[start];
if (prefix.equals("instruction")) {
p.instr_addr = addr;
p.instr_bits = bits;
}
private String describe(String prefix, Object o) {
if (o==null) return null;
- if (o instanceof Port) {
- Port p = (Port)o;
- return prefix+"_"+p.getShip().getName()+"_"+p.getName();
+ if (o instanceof InterpreterBenkoBox) {
+ InterpreterBenkoBox p = (InterpreterBenkoBox)o;
+ return prefix+"_"+getUniqueName(p.getShip())+"_"+p.getName();
}
if (o instanceof Node) {
return ((Node)o).describe(prefix);
-package edu.berkeley.fleet;
+package edu.berkeley.fleet.interpreter;
+import edu.berkeley.fleet.api.*;
+import edu.berkeley.fleet.api.BenkoBox;
/** anything that has a destination address on the switch fabric */
-public abstract class Port {
+public abstract class InterpreterBenkoBox extends BenkoBox {
private final String name;
- private final Ship ship;
+ private final InterpreterShip ship;
- public Port(Ship ship, String name) {
+ public InterpreterBenkoBox(InterpreterShip ship, String name) {
this.ship = ship;
this.name = name;
- ship.addPort(name, this);
+ ship.addBenkoBox(name, this);
}
+ int bits;
+ int addr;
+ int instr_bits;
+ int instr_addr;
protected boolean special = false;
protected boolean noInbox = false;
protected boolean noChannelDef = false;
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!");*/ addDataFromFabric(0); }
+ void addTokenFromFabric() { 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!");*/ addDataFromShip(0); }
+ public void addTokenFromShip() { 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!"); }
public String getName() { return name; }
- int bits;
- int addr;
- int instr_bits;
- int instr_addr;
+ public int getInstructionFifoLength() { return 4; }
+
}
--- /dev/null
+package edu.berkeley.fleet.interpreter;
+import edu.berkeley.fleet.api.*;
+
+import edu.berkeley.fleet.api.*;
+import java.util.*;
+import java.io.*;
+
+/** a ship, which belongs to a fleet and which may have many ports */
+public abstract class InterpreterShip extends Ship {
+
+ /** You should instantiate a bunch of Inboxes and Outboxes in your constructor */
+ public InterpreterShip(Interpreter fleet, String name) { this.fleet = fleet; }
+
+ private Interpreter fleet;
+
+ // this is dumb, the fpga fleet currently requires these in declaration-order; it shouldn't
+ private ArrayList<InterpreterBenkoBox> portlist = new ArrayList<InterpreterBenkoBox>();
+ private HashMap<String,InterpreterBenkoBox> ports = new HashMap<String,InterpreterBenkoBox>();
+
+ public Iterable<BenkoBox> getBenkoBoxes() { return (Iterable<BenkoBox>)(Object)portlist; }
+ public String getType() { return getClass().getSimpleName(); }
+ public Fleet getFleet() { return fleet; }
+ public Interpreter getInterpreter() { return fleet; }
+
+ /**
+ * Override this method, check inboxes for the data you need, and
+ * if you find it, deposit results in an outbox; we'll take care
+ * of the rest.
+ */
+ public abstract void service();
+
+ public final void _service() {
+ for(InterpreterBenkoBox p : ports.values()) p.service();
+ service();
+ }
+
+ void addBenkoBox(String name, InterpreterBenkoBox port) { ports.put(name, port); portlist.add(port); }
+
+ public void shutdown() {
+ for(InterpreterBenkoBox p : ports.values())
+ p.shutdown();
+ }
+}
-package edu.berkeley.fleet;
+package edu.berkeley.fleet.interpreter;
+import edu.berkeley.fleet.api.*;
+import edu.berkeley.fleet.api.Instruction;
import java.io.*;
public class Log {
public static void dispatch(Dispatchable d) {
println(green("dispatch: " + indent(d+"", " ")));
}
+ public static void dispatch(Instruction d) {
+ println(green("dispatch: " + indent(d+"", " ")));
+ }
- public static void data(String data, Port source, Port dest) {
- println((" data: ") + indent(purple(data) + (source==null ? "" : (" : " + source))+(" -> "+purple(""+dest)), " "));
+ public static void data(String data, BenkoBox source, BenkoBox dest) {
+ println((" data: ") + indent(purple(data) +
+ (source==null ? "" :
+ (" : " + source))+(" -> "+purple(""+dest)), " "));
}
- public static void token(Port source, Port dest) {
+ public static void token(BenkoBox source, BenkoBox dest) {
println(purple(" token: ") + (source + " -> " + purple(dest+"")));
}
public static String invert(Object o) { if (!ansi_color) return o+""; return "\033[7m"+o+"\033[0m"; }
public static String bold(Object o) { if (!ansi_color) return o+""; return "\033[1m"+o+"\033[0m"; }
+ public static void error(Object o) { println(red(o)); }
+
public static String indent(String s, String indent) {
StringBuffer ret = new StringBuffer();
for(int i=0; i<s.length(); i++) {
--- /dev/null
+package edu.berkeley.fleet.interpreter;
+import edu.berkeley.fleet.api.*;
+
+import java.util.*;
+import java.io.*;
+import edu.berkeley.fleet.api.Instruction;
+import edu.berkeley.fleet.api.BenkoBox;
+import edu.berkeley.fleet.*;
+import edu.berkeley.fleet.parser.*;
+
+public class Main {
+ private static boolean debugMemory = true;
+ public static boolean dump_fabric = false;
+ public static boolean dump_code = false;
+
+ public static void main(String[] s) throws Exception {
+ for(int i=0; i<s.length; i++) {
+ if (s[i].startsWith("--color=")) {
+ String val = s[i].substring(s[i].indexOf('=')+1);
+ if (val.equals("on")) {
+ Log.ansi_color = true;
+ continue;
+ } else if (val.equals("off")) {
+ Log.ansi_color = false;
+ continue;
+ }
+ } else if (s[i].startsWith("--dump-fabric")) {
+ dump_fabric = true;
+ continue;
+ } else if (s[i].startsWith("--dump-code")) {
+ dump_code = true;
+ continue;
+
+ } else if (s[i].startsWith("--memory=")) {
+ String val = s[i].substring(s[i].indexOf('=')+1);
+ if (val.equals("hide")) {
+ debugMemory = false;
+ continue;
+ } else if (val.equals("show")) {
+ debugMemory = true;
+ continue;
+ }
+ }
+ System.out.println("Fleeterpreter usage:");
+ System.out.println("");
+ System.out.println(" --dump-fabric");
+ System.out.println(" --dump-code");
+ System.out.println(" --color={on|off}");
+ System.out.println(" --inboxes={configured|unconfigured}");
+ System.out.println(" --memory={hide|show}");
+ System.exit(-1);
+ }
+ new Main().go(new InputStreamReader(System.in));
+ }
+
+ public void go(Reader r) throws Exception {
+ Interpreter fleet = new Interpreter();
+ CodeBag rootCodeBag = new Parser(fleet).walk(r);
+ if (dump_fabric) {
+ fleet.dumpFabric(false);
+
+ } else if (dump_code) {
+ fleet.dumpFabric(true);
+ try {
+ rootCodeBag.dump(fleet);
+ } catch (Exception e) { throw new RuntimeException(e); }
+
+ } else if (rootCodeBag != null) {
+ if (debugMemory) { fleet.dumpMem(); }
+ System.out.println(rootCodeBag);
+ rootCodeBag.dispatch(fleet);
+ fleet.go();
+ if (debugMemory) { fleet.dumpMem(); }
+ }
+ }
+
+}
\ No newline at end of file
-package edu.berkeley.fleet;
+package edu.berkeley.fleet.interpreter;
+import edu.berkeley.fleet.api.*;
+import edu.berkeley.fleet.api.Instruction;
public abstract class Outbox extends InstructionPort {
/** number of tokens queued on the trigger input */
private int triggersReceived = 0;
- protected Outbox(Ship ship, String name) {
+ private Interpreter getInterpreter() { return ((InterpreterShip)getShip()).getInterpreter(); }
+
+ protected Outbox(InterpreterShip ship, String name) {
super(ship, name);
}
}
int register;
- protected final boolean service(Instruction instruction) {
+ protected final boolean service(Instruction.Executable instruction) {
// if no instruction waiting, do nothing
if (instruction == null) return false;
// check firing conditions
- if (instruction.trigger && triggersReceived <= 0) return false;
+ if (instruction.tokenIn && triggersReceived <= 0) return false;
if (instruction.dataIn && readyForItemFromShip) return false;
// consume trigger
- if (instruction.trigger) triggersReceived--;
+ if (instruction.tokenIn) triggersReceived--;
// consume item
if (instruction.dataIn) {
if (instruction.dataOut) {
// if item to be transmitted, send it
- send(instruction.destination.resolve(getShip().getFleet()), register);
- if (instruction.ack)
+ send((InterpreterBenkoBox)instruction.dest, register);
+ if (instruction.tokenOut)
throw new RuntimeException("outboxes may not send acks!");
- } else if (instruction.ack) {
+ } else if (instruction.tokenOut) {
// if no item was sent, we might still send an ack
- getFleet().sendToken(this, instruction.destination.resolve(getShip().getFleet()));
+ getInterpreter().sendToken(this, (InterpreterBenkoBox)instruction.dest);
}
return true;
}
/** this is invoked to transmit data; the subclass decides if it is a token or not */
- protected abstract void send(Port port, int data);
+ protected abstract void send(InterpreterBenkoBox port, int data);
/** subclass invokes this to add an item from the ship */
protected final void addItemFromShip(int data) {
-package edu.berkeley.fleet;
+package edu.berkeley.fleet.interpreter;
+import edu.berkeley.fleet.api.*;
+/** a port which receives only tokens */
public class TokenInbox extends Inbox {
- public TokenInbox(Ship ship, String name) {
+ public TokenInbox(InterpreterShip ship, String name) {
super(ship, name);
}
--- /dev/null
+package edu.berkeley.fleet.interpreter;
+import edu.berkeley.fleet.api.*;
+
+/** a port which outputs only tokens */
+public class TokenOutbox extends Outbox {
+
+ public TokenOutbox(InterpreterShip ship, String name) {
+ super(ship, name);
+ }
+
+ private Interpreter getInterpreter() { return ((InterpreterShip)getShip()).getInterpreter(); }
+ protected void send(InterpreterBenkoBox port, int data) {
+ getInterpreter().sendToken(this, port);
+ }
+
+ public boolean readyForTokenFromShip() {
+ return super.readyForItemFromShip();
+ }
+
+ public void addTokenFromShip() {
+ addItemFromShip(0);
+ }
+
+}
--- /dev/null
+package edu.berkeley.fleet.parser;
+
+import edu.berkeley.fleet.api.*;
+
+// used only for special interpreter parsing extensions
+import edu.berkeley.fleet.interpreter.Interpreter;
+
+import edu.berkeley.fleet.interpreter.CodeBag;
+
+import edu.berkeley.sbp.*;
+import edu.berkeley.sbp.chr.*;
+import edu.berkeley.sbp.misc.*;
+import edu.berkeley.sbp.meta.*;
+import edu.berkeley.sbp.bind.*;
+import edu.berkeley.sbp.util.*;
+import java.util.*;
+import java.io.*;
+
+// FIXME: eliminate use of CodeBag class
+
+/**
+ * @author Adam Megacz <megacz@cs.berkeley.edu>
+ * @author Thomas Kho <tkho@eecs.berkeley.edu>
+ */
+public class Parser {
+
+ public Parser(Fleet fleet) {
+ this.fleet = fleet;
+ }
+
+ //////////////////////////////////////////////////////////////////////////////
+
+ private HashMap<String,Ship> shipMap =
+ new HashMap<String,Ship>();
+
+ static Tree<String> parse(Reader r) throws Exception {
+ InputStream grammarStream =
+ Parser.class.getClassLoader().getResourceAsStream("edu/berkeley/fleet/parser/fleet.g");
+ CharParser metaGrammarParser = new CharParser(MetaGrammar.newInstance());
+ Tree<String> parsedGrammar = metaGrammarParser.parse(new CharInput(grammarStream)).expand1();
+ Union grammar = Grammar.create(parsedGrammar, "s", new Grammar.Bindings() { });
+ CharParser parser = new CharParser(grammar);
+ Tree tree = parser.parse(new CharInput(r)).expand1();
+ return tree;
+ }
+
+ private Fleet fleet;
+ private ArrayList<String> imports = new ArrayList<String>();
+
+
+ public CodeBag walk(Reader r) throws Exception {
+ return walk((Tree<String>)parse(r));
+ }
+
+ CodeBag walk(Tree<String> t) {
+ CodeBag rootCodeBag = null;
+ String head = t.head();
+ if (head==null) {
+ } else if (head.equals("Program")) {
+ for(Tree<String> tc : t.child(0))
+ walk(tc);
+ CodeBag cb = new CodeBag(null, null);
+ if (t.size()>1)
+ for(Tree<String> statement : t.child(1))
+ fillCodeBag(statement, cb);
+ rootCodeBag = cb;
+
+ } else if (head.equals("Import")) {
+ imports.add(string(t.child(0)));
+
+ } else if (head.equals("Ship")) {
+ String name = name(t.child(0));
+ String type = string(t.child(1));
+ Ship ship = null;
+ if (fleet instanceof Fleet) {
+ String classname = type;
+ boolean good = false;
+ for(String s : imports)
+ if ((ship = ((Interpreter)fleet).tryCreate(s+"."+classname, name)) != null)
+ break;
+ if (ship==null)
+ throw new RuntimeException("couldn't find a ship called \""+classname+"\"");
+ } else {
+ ship = allocateShip(type);
+ }
+ shipMap.put(name, ship);
+
+ } else if (head.equals("Include")) {
+ try {
+ walk(parse(new InputStreamReader(new FileInputStream(string(t.child(0))))));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ } else if (head.equals("Memory")) {
+ if (((Interpreter)fleet).mem.length != 0)
+ throw new RuntimeException("multiple memory directives found");
+ Tree<String> m = t.child(0);
+ int[] mem = new int[m.size()];
+ for(int i=0; i<mem.length; i++)
+ mem[i] = Integer.parseInt(string(m.child(i)));
+ ((Interpreter)fleet).mem = mem;
+ }
+ return rootCodeBag;
+ }
+
+ String string(Tree<String> t) {
+ String ret = "";
+ if (t.head() != null) ret += t.head();
+ for(Tree<String> c : t)
+ ret += string(c);
+ return ret;
+ }
+
+ String name(Tree<String> t) {
+ return string(t.child(0))+string(t.child(1));
+ }
+
+ BenkoBox portReference(Tree<String> t) {
+ if (!"Port".equals(t.head())) return null;
+ String shipName = name(t.child(0));
+ String portName = name(t.child(1));
+ Ship ship = shipMap.get(shipName);
+ if (ship==null) throw new RuntimeException("no such ship \""+shipName+"\"");
+ for(BenkoBox b : ship.getBenkoBoxes())
+ if (b.getName().equals(portName))
+ return b;
+ throw new RuntimeException("no such benkobox \""+portName+"\" on ships of type \""+ship.getType()+"\"");
+ }
+
+ private HashMap<String,Integer> numAllocated = new HashMap<String,Integer>();
+ Ship allocateShip(String shipType) {
+ int allocated = 0;
+ if (numAllocated.get(shipType) != null)
+ allocated = numAllocated.get(shipType);
+ numAllocated.put(shipType, allocated+1);
+ for(Iterator<Ship> it = fleet.iterator();
+ it.hasNext();
+ ) {
+ Ship s = it.next();
+ if (s.getType().equals(shipType)) {
+ if (allocated == 0) return s;
+ allocated--;
+ }
+ }
+ throw new RuntimeException("no more ships of type \""+shipType+"\"");
+ }
+
+ void fillCodeBag(Tree<String> t, CodeBag cb) {
+ if (t.head()==null) return;
+ else if (t.head().equals("NamedCodeBag")) {
+ CodeBag cb2 = new CodeBag(cb, name(t.child(0)));
+ for(Tree<String> statement : t.child(1))
+ fillCodeBag(statement, cb2);
+
+ } else if (t.head().equals("Literal")) {
+ int literal = Integer.parseInt(string(t.child(0)));
+ BenkoBox benkobox = portReference(t.child(1));
+ cb.add(new Instruction.Literal.Absolute(benkobox, literal));
+
+ } else if (t.head().equals("Fiber")) {
+ BenkoBox benkobox = portReference(t.child(0));
+
+ OUTER: for(Tree tt : t.child(1)) {
+ int count = 1;
+ Tree ttx = null;
+ boolean recycle = false;
+ ttx = tt.child(1);
+ if (tt.size() > 1) {
+ tt = tt.child(0);
+ if (tt.size() > 0 && tt.child(0).size()>0) {
+ tt = tt.child(0);
+ if (tt.child(0).size() == 0) count=1;
+ else if (tt.child(0).size() > 0 && "Star".equals(tt.child(0).child(0).head())) count=0;
+ else count = Integer.parseInt(string(tt.child(0)));
+ if (tt.size() > 1 && tt.child(1).size() > 0)
+ recycle = true;
+ }
+ }
+ boolean tokenIn = false;
+ boolean dataIn = false;
+ boolean latch = false;
+ boolean dataOut = false;
+ boolean tokenOut = false;
+ BenkoBox dest = null;
+ for(int i=0; i<ttx.size(); i++) {
+ Tree ttt = ttx.child(i);
+ if ("Wait".equals(ttt.head())) { tokenIn = true; }
+ else if ("Kill".equals(ttt.head())) {
+ cb.add(new Instruction.Kill(benkobox, count));
+ continue OUTER;
+ }
+ 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 ("Deliver".equals(ttt.head())) { dataOut = true; }
+ else if ("Ack".equals(ttt.head())) { tokenOut = true; dest = portReference(ttt.child(0)); }
+ }
+ cb.add(new Instruction.Executable(benkobox,
+ dest, count, tokenIn, dataIn, latch, dataOut, tokenOut, recycle));
+ }
+ }
+ }
+}
| Literal:: int ":" "sendto" Port /ws
| NamedCodeBag:: name ":" "{" CodeBagBody "}" /ws
-Instruction = Instruction:: ("[" (int|(Star::"*")) "]" ws!)? (Command +/ (ws! "," ws!))
-Command = Wait:: "wait"
+Instruction = Instruction:: (Brack:: "[" (int|(Star::"*"))? ("r")? "]" ws!)? (Command +/ (ws! "," ws!) ws! ";"!)
+Command = Kill:: "kill"
+ | Wait:: "wait"
| Discard:: "discard"
| Take:: "take"
| SendTo:: "sendto" ws! Port
- | Accept:: "accept"
+ | Deliver:: "deliver"
| Ack:: "ack" ws! Port
Source = Port
package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
import edu.berkeley.fleet.*;
import java.util.*;
/**
* @author Adam Megacz <megacz@cs.berkeley.edu>
*/
-public class AdderShip extends Ship {
+public class Adder extends InterpreterShip {
private int link;
public String getBalsaName() { return "adder"; }
- public AdderShip(Fleet fleet, String name) {
+ public Adder(Interpreter fleet, String name) {
super(fleet, name);
}
--- /dev/null
+package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
+import edu.berkeley.fleet.*;
+
+import java.util.*;
+import java.io.*;
+
+public class Alu1 extends InterpreterShip {
+
+ DataInbox in = new DataInbox(this, "in");
+ DataInbox op = new DataInbox(this, "op");
+ DataOutbox out = new DataOutbox(this, "out");
+
+ public Alu1(Interpreter fleet, String name) { super(fleet, name); }
+
+ public String getBalsaName() { return "alu1"; }
+
+ public void service() {
+ if (in.dataReadyForShip() && op.dataReadyForShip()) {
+ int data = in.removeDataForShip();
+ int opcode = in.removeDataForShip();
+ switch(opcode) {
+ case 0: out.addDataFromShip(-1 * data); // NEG
+ break;
+ case 1: out.addDataFromShip(data+1); // INC
+ break;
+ case 2: out.addDataFromShip(data-1); // DEC
+ break;
+ case 3: out.addDataFromShip(Math.abs(data)); // ABS
+ break;
+ default: out.addDataFromShip(0);
+ break;
+ }
+ }
+ }
+
+}
--- /dev/null
+package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
+import edu.berkeley.fleet.*;
+
+import java.util.*;
+import java.io.*;
+
+public class Alu2 extends InterpreterShip {
+
+ DataInbox ap = new DataInbox(this, "a");
+ DataInbox bp = new DataInbox(this, "b");
+ DataInbox opp = new DataInbox(this, "op");
+ DataOutbox out = new DataOutbox(this, "out");
+
+ public Alu2(Interpreter fleet, String name) { super(fleet, name); }
+
+ public String getBalsaName() { return "alu2"; }
+
+ public void service() {
+ if (ap.dataReadyForShip() && bp.dataReadyForShip() && opp.dataReadyForShip()) {
+ int a = ap.removeDataForShip();
+ int b = bp.removeDataForShip();
+ int op = opp.removeDataForShip();
+ switch(op) {
+ case 0: out.addDataFromShip(a+b); // ADD
+ break;
+ case 1: out.addDataFromShip(a-b); // SUB
+ break;
+ case 2: out.addDataFromShip(a*b); // MUL
+ break;
+ case 3: out.addDataFromShip(a/b); // DIV
+ break;
+ case 4: out.addDataFromShip(a%b); // REM
+ break;
+ default: out.addDataFromShip(0);
+ break;
+ }
+ }
+ }
+
+}
package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
import edu.berkeley.fleet.*;
import java.util.*;
/**
* @author Dominic Antonelli <dantonel@berkeley.edu>
*/
-public class ArithmeticShip extends Ship {
+public class ArithmeticShip extends InterpreterShip {
private int link;
DataInbox cmd = new DataInbox(this, "cmd");
DataOutbox out = new DataOutbox(this, "out");
- public ArithmeticShip(Fleet fleet, String name) {
+ public ArithmeticShip(Interpreter fleet, String name) {
super(fleet, name);
}
+++ /dev/null
-package edu.berkeley.fleet.ships;
-import edu.berkeley.fleet.*;
-
-import java.util.*;
-import java.io.*;
-
-public class BitBucketShip extends Ship {
-
- TokenInbox token = new TokenInbox(this, "token");
- DataInbox data = new DataInbox(this, "data");
-
- public BitBucketShip(Fleet fleet, String name) {
- super(fleet, name);
- }
-
- public void service() {
- if (token.tokenReadyForShip()) token.removeTokenForShip();
- if (data.dataReadyForShip()) data.removeDataForShip();
- }
-
-}
package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
import edu.berkeley.fleet.*;
import java.util.*;
import java.io.*;
-public class CommandShip extends Ship {
+public class Command extends InterpreterShip {
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) {
+ public Command(Interpreter fleet, String name) {
super(fleet, name);
}
package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
import edu.berkeley.fleet.*;
import java.util.*;
import java.io.*;
-public class CounterShip extends Ship {
+public class Counter extends InterpreterShip {
private int count = 0;
TokenInbox decrement = new TokenInbox(this, "decrement");
TokenOutbox zero = new TokenOutbox(this, "zero");
- public CounterShip(Fleet fleet, String name) {
+ public Counter(Interpreter fleet, String name) {
super(fleet, name);
}
--- /dev/null
+package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
+import edu.berkeley.fleet.*;
+
+import java.util.*;
+import java.io.*;
+
+public class DeMux extends InterpreterShip {
+
+ DataInbox inp = new DataInbox(this, "in");
+ DataInbox selp = new DataInbox(this, "select");
+ DataOutbox truep = new DataOutbox(this, "true");
+ DataOutbox falsep = new DataOutbox(this, "false");
+
+ public String getBalsaName() { return "demux"; }
+
+ public DeMux (Interpreter fleet, String name) {
+ super(fleet, name);
+ }
+
+ public void service() {
+ if (inp.dataReadyForShip() && selp.dataReadyForShip() &&
+ truep.readyForDataFromShip() && falsep.readyForDataFromShip()) {
+ int in = inp.removeDataForShip();
+ int sel = selp.removeDataForShip();
+ if (sel==0)
+ falsep.addDataFromShip(in);
+ else
+ truep.addDataFromShip(in);
+ }
+ }
+
+}
+
package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
import edu.berkeley.fleet.*;
import java.util.*;
import java.io.*;
-public class DebugShip extends Ship {
+public class Debug extends InterpreterShip {
//TokenInbox token = new TokenInbox(this, "token");
DataInbox data = new DataInbox(this, "data", true, false);
public String getBalsaName() { return "debug"; }
- public DebugShip(Fleet fleet, String name) {
+ public Debug(Interpreter fleet, String name) {
super(fleet, name);
}
--- /dev/null
+package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
+import edu.berkeley.fleet.*;
+
+import java.util.*;
+import java.io.*;
+
+public class Dup extends InterpreterShip {
+
+ DataInbox in = new DataInbox(this, "in");
+ DataOutbox a = new DataOutbox(this, "a");
+ DataOutbox b = new DataOutbox(this, "b");
+
+ public String getBalsaName() { return "dup"; }
+
+ public Dup (Interpreter fleet, String name) {
+ super(fleet, name);
+ }
+
+ public void service() {
+ if (in.dataReadyForShip() && a.readyForDataFromShip() && b.readyForDataFromShip()) {
+ int data = in.removeDataForShip();
+ a.addDataFromShip(data);
+ b.addDataFromShip(data);
+ }
+ }
+
+}
+
--- /dev/null
+package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
+import edu.berkeley.fleet.*;
+
+import java.util.*;
+import java.io.*;
+
+public class Dup3 extends InterpreterShip {
+
+ DataInbox in = new DataInbox(this, "in");
+ DataOutbox a = new DataOutbox(this, "a");
+ DataOutbox b = new DataOutbox(this, "b");
+ DataOutbox c = new DataOutbox(this, "c");
+
+ public String getBalsaName() { return "dup3"; }
+
+ public Dup3 (Interpreter fleet, String name) {
+ super(fleet, name);
+ }
+
+ public void service() {
+ if (in.dataReadyForShip() && a.readyForDataFromShip() && b.readyForDataFromShip() && c.readyForDataFromShip()) {
+ int data = in.removeDataForShip();
+ a.addDataFromShip(data);
+ b.addDataFromShip(data);
+ c.addDataFromShip(data);
+ }
+ }
+
+}
+
package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
import edu.berkeley.fleet.*;
import java.util.*;
/**
* @author Dominic Antonelli <dantonel@berkeley.edu>
*/
-public class DuplicatorShip extends Ship {
+public class DuplicatorShip extends InterpreterShip {
DataInbox in = new DataInbox(this, "in");
DataOutbox out0 = new DataOutbox(this, "out0");
DataOutbox out2 = new DataOutbox(this, "out2");
DataOutbox out3 = new DataOutbox(this, "out3");
- public DuplicatorShip (Fleet fleet, String name) {
+ public DuplicatorShip (Interpreter fleet, String name) {
super(fleet, name);
}
package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
import edu.berkeley.fleet.*;
import java.util.*;
import java.io.*;
-public class FetchShip extends Ship {
+public class FetchShip extends InterpreterShip {
DataInbox codebag = new DataInbox(this, "codebag");
TokenInbox release = new TokenInbox(this, "release");
TokenInbox revoke = new TokenInbox(this, "revoke");
TokenOutbox done = new TokenOutbox(this, "done");
- public FetchShip(Fleet fleet, String name) {
+ public FetchShip(Interpreter fleet, String name) {
super(fleet, name);
}
release.removeTokenForShip();
if (cb==null)
throw new RuntimeException("bogus codebag -- this should not happen");
- cb.dispatch(getFleet());
+ cb.dispatch(getInterpreter());
}
done.addTokenFromShip();
package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
import edu.berkeley.fleet.*;
import java.util.*;
import java.io.*;
-public class FifoShip extends Ship {
+public class Fifo extends InterpreterShip {
DataInbox in = new DataInbox(this, "in");
DataOutbox out = new DataOutbox(this, "out");
- public String getBalsaName() { return "fifoship"; }
+ public String getBalsaName() { return "fifo"; }
private Queue<Integer> fifo = new LinkedList<Integer>();
- public FifoShip(Fleet fleet, String name) {
+ public Fifo(Interpreter fleet, String name) {
super(fleet, name);
}
package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
import edu.berkeley.fleet.*;
import java.util.*;
import java.io.*;
-public class HaltShip extends Ship {
+public class HaltShip extends InterpreterShip {
TokenInbox in = new TokenInbox(this, "in");
- public HaltShip(Fleet fleet, String name) {
+ public HaltShip(Interpreter fleet, String name) {
super(fleet, name);
}
public void service() {
if (!in.tokenReadyForShip()) return;
in.removeTokenForShip();
- getFleet().halt = true;
+ ((Interpreter)getInterpreter()).halt = true;
Log.println(Log.yellow(" HALT: ====== halt ship got a token; halting the fleet ======"));
}
package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
import edu.berkeley.fleet.*;
import java.util.*;
import java.io.*;
-public class HomeworkCounter extends Ship {
+public class HomeworkCounter extends InterpreterShip {
private int count = -1;
DataInbox load = new DataInbox(this, "load");
TokenInbox ask = new TokenInbox(this, "ask");
- public HomeworkCounter(Fleet fleet, String name) {
+ public HomeworkCounter(Interpreter fleet, String name) {
super(fleet, name);
}
--- /dev/null
+package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
+import edu.berkeley.fleet.*;
+
+import java.util.*;
+import java.io.*;
+
+public class Lut extends InterpreterShip {
+
+ DataInbox ap = new DataInbox(this, "a");
+ DataInbox bp = new DataInbox(this, "b");
+ DataInbox lutp = new DataInbox(this, "lut");
+ DataOutbox out = new DataOutbox(this, "out");
+
+ public Lut(Interpreter fleet, String name) { super(fleet, name); }
+
+ public String getBalsaName() { return "lut"; }
+
+ public void service() {
+ if (ap.dataReadyForShip() && bp.dataReadyForShip() && lutp.dataReadyForShip()) {
+ int a = ap.removeDataForShip();
+ int b = bp.removeDataForShip();
+ int lut = lutp.removeDataForShip();
+ int ret = 0;
+ if ((lut & 1) != 0) ret |= (~a) & (~b);
+ if ((lut & 2) != 0) ret |= (a) & (~b);
+ if ((lut & 4) != 0) ret |= (~a) & (b);
+ if ((lut & 8) != 0) ret |= a & b;
+ out.addDataFromShip(ret);
+ }
+ }
+
+}
package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
import edu.berkeley.fleet.*;
import java.util.*;
import java.io.*;
-public class MemoryReadShip extends Ship {
+public class MemoryReadShip extends InterpreterShip {
boolean _loaded = false;
int _count = 0;
DataOutbox data = new DataOutbox(this, "data");
TokenOutbox done = new TokenOutbox(this, "done");
- public MemoryReadShip(Fleet fleet, String name) {
+ public MemoryReadShip(Interpreter fleet, String name) {
super(fleet, name);
}
public void service() {
if (_count > 0) {
if (!data.readyForDataFromShip()) return;
- data.addDataFromShip(_addr>=getFleet().mem.length ? 0 : getFleet().mem[_addr]);
+ data.addDataFromShip(_addr>=getInterpreter().mem.length ? 0 : getInterpreter().mem[_addr]);
_count--;
_addr += _stride;
if (_count==0)
package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
import edu.berkeley.fleet.*;
import java.util.*;
/**
* @author Thomas Kho <tkho@eecs.berkeley.edu>
*/
-public class MemoryWriteShip extends Ship {
+public class MemoryWriteShip extends InterpreterShip {
int _count = 0;
int _stride = 0;
DataInbox data = new DataInbox(this, "data");
TokenOutbox done = new TokenOutbox(this, "done");
- public MemoryWriteShip(Fleet fleet, String name) {
+ public MemoryWriteShip(Interpreter fleet, String name) {
super(fleet, name);
}
public void service() {
if (_count > 0) {
if (!data.dataReadyForShip()) return;
- getFleet().writeMem(_addr, data.removeDataForShip());
+ getInterpreter().writeMem(_addr, data.removeDataForShip());
_count--;
_addr += _stride;
if (_count==0)
package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
import edu.berkeley.fleet.*;
import java.util.*;
/**
* @author Dominic Antonelli <dantonel@berkeley.edu>
*/
-public class MultiplierShip extends Ship {
+public class MultiplierShip extends InterpreterShip {
private int link;
DataOutbox out0 = new DataOutbox(this, "out0");
DataOutbox out1 = new DataOutbox(this, "out1");
- public MultiplierShip(Fleet fleet, String name) {
+ public MultiplierShip(Interpreter fleet, String name) {
super(fleet, name);
}
--- /dev/null
+package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
+import edu.berkeley.fleet.*;
+
+import java.util.*;
+import java.io.*;
+
+public class Mux extends InterpreterShip {
+
+ DataInbox ap = new DataInbox(this, "a");
+ DataInbox bp = new DataInbox(this, "b");
+ DataInbox choicep = new DataInbox(this, "select");
+ DataOutbox out = new DataOutbox(this, "out");
+
+ public Mux(Interpreter fleet, String name) { super(fleet, name); }
+
+ public String getBalsaName() { return "mux"; }
+
+ public void service() {
+ if (ap.dataReadyForShip() && bp.dataReadyForShip() && choicep.dataReadyForShip()) {
+ int a = ap.removeDataForShip();
+ int b = bp.removeDataForShip();
+ int choice = choicep.removeDataForShip();
+ out.addDataFromShip(choice==0 ? a : b);
+ }
+ }
+
+}
package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
import edu.berkeley.fleet.*;
import java.util.*;
/**
* @author Dominic Antonelli <dantonel@berkeley.edu>
*/
-public class ScatterShip extends Ship {
+public class ScatterShip extends InterpreterShip {
DataInbox in = new DataInbox(this, "in");
Vector<DataOutbox> out = new Vector<DataOutbox>();
private int size = 2;
private int state = 0;
- public ScatterShip(Fleet fleet, String name) {
+ public ScatterShip(Interpreter fleet, String name) {
super(fleet, name);
init();
}
--- /dev/null
+package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
+import edu.berkeley.fleet.*;
+
+import java.util.*;
+import java.io.*;
+
+public class Shifter extends InterpreterShip {
+
+ private int count = 0;
+
+ DataInbox valp = new DataInbox(this, "val");
+ DataInbox shamtp = new DataInbox(this, "shamt");
+ DataOutbox out = new DataOutbox(this, "out");
+
+ public Shifter(Interpreter fleet, String name) {
+ super(fleet, name);
+ }
+
+ public String getBalsaName() { return "shift"; }
+
+ public void service() {
+ if (valp.dataReadyForShip() && shamtp.dataReadyForShip()) {
+ int val = valp.removeDataForShip();
+ int shamt = shamtp.removeDataForShip();
+ if (shamt < 0) val = val >> (-1 * shamt);
+ else val = val << shamt;
+ out.addDataFromShip(val);
+ }
+ }
+
+}
--- /dev/null
+package edu.berkeley.fleet.ships;
+import edu.berkeley.fleet.interpreter.*;
+import edu.berkeley.fleet.*;
+
+import java.util.*;
+import java.io.*;
+
+public class Sort2 extends InterpreterShip {
+
+ DataInbox ap = new DataInbox(this, "a");
+ DataInbox bp = new DataInbox(this, "b");
+ DataOutbox min = new DataOutbox(this, "min");
+ DataOutbox max = new DataOutbox(this, "max");
+
+ public Sort2(Interpreter fleet, String name) { super(fleet, name); }
+
+ public String getBalsaName() { return "sort2"; }
+
+ public void service() {
+ if (ap.dataReadyForShip() && bp.dataReadyForShip()) {
+ int a = ap.removeDataForShip();
+ int b = bp.removeDataForShip();
+ max.addDataFromShip(Math.max(a,b));
+ min.addDataFromShip(Math.min(a,b));
+ }
+ }
+
+}
+++ /dev/null
-package edu.berkeley.fleet.ships;
-import edu.berkeley.fleet.*;
-
-import java.util.*;
-import java.io.*;
-
-public class TokenFifo extends Ship {
-
- private int count = 0;
-
- TokenOutbox out = new TokenOutbox(this, "out");
- TokenInbox in = new TokenInbox(this, "in");
-
- public TokenFifo(Fleet fleet, String name) {
- super(fleet, name);
- }
-
- public void service() {
- if (in.tokenReadyForShip()) {
- count++;
- in.removeTokenForShip();
- return;
- }
- if (count > 0 && out.readyForTokenFromShip()) {
- count--;
- out.addTokenFromShip();
- }
- }
-
-}
+++ /dev/null
-package edu.berkeley.fleet.ships;
-import edu.berkeley.fleet.*;
-
-import java.util.*;
-import java.io.*;
-
-public class TokenSourceShip extends Ship {
-
- TokenOutbox out = new TokenOutbox(this, "out");
-
- public TokenSourceShip(Fleet fleet, String name) {
- super(fleet, name);
- }
-
- public void service() {
- if (out.readyForTokenFromShip())
- out.addTokenFromShip();
- }
-
- public void shutdown() {
- }
-
-}