implement am26 support for constants
[fleet.git] / src / edu / berkeley / fleet / fpga / FpgaBenkoBox.java
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;
6 import java.util.*;
7
8 /** anything that has a destination address on the switch fabric */
9 public class FpgaBenkoBox extends BenkoBox {
10         
11     private final String name;
12     private final FpgaShip ship;
13     private  Destination[] ports;
14         
15     public Iterable<Destination> getDestinations() {
16         ArrayList<Destination> ret = new ArrayList<Destination>();
17         for(Destination d : ports) ret.add(d);
18         return ret;
19     }
20     private static int default_addr;
21     private static int default_instr_addr;
22
23     public int bits;
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;
31     void service() { }
32     public boolean special() { return special; }
33     public boolean ihorn() { return ihorn; }
34     public boolean dhorn() { return dhorn; }
35     public boolean inbox;
36     public boolean isInbox() { return inbox; }
37     public boolean isOutbox() { return !inbox; }
38     public long resolveLiteral(String literal) {
39         return bbd.resolveLiteral(literal);
40     }
41     public FpgaBenkoBox(BenkoBoxDescription bbd, boolean inbox, FpgaShip ship, String name) {
42         this(bbd, inbox, ship, name, false, false, false);
43     }
44     public FpgaBenkoBox(BenkoBoxDescription bbd, boolean inbox, FpgaShip ship, String name, boolean special) {
45         this(bbd, inbox, ship, name, special, false, false);
46     }
47     public FpgaBenkoBox(BenkoBoxDescription bbd, boolean inbox, FpgaShip ship, String name, boolean special, boolean ihorn, boolean dhorn) {
48         this.bbd = bbd;
49         this.inbox = inbox;
50         this.special = special;
51         this.dhorn = dhorn;
52         this.ihorn = ihorn;
53         this.ship = ship;
54         this.name = name;
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);
60     }
61
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);
66         ports = newports;
67     }
68
69     public class VirtualPort extends Destination {
70         public String name;
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(); }
76         // fixme
77         public long addr = (default_addr++);
78     }
79         
80     /** adds one token to the port from the switch fabric side */
81     void addTokenFromFabric() { addDataFromFabric(0); }
82         
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);   
87     }
88
89     /** adds one token to the port from the ship side */
90     public void addTokenFromShip() { addDataFromShip(0); }
91         
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!"); }
94
95     public Ship getShip() { return ship; }
96
97     public Fleet getFleet() { return getShip().getFleet(); }
98
99     public String toString() { return ship+"."+name; }
100
101     public String getName() { return name; }
102
103     public int getInstructionFifoLength() { return 4; }
104
105 }