1 package edu.berkeley.fleet.fpga;
2 import edu.berkeley.fleet.doc.*;
3 import edu.berkeley.fleet.api.*;
4 import edu.berkeley.fleet.api.*;
5 import edu.berkeley.fleet.api.BenkoBox;
8 /** anything that has a destination address on the switch fabric */
9 public class FpgaBenkoBox extends BenkoBox {
11 private final String name;
12 private final FpgaShip ship;
13 private Destination[] ports;
15 public Iterable<Destination> getDestinations() {
16 ArrayList<Destination> ret = new ArrayList<Destination>();
17 for(Destination d : ports) ret.add(d);
20 private static int default_addr;
21 private static int default_instr_addr;
24 public int addr = (default_addr++);
25 public int instr_bits;
26 public int instr_addr = (default_instr_addr++);
27 private final BenkoBoxDescription bbd;
28 protected boolean special = false;
29 protected boolean ihorn = false;
30 protected boolean dhorn = false;
32 public boolean special() { return special; }
33 public boolean ihorn() { return ihorn; }
34 public boolean dhorn() { return dhorn; }
36 public boolean isInbox() { return inbox; }
37 public boolean isOutbox() { return !inbox; }
38 public long resolveLiteral(String literal) {
39 return bbd.resolveLiteral(literal);
41 public FpgaBenkoBox(BenkoBoxDescription bbd, boolean inbox, FpgaShip ship, String name) {
42 this(bbd, inbox, ship, name, false, false, false);
44 public FpgaBenkoBox(BenkoBoxDescription bbd, boolean inbox, FpgaShip ship, String name, boolean special) {
45 this(bbd, inbox, ship, name, special, false, false);
47 public FpgaBenkoBox(BenkoBoxDescription bbd, boolean inbox, FpgaShip ship, String name, boolean special, boolean ihorn, boolean dhorn) {
50 this.special = special;
55 String[] ports = new String[] { "" };
56 this.ports = new Destination[ports.length];
57 for(int i=0; i<ports.length; i++)
58 this.ports[i] = new VirtualPort(ports[i]);
59 ship.addBenkoBox(name, this);
62 public void addDestination(String dest) {
63 Destination[] newports = new Destination[ports.length+1];
64 System.arraycopy(ports, 0, newports, 0, ports.length);
65 newports[newports.length-1] = new VirtualPort(dest);
69 public class VirtualPort extends Destination {
71 public VirtualPort(String name) { this.name = name; }
72 public String getDestinationName() { return name; }
73 public Ship getShip() { return FpgaBenkoBox.this.getShip(); }
74 public void addDataFromFabric(long data) { FpgaBenkoBox.this.addDataFromFabric(name, (int)data); }
75 public String toString() { return getShip()+"."+getName(); }
77 public long addr = (default_addr++);
80 /** adds one token to the port from the switch fabric side */
81 void addTokenFromFabric() { addDataFromFabric(0); }
83 /** adds the included datum to the port from the switch fabric side */
84 void addDataFromFabric(int datum) { throw new RuntimeException("this should never happen!"); }
85 void addDataFromFabric(String name, int datum) {
86 addDataFromFabric(datum);
89 /** adds one token to the port from the ship side */
90 public void addTokenFromShip() { addDataFromShip(0); }
92 /** adds the included datum to the port from the switch fabric side */
93 public void addDataFromShip(int datum) { throw new RuntimeException("this should never happen!"); }
95 public Ship getShip() { return ship; }
97 public Fleet getFleet() { return getShip().getFleet(); }
99 public String toString() { return ship+"."+name; }
101 public String getName() { return name; }
103 public int getInstructionFifoLength() { return 4; }