total overhaul: fleetcode-1.0 api finished
[fleet.git] / src / edu / berkeley / fleet / interpreter / InterpreterDock.java
1 package edu.berkeley.fleet.interpreter;
2 import edu.berkeley.fleet.api.*;
3 import edu.berkeley.fleet.api.Dock;
4 import edu.berkeley.fleet.two.*;
5 import java.util.*;
6
7
8 /** anything that has a destination address on the switch fabric */
9 public abstract class InterpreterDock extends FleetTwoDock {
10         
11     private final InterpreterShip ship;
12     private final Destination[] ports;
13     private final int addr = max_addr++;
14     
15     public InterpreterDock(InterpreterShip ship, String[] ports, DockDescription bbd) {
16         super(ship, bbd);
17         this.ship = ship;
18         this.ports = new Destination[ports.length];
19         for(int i=0; i<ports.length; i++)
20             this.ports[i] =
21                 new InterpreterDockDestination(ports[i], this, false);
22     }
23
24     public Path getPath(Destination d, BitVector signal) {
25         throw new RuntimeException();
26     }
27
28     public Iterable<Destination> getDestinations() {
29         HashSet<Destination> ret = new HashSet<Destination>();
30         for(Destination d : ports) ret.add(d);
31         return ret;
32     }
33
34     public Destination getInstructionDestination() {
35         return ports[0];
36     }
37     public Destination getDataDestination() {
38         return ports[0];
39     }
40
41
42     /** adds the included datum to the port from the switch fabric  side */
43     public abstract void addDataFromFabric(Packet packet);
44
45     abstract void service();
46
47     abstract void   shutdown();
48
49     public   Ship   getShip()                  { return ship; }
50     public   Fleet  getFleet()                 { return getShip().getFleet(); }
51     public   String toString()                 { return ship+"."+getName(); }
52     public   int    getInstructionFifoSize() { return 4; }
53     
54     Interpreter getInterpreter() { return ((InterpreterShip)getShip()).getInterpreter(); }
55
56     public long getDestAddr() { return addr; }
57
58     private static int max_addr;
59     private class InterpreterDockDestination extends InterpreterDestination {
60         public String name;
61         public long addr = max_addr++;
62         public InterpreterDockDestination(String name, InterpreterDock id, boolean isInstructionDestination) {
63             super(id, isInstructionDestination);
64             this.name = name;
65         }
66         public String getDestinationName()               { return name; }
67         public Ship getShip()                    { return InterpreterDock.this.getShip(); }
68         public void addDataFromFabric(Packet packet) { InterpreterDock.this.addDataFromFabric(packet); }
69         public String toString()                 { return getShip()+"."+getName(); }
70         public long getDestAddr() { return addr; }
71     }
72 }