From: adam Date: Thu, 26 Jun 2008 07:23:44 +0000 (+0100) Subject: first pass overhaul of interpreter; still does not work X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=aa30d7ced239c556baa04a4bfb4732705c686909;p=fleet.git first pass overhaul of interpreter; still does not work --- diff --git a/src/edu/berkeley/fleet/interpreter/Inbox.java b/src/edu/berkeley/fleet/interpreter/Inbox.java deleted file mode 100644 index 6d2f8ad..0000000 --- a/src/edu/berkeley/fleet/interpreter/Inbox.java +++ /dev/null @@ -1,113 +0,0 @@ -package edu.berkeley.fleet.interpreter; -import edu.berkeley.sbp.util.ANSI; -import edu.berkeley.fleet.api.*; -import static edu.berkeley.fleet.util.BitManipulations.*; -import edu.berkeley.fleet.two.*; -import java.util.*; - -/** this is a generic inbox which stores <32-bit items (tokens or data) */ -public class Inbox extends InstructionDock { - - public boolean dataReadyForShip() { return itemReadyForShip; } - public Packet removePacketForShip() { remove(); return register; } - public Packet peekPacketForShip() { return register; } - public long removeDataForShip() { remove(); return register.value; } - - // private data ////////////////////////////////////////////////////////////////////////////// - - private Packet register = new Packet(null, null, 0, null); - - /** data which has arrived from the switch fabric but not been acted on */ - private Queue itemsFromFabric = new LinkedList(); - - /** true iff data is currently being presented to the ship */ - private boolean itemReadyForShip = false; - - /** if an ack token is pending, this is where it should be sent once the item is accepted */ - private Packet bufferedAck = null; - - public Inbox(InterpreterShip ship, DockDescription dd) { super(ship, new String[] { "" }, dd); } - public Inbox(InterpreterShip ship, String[] ports, DockDescription dd) { super(ship, ports, dd); } - - public void addDataFromFabric(Packet packet) { itemsFromFabric.add(packet); } - private void remove() { - if (!itemReadyForShip) - throw new RuntimeException("invoked accept() on an inbox which does not have items ready; your ship is buggy"); - itemReadyForShip = false; - if (bufferedAck != null) { bufferedAck.send(); bufferedAck = null; } - } - - ////////////////////////////////////////////////////////////////////////////// - - protected void setDataLatch(long value) { register = new Packet(getInterpreter(), null, value, null); } - protected long peekDataLatch() { return register.value; } - - /** invoked by superclass */ - protected final boolean service(Instruction instruction_) { - - // if data is stuck on itemPresentedToShip, wait for it to go somewhere before - // considering additional instructions - if (itemReadyForShip) return false; - - // if no instruction waiting, do nothing - if (instruction_ == null) return false; - - /* - if (instruction_ instanceof Instruction.Literal) { - register = new Packet(getInterpreter(), null, ((Instruction.Literal)instruction_).literal, null); - return true; - } else if (instruction_ instanceof Instruction.HalfLiteral) { - Instruction.HalfLiteral ll = (Instruction.HalfLiteral)instruction_; - long val = (register==null) ? 0 : register.value; - val = - ll.high - ? setField(36, 19, ll.literal, val) - : setField(18, 0, ll.literal, val); - register = new Packet(getInterpreter(), null, val, null); - return true; - } - */ - Instruction.Move instruction = (Instruction.Move)instruction_; - - // check firing conditions - if (instruction.tokenIn) - throw new RuntimeException("invalid instruction: " + instruction + - " (attempts to use trigger on an inbox)"); - - if (instruction.dataIn && itemsFromFabric.size()==0) return false; - - // consume inbound data+token - if (instruction.dataIn) { - if (instruction.latchData) { - register = itemsFromFabric.remove(); - } else { - itemsFromFabric.remove(); - } - } - - // if dataOut, present data to the ship - if (instruction.dataOut) { - itemReadyForShip = true; - - // and make note of the fact that we need to send an ack (if requested) - if (instruction.tokenOut) - bufferedAck = new Packet(getInterpreter(), this, 0, (InterpreterDestination)(Object)instruction.path); - - } else if (instruction.tokenOut) { - - // if dataOut is not set, we can send the data immediately - new Packet(getInterpreter(), this, 0, (InterpreterDestination)(Object)instruction.path).send(); - } - return true; - } - - protected void shutdown() { - if (itemsFromFabric.size() > 0) { - Log.println(ANSI.red(" WARNING: you left data on the input to inbox " + this + ":")); - for(Packet p : itemsFromFabric) - Log.println(" " + p.value); - } - super.shutdown(true); - } - -} diff --git a/src/edu/berkeley/fleet/interpreter/Interpreter.java b/src/edu/berkeley/fleet/interpreter/Interpreter.java index 3cc2324..69fd939 100644 --- a/src/edu/berkeley/fleet/interpreter/Interpreter.java +++ b/src/edu/berkeley/fleet/interpreter/Interpreter.java @@ -3,16 +3,18 @@ import java.io.*; import java.util.*; import java.util.concurrent.*; import java.lang.reflect.*; -import edu.berkeley.fleet.*; import edu.berkeley.sbp.util.ANSI; import edu.berkeley.fleet.api.*; import edu.berkeley.fleet.two.*; import edu.berkeley.fleet.assembler.*; -import edu.berkeley.fleet.two.*; import edu.berkeley.fleet.util.*; public class Interpreter extends FleetTwoFleet implements Parser.FleetWithDynamicShips { + private BlockingQueue debugStream = new LinkedBlockingQueue(); + private InterpreterShip debugShip = null; + private HashMap ships = new HashMap(); + public Iterator iterator() { return (Iterator)(Object)ships.values().iterator(); } public Ship getShip(String type, int ordinal) { for(Ship s : this) if (s.getType().equals(type)) @@ -21,101 +23,11 @@ public class Interpreter extends FleetTwoFleet implements Parser.FleetWithDynami return null; } - public int getWordWidth() { return 37; } - /** some "halt ship" can turn this on to stop the interpreter */ - private HashMap ships = new HashMap(); - private BlockingQueue debugStream = new LinkedBlockingQueue(); - - public int getWordSize() { return 37; } - - public FleetProcess run(final byte[] instructions) { - try { - final FleetProcess fp = new FleetProcess() { - public void dispatchInstruction(Instruction i) { throw new RuntimeException(); } - public void invokeInstruction(Instruction i) { throw new RuntimeException("not supported"); } - public Dock getDebugInputDock() { return null; } - public BitVector readWord() { - /* - try { - return debugStream.take(); - } catch (Exception e) { - throw new RuntimeException(e); - }*/ - throw new RuntimeException(); - } - protected void _terminate() { - // FIXME: hack - ships = new HashMap(); - debugStream = new LinkedBlockingQueue(); - } - }; - new Thread() { - public void run() { - try { - // find the first icache - InterpreterShip iscratch = null; - for(Ship ship : Interpreter.this) - if (ship.getClass().getSimpleName().equals("Memory")) { - iscratch = (InterpreterShip)ship; - break; - } - if (iscratch==null) { - BufferedReader br = - new BufferedReader(new InputStreamReader(new FileInputStream("ships/Memory.ship"))); - ShipDescription sd = new ShipDescription("Memory", br); - iscratch = (InterpreterShip)Class.forName("edu.berkeley.fleet.interpreter.Memory") - .getConstructor(new Class[] { Interpreter.class, String.class, ShipDescription.class }) - .newInstance(new Object[] { Interpreter.this, "memory", sd }); - } - iscratch - .getClass() - .getMethod("boot", new Class[] { byte[].class }) - .invoke(iscratch, new Object[] { instructions }); - - while(!fp.isTerminated()) - 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(InterpreterShip ship : ships.values()) - for(int j=0; j<10; j++) - ship._service(); - - // check the state of the ships - for(InterpreterShip ship : ships.values()) - ship.shutdown(); - - Log.println(ANSI.yellow(" DONE: ====== FLEET is halted. Have a nice day. ======")); - - } catch (Exception e) { - if (fp.isTerminated()) return; - throw new RuntimeException(e); - } - } - }.start(); - return fp; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public void dispatch(Instruction i, long address) { + void dispatch(Instruction i) { Log.dispatch(i); - - if (i instanceof Instruction.Tail) { - Instruction.Tail ic = (Instruction.Tail)i; - ((InstructionDock)(ic.dock)).tailged--; - - } else { - InstructionDock sourceDock = (InstructionDock)(((Instruction)i).dock); - ((InstructionDock)sourceDock).addInstruction(((Instruction)i)); - } + ((InterpreterDock)i.dock).addInstruction(i); } - public Iterator iterator() { return (Iterator)(Object)ships.values().iterator(); } - public Ship createShip(String shipType, String shipname) { try { Class c = Class.forName("edu.berkeley.fleet.interpreter."+shipType); @@ -124,6 +36,8 @@ public class Interpreter extends FleetTwoFleet implements Parser.FleetWithDynami ShipDescription sd = new ShipDescription(shipType, br); InterpreterShip ret = (InterpreterShip)con.newInstance(new Object[] { this, shipname, sd }); ships.put(shipname, ret); + if (shipType.equals("Debug") && debugShip == null) + debugShip = ret; return ret; } catch (Exception e) { e.printStackTrace(); @@ -131,7 +45,10 @@ public class Interpreter extends FleetTwoFleet implements Parser.FleetWithDynami } } - public void debug(long data) { + void debug(long d) { + throw new RuntimeException(); + } + void debug(BitVector data) { try { if (debugStream != null) debugStream.put(data); else Log.println(ANSI.invert(" DEBUG: got a datum: " + data+ANSI.clreol())); @@ -142,27 +59,19 @@ public class Interpreter extends FleetTwoFleet implements Parser.FleetWithDynami // Instruction Encoding ///////////////////////////////////////////////////////////////////////// - public Dock getUniversalSource() { return null; } + public Dock getUniversalSource() { + // FIXME + return debugShip.getDock("in"); + } - public long getDestAddr(Path path) { throw new RuntimeException(); } - public long getBoxInstAddr(Dock box) { return ((InstructionDock)box).getDestAddr(); } - public Path getPathByAddr(Dock source, long dest) { throw new RuntimeException(); } - public Destination getDestByAddr(long dest) { - /* - for(Ship ship : Interpreter.this) - for(Dock bb : ship) - if (getDestAddr(bb.getDataDestination())==dest) - return bb.getDataDestination(); - */ - return null; - } - public Dock getBoxByInstAddr(long dest) { - for(Ship ship : Interpreter.this) - for(Dock bb : ship) - if (getBoxInstAddr(bb) == dest) - return bb; - return null; - } + public long getDestAddr(Path path) { + // FIXME + throw new RuntimeException(); + } + public Path getPathByAddr(Dock source, long dest) { + // FIXME + throw new RuntimeException(); + } // ShipDescription ////////////////////////////////////////////////////////////////////////////// @@ -189,22 +98,13 @@ public class Interpreter extends FleetTwoFleet implements Parser.FleetWithDynami pw.println(""); for(DockDescription b : sd) { String name = b.getName(); - pw.print(" "); - if ( b.isInputDock()) pw.print("Inbox"); - if (!b.isInputDock()) pw.print("Outbox"); - pw.print(" box_"); + pw.print(" InterpreterDock box_"); pw.print(name); - pw.print(" = new "); - if ( b.isInputDock()) pw.print("Inbox"); - if (!b.isInputDock()) pw.print("Outbox"); - pw.print("(this, new String[] { "); - boolean first = true; - pw.print("\"\""); - pw.println("}, shipDescription.getDockDescription(\""+name+"\"));"); + pw.print(" = new InterpreterDock(this, shipDescription.getDockDescription(\""+name+"\"));"); } pw.println(""); pw.println(" public "+filename+"(Interpreter fleet, String name, ShipDescription sd) {"); - pw.println(" super(fleet, name, sd);"); + pw.println(" super(fleet, sd);"); for(DockDescription b : sd) pw.println(" addDock(\""+b.getName()+"\", box_"+b.getName()+");"); pw.println(" }"); @@ -216,5 +116,40 @@ public class Interpreter extends FleetTwoFleet implements Parser.FleetWithDynami } catch (Exception e) { throw new RuntimeException(e); } } -} + // Run ////////////////////////////////////////////////////////////////////////////// + public FleetProcess run(final Instruction[] instructions) { + InterpreterProcess ip = new InterpreterProcess(instructions); + new Thread(ip).start(); + return ip; + } + + private class InterpreterProcess extends FleetProcess implements Runnable { + private Instruction[] instructions; + public InterpreterProcess(Instruction[] instructions) { + this.instructions = instructions; + } + public void dispatchInstruction(Instruction i) { dispatch(i); } + public Dock getDebugInputDock() { return debugShip.getDock("in"); } + public BitVector readWord() { + try { + return debugStream.take(); + } catch (Exception e) { throw new RuntimeException(e); } + } + protected void _terminate() { } + public void run() { + try { + while(!isTerminated()) + for(InterpreterShip ship : ships.values()) + for(int j=0; j<10; j++) + ship._service(); + for(InterpreterShip ship : ships.values()) + ship.reset(); + debugStream.clear(); + } catch (Exception e) { + if (isTerminated()) return; + throw new RuntimeException(e); + } + } + } +} \ No newline at end of file diff --git a/src/edu/berkeley/fleet/interpreter/InterpreterDestination.java b/src/edu/berkeley/fleet/interpreter/InterpreterDestination.java index 784479c..6f709b4 100644 --- a/src/edu/berkeley/fleet/interpreter/InterpreterDestination.java +++ b/src/edu/berkeley/fleet/interpreter/InterpreterDestination.java @@ -2,9 +2,19 @@ package edu.berkeley.fleet.interpreter; import edu.berkeley.fleet.api.*; import java.util.*; -abstract class InterpreterDestination extends Destination { - public InterpreterDestination(InstructionDock d, boolean isInstructionDestination) { super(d); } - public abstract long getDestAddr(); - public abstract void addDataFromFabric(Packet packet); - public abstract String getDestinationName(); +class InterpreterDestination extends Destination { + + public InterpreterDestination(InterpreterDock d, boolean isInstructionDestination) { + super(d); + } + + /** adds the included datum to the port from the switch fabric side */ + public void addDataFromFabric(Packet packet) { + throw new RuntimeException(); + } + + + public String toString() { + return ""; + } } diff --git a/src/edu/berkeley/fleet/interpreter/InterpreterDock.java b/src/edu/berkeley/fleet/interpreter/InterpreterDock.java index 4353c8d..a578fa9 100644 --- a/src/edu/berkeley/fleet/interpreter/InterpreterDock.java +++ b/src/edu/berkeley/fleet/interpreter/InterpreterDock.java @@ -1,130 +1,76 @@ package edu.berkeley.fleet.interpreter; +import java.util.*; import edu.berkeley.sbp.util.ANSI; import edu.berkeley.fleet.two.*; import edu.berkeley.fleet.api.*; import edu.berkeley.fleet.api.Instruction; import static edu.berkeley.fleet.api.Predicate.*; -import java.util.*; - /** anything that has a source (instruction horn) address on the switch fabric */ -abstract class InstructionDock extends FleetTwoDock { +class InterpreterDock extends FleetTwoDock { - private final InterpreterShip ship; - private final Destination[] ports; - private final int addr = max_addr++; + // Dock State ////////////////////////////////////////////////////////////////////////////// - - public Path getPath(Destination d, BitVector signal) { - throw new RuntimeException(); - } - - public Iterable getDestinations() { - HashSet ret = new HashSet(); - for(Destination d : ports) ret.add(d); - return ret; - } - - public Destination getInstructionDestination() { - return ports[0]; - } - public Destination getDataDestination() { - return ports[0]; - } - - - /** adds the included datum to the port from the switch fabric side */ - public abstract void addDataFromFabric(Packet packet); - - - abstract void shutdown(); - - public Ship getShip() { return ship; } - public Fleet getFleet() { return getShip().getFleet(); } - public String toString() { return ship+"."+getName(); } - public int getInstructionFifoSize() { return 4; } - - Interpreter getInterpreter() { return ((InterpreterShip)getShip()).getInterpreter(); } - - public long getDestAddr() { return addr; } - - private static int max_addr; - private class InterpreterDockDestination extends InterpreterDestination { - public String name; - public long addr = max_addr++; - public InterpreterDockDestination(String name, InstructionDock id, boolean isInstructionDestination) { - super(id, isInstructionDestination); - this.name = name; - } - public String getDestinationName() { return name; } - public Ship getShip() { return InstructionDock.this.getShip(); } - public void addDataFromFabric(Packet packet) { InstructionDock.this.addDataFromFabric(packet); } - public String toString() { return getShip()+"."+getName(); } - public long getDestAddr() { return addr; } - } - - public int tailged = 0; - public boolean flag_a = false; public boolean flag_b = false; public boolean flag_c = false; - - /** the currently executing instruction */ + public int ilc = 1; + public int olc = 1; + public BitVector dataLatch = new BitVector(getShip().getFleet().getWordWidth()); + public InterpreterPath pathLatch = null; + public boolean hatchIsOpen = true; private Instruction executing = null; - - /** all instructions waiting to be executed (excludes executing) */ private Queue instructions = new LinkedList(); - public int loopCounter = 0; - private int repeatCounter = 1; - - InstructionDock(InterpreterShip ship, String[] ports, DockDescription bbd) { - super(ship, bbd); - this.ship = ship; - this.ports = new Destination[ports.length]; - for(int i=0; i 0) - instructions.remove(); + instructions.clear(); } - public void kill() { - repeatCounter = 1; - if (executing != null) { executing = null; return; } - if (instructions.size()==0) - throw new RuntimeException("deadlocked " + this + " by killing too many instructions"); - instructions.remove(); - } + // Destinations ////////////////////////////////////////////////////////////////////////////// - /** an instruction arrives from the instruction horn */ - void addInstruction(Instruction instr) { instructions.add(instr); } + /** includes the epilogue fifo */ + public InterpreterDestination instructionDestination = new InterpreterDestination(this, true); + public InterpreterDestination dataDestination = new InterpreterDestination(this, false); - protected void shutdown(boolean leaveAsInbox) { - if (!(executing != null || instructions.size() > 0)) return; - Log.println(ANSI.red(" WARNING: you left instructions on the instruction queue of port " + - this + "; they are:")); - if (executing != null) - Log.println(" " + executing); - for(Instruction i : instructions) - Log.println(" " + i); + InterpreterDock(InterpreterShip ship, DockDescription bbd) { + super(ship, bbd); + } + + public void addInstruction(Instruction i) { + throw new RuntimeException(); } + public Path getPath(Destination d, BitVector signal) { return new InterpreterPath(this, (InterpreterDestination)d, signal); } + public Destination getInstructionDestination() { return instructionDestination; } + public Destination getDataDestination() { return dataDestination; } + public int getInstructionFifoSize() { return Integer.MAX_VALUE; } + public Interpreter getInterpreter() { return ((InterpreterShip)getShip()).getInterpreter(); } + // interface to subclass /////////////////////////////////////////////////////////////////////// /** this will be invoked periodically; should return true to "consume" an instruction, false to leave it executing */ - protected abstract void setDataLatch(long value); - protected abstract long peekDataLatch(); + protected void setDataLatch(long value) { throw new RuntimeException(); } + protected long peekDataLatch() { throw new RuntimeException(); } + public boolean dataReadyForShip() { throw new RuntimeException(); } + public Packet removePacketForShip() { throw new RuntimeException(); } + public Packet peekPacketForShip() { throw new RuntimeException(); } + public long removeDataForShip() { throw new RuntimeException(); } + public final boolean readyForDataFromShip() { throw new RuntimeException(); } + public void addDataFromShip(long data) { throw new RuntimeException(); } + public void addDataFromFabric(Packet packet) { throw new RuntimeException(); } + protected final void addItemFromShip(long data) { throw new RuntimeException(); } protected final void service() { /* - if (tailged > 0) return; if (executing==null && instructions.size() > 0) executing = instructions.remove(); if (executing==null) return; @@ -201,7 +147,4 @@ abstract class InstructionDock extends FleetTwoDock { } */ } - - - } diff --git a/src/edu/berkeley/fleet/interpreter/InterpreterPath.java b/src/edu/berkeley/fleet/interpreter/InterpreterPath.java new file mode 100644 index 0000000..0226459 --- /dev/null +++ b/src/edu/berkeley/fleet/interpreter/InterpreterPath.java @@ -0,0 +1,25 @@ +package edu.berkeley.fleet.interpreter; +import edu.berkeley.fleet.api.*; +import java.util.*; + +class InterpreterPath extends Path { + + public final InterpreterDock source; + public final InterpreterDestination dest; + public final BitVector signal; + + public InterpreterPath(InterpreterDock source, + InterpreterDestination dest, + BitVector signal) { + this.source = source; + this.dest = dest; + this.signal = signal; + } + + public Dock getSource() { return source; } + public Destination getDestination() { return dest; } + public int getBufferingAmount() { return Integer.MAX_VALUE; } + public int getLatencyMetric() { return 0; } + public BitVector getSignal() { return signal; } + +} diff --git a/src/edu/berkeley/fleet/interpreter/InterpreterShip.java b/src/edu/berkeley/fleet/interpreter/InterpreterShip.java index 8c180ca..86a3101 100644 --- a/src/edu/berkeley/fleet/interpreter/InterpreterShip.java +++ b/src/edu/berkeley/fleet/interpreter/InterpreterShip.java @@ -8,14 +8,12 @@ import java.io.*; abstract class InterpreterShip extends FleetTwoShip { /** You should instantiate a bunch of Inboxes and Outboxes in your constructor */ - public InterpreterShip(Interpreter fleet, String name, ShipDescription sd) { + public InterpreterShip(Interpreter fleet, ShipDescription sd) { super(fleet, sd); } - private HashMap ports = new HashMap(); - + private HashMap ports = new HashMap(); public Iterator iterator() { return (Iterator)(Object)ports.values().iterator(); } - public Interpreter getInterpreter() { return (Interpreter)getFleet(); } /** * Override this method, check inboxes for the data you need, and @@ -25,16 +23,18 @@ abstract class InterpreterShip extends FleetTwoShip { public abstract void service(); public final void _service() { - for(InstructionDock p : ports.values()) p.service(); + for(InterpreterDock p : ports.values()) p.service(); service(); } - protected void addDock(String name, InstructionDock port) { + protected void addDock(String name, InterpreterDock port) { ports.put(name, port); } - public void shutdown() { - for(InstructionDock p : ports.values()) - p.shutdown(); + public void reset() { + for(InterpreterDock p : ports.values()) + p.reset(); } + + public Interpreter getInterpreter() { return (Interpreter)getFleet(); } } diff --git a/src/edu/berkeley/fleet/interpreter/Outbox.java b/src/edu/berkeley/fleet/interpreter/Outbox.java deleted file mode 100644 index 8b06cbc..0000000 --- a/src/edu/berkeley/fleet/interpreter/Outbox.java +++ /dev/null @@ -1,121 +0,0 @@ -package edu.berkeley.fleet.interpreter; -import edu.berkeley.sbp.util.ANSI; -import edu.berkeley.fleet.api.*; -import edu.berkeley.fleet.two.*; -import edu.berkeley.sbp.util.*; -import edu.berkeley.fleet.util.*; -import static edu.berkeley.fleet.util.BitManipulations.*; -import edu.berkeley.fleet.two.*; -import edu.berkeley.fleet.api.Instruction; - -public class Outbox extends InstructionDock { - - /** are we ready to accept another item from the ship? */ - private boolean readyForDataFromShip = false; - private boolean haveDataFromShip = false; - - /** data which has been presented by the ship and is waiting to depart */ - private long itemPresentedByShip; - - /** number of tokens queued on the trigger input */ - private int triggersReceived = 0; - - /** the latched value */ - private long register; - - public Outbox(InterpreterShip ship, DockDescription dd) { this(ship, new String[] { "" }, dd); } - public Outbox(InterpreterShip ship, String[] ports, DockDescription dd) { super(ship, ports, dd); } - - protected void setDataLatch(long value) { register = value; } - protected long peekDataLatch() { return register; } - - protected final boolean service(Instruction instruction_) { - /* - if (instruction_ instanceof Instruction.Literal) { - register = ((Instruction.Literal)instruction_).literal; - return true; - } else if (instruction_ instanceof Instruction.HalfLiteral) { - Instruction.HalfLiteral ll = (Instruction.HalfLiteral)instruction_; - register = - ll.high - ? setField(36, 19, ll.literal, register) - : setField(18, 0, ll.literal, register); - return true; - } - */ - Instruction.Move instruction = (Instruction.Move)instruction_; - - // if no instruction waiting, do nothing - if (instruction == null) return false; - - // check firing conditions - if (instruction.tokenIn && triggersReceived <= 0) return false; - if (instruction.dataIn) { - if (!haveDataFromShip) { readyForDataFromShip = true; return false; } - } - - // consume trigger - if (instruction.tokenIn) triggersReceived--; - - // consume item - if (instruction.dataIn) { - haveDataFromShip = false; - if (instruction.latchData) - register = itemPresentedByShip; - } - - if (instruction.dataOut) { - - // if item to be transmitted, send it - InterpreterDestination dest = (InterpreterDestination)(Object)instruction.path; - if (instruction.latchPath) { - // FIXME: still not supported - long bits = FleetTwoFleet.DISPATCH_PATH.getval(register); - getInterpreter().dispatch(((Interpreter)getInterpreter()).readInstruction(register, null), bits); - /* - dest = (InterpreterDestination)(((Interpreter)getInterpreter()).iie.getDestByAddr(bits)); - if (dest == null) { - if (pump != null) { - - Dock pump = ((Interpreter)getInterpreter()).iie.getDestByInstAddr(bits); - } - } - */ - //throw new RuntimeException(); - } else { - new Packet(getInterpreter(), this, register, dest).send(); - } - if (instruction.tokenOut) - throw new RuntimeException("outboxes may not send acks!"); - - } else if (instruction.tokenOut) { - - // if no item was sent, we might still send an ack - new Packet(getInterpreter(), this, 0, (InterpreterDestination)(Object)instruction.path).send(); - } - - return true; - } - - public final boolean readyForDataFromShip() { return readyForDataFromShip; } - public void addDataFromShip(long data) { addItemFromShip(data); } - public void addDataFromFabric(Packet packet) { triggersReceived++; } - - /** subclass invokes this to add an item from the ship */ - protected final void addItemFromShip(long data) { - if (!readyForDataFromShip) - throw new RuntimeException("tried to add an item to an outbox which was not ready! you have a buggy ship!"); - readyForDataFromShip = false; - haveDataFromShip = true; - itemPresentedByShip = data; - } - - void shutdown() { - if (haveDataFromShip) - Log.println(ANSI.red(" WARNING: you left a value ("+itemPresentedByShip+") on outbox port " + this)); - if (triggersReceived > 0) - Log.println(ANSI.red(" WARNING: you left a token on the trigger input to port " + this)); - super.shutdown(false); - } - -} diff --git a/src/edu/berkeley/fleet/interpreter/Packet.java b/src/edu/berkeley/fleet/interpreter/Packet.java index 1a7077d..a4a20a1 100644 --- a/src/edu/berkeley/fleet/interpreter/Packet.java +++ b/src/edu/berkeley/fleet/interpreter/Packet.java @@ -1,28 +1,20 @@ package edu.berkeley.fleet.interpreter; -import java.io.*; -import java.util.*; -import java.util.concurrent.*; -import java.lang.reflect.*; -import edu.berkeley.fleet.*; -import edu.berkeley.sbp.util.ANSI; import edu.berkeley.fleet.api.*; -import edu.berkeley.fleet.two.*; class Packet { - Interpreter interpreter; - long value; - InterpreterDestination destination; + InterpreterPath path; + BitVector value; + boolean isToken; - public Packet(Interpreter interpreter, InstructionDock source, long value, InterpreterDestination destination) { - Log.data(value+"", source, (Destination)destination); - this.interpreter = interpreter; + public Packet(InterpreterPath path, BitVector value, boolean isToken) { this.value = value; - this.destination = destination; + this.path = path; + this.isToken = isToken; } public void send() { - destination.addDataFromFabric(this); + ((InterpreterDestination)path.getDestination()).addDataFromFabric(this); } }