rename slipway=>fpga
[fleet.git] / src / edu / berkeley / fleet / fpga / SlipwayShip.java
1 package edu.berkeley.fleet.fpga;
2 import edu.berkeley.fleet.doc.*;
3 import edu.berkeley.fleet.api.*;
4 import java.util.*;
5 import java.io.*;
6
7 /** a ship, which belongs to a fleet and which may have many ports */
8 public class SlipwayShip extends Ship {
9         
10     /** You should instantiate a bunch of Inboxes and Outboxes in your constructor */
11     public SlipwayShip(Slipway fleet, String name, String type, ShipDescription sd) {
12         this.fleet = fleet; this.type = type;
13         for(BenkoBoxDescription sdbb : sd) {
14             SlipwayBenkoBox sbb = new SlipwayBenkoBox(sdbb.isInbox(), this, sdbb.getName());
15             for(String port : sdbb) {
16                 if (port.equals("")) continue;
17                 sbb.addDestination(port);
18             }
19         }
20         if        (type.equals("Debug")) {
21             new SlipwayBenkoBox(false, this, "out", true);
22             
23         } else if (type.equals("Execute")) {
24             new SlipwayBenkoBox(false, this, "ihorn", true, true, false);
25             new SlipwayBenkoBox(false, this, "dhorn", true, false, true);
26             
27         } else if (type.equals("Memory")) {
28             new SlipwayBenkoBox(true,  this, "command", true);
29             new SlipwayBenkoBox(false, this, "ihorn",   true, true, false);
30             new SlipwayBenkoBox(false, this, "dhorn",   true, false, true);
31         }
32     }
33
34     private Slipway fleet;
35     private String  type;
36
37     public long resolveLiteral(String s) {
38         if (s.equals("NEG")) return 0;
39         if (s.equals("INC")) return 1;
40         if (s.equals("DEC")) return 2;
41         if (s.equals("ABS")) return 3;
42         if (s.equals("ADD")) return 0;
43         if (s.equals("SUB")) return 1;
44         if (s.equals("MAX")) return 2;
45         if (s.equals("MIN")) return 3;
46         return super.resolveLiteral(s);
47     }
48
49     // this is dumb, the fpga fleet currently requires these in declaration-order; it shouldn't
50     private ArrayList<SlipwayBenkoBox> portlist = new ArrayList<SlipwayBenkoBox>();
51     private HashMap<String,SlipwayBenkoBox> ports = new HashMap<String,SlipwayBenkoBox>();
52
53     public Iterable<BenkoBox> getBenkoBoxes() { return (Iterable<BenkoBox>)(Object)portlist; }
54     public String getType()                   { return type; }
55     public Fleet  getFleet()                  { return fleet; }
56     public Slipway  getSlipway()              { return fleet; }
57
58     void addBenkoBox(String name, SlipwayBenkoBox port) { ports.put(name, port); portlist.add(port); }
59
60 }