42a65cdbfa4a49fb0c8c3026f3d18f5346375889
[fleet.git] / src / edu / berkeley / fleet / interpreter / InterpreterPump.java
1 package edu.berkeley.fleet.interpreter;
2 import edu.berkeley.fleet.doc.*;
3 import edu.berkeley.fleet.api.*;
4 import edu.berkeley.fleet.api.Pump;
5 import java.util.*;
6
7 /** anything that has a destination address on the switch fabric */
8 public abstract class InterpreterPump extends Pump {
9         
10     private final String name;
11     private final InterpreterShip ship;
12     private final Destination[] ports;
13     private final int addr = max_addr++;
14     private  PumpDescription bbd;
15
16     public void setDescription(PumpDescription bbd) {
17         this.bbd = bbd;
18     }
19     public long resolveLiteral(String literal) {
20         return bbd.resolveLiteral(literal);
21     }
22     
23     public InterpreterPump(InterpreterShip ship, String name, String[] ports) {
24         this.ship = ship;
25         this.name = name;
26         this.ports = new Destination[ports.length];
27         for(int i=0; i<ports.length; i++)
28             this.ports[i] =
29                 new InterpreterPumpDestination(ports[i]);
30     }
31
32     public Iterable<Destination> getDestinations() {
33         HashSet<Destination> ret = new HashSet<Destination>();
34         for(Destination d : ports) ret.add(d);
35         return ret;
36     }
37
38     /** adds the included datum to the port from the switch fabric  side */
39     public abstract void addDataFromFabric(Packet packet);
40
41     abstract void service();
42
43     abstract void   shutdown();
44
45     public   Ship   getShip()                  { return ship; }
46     public   Fleet  getFleet()                 { return getShip().getFleet(); }
47     public   String toString()                 { return ship+"."+name; }
48     public   String getName()                  { return name; }
49     public   int    getInstructionFifoLength() { return 4; }
50     
51     Interpreter getInterpreter() { return ((InterpreterShip)getShip()).getInterpreter(); }
52
53     public long getDestAddr() { return addr; }
54
55     private static int max_addr;
56
57     private class InterpreterPumpDestination extends InterpreterDestination {
58         public String name;
59         public long addr = max_addr++;
60         public InterpreterPumpDestination(String name)          { this.name = name; }
61         public String getDestinationName()               { return name; }
62         public Ship getShip()                    { return InterpreterPump.this.getShip(); }
63         public void addDataFromFabric(Packet packet) { InterpreterPump.this.addDataFromFabric(packet); }
64         public String toString()                 { return getShip()+"."+getName(); }
65         public long getDestAddr() { return addr; }
66     }
67 }