cbcf96878b8a91c5840e1e5115b9a7ebe94aaba0
[fleet.git] / src / edu / berkeley / fleet / slipway / SlipwayShip.java
1 package edu.berkeley.fleet.slipway;
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             new SlipwayBenkoBox(sdbb.isInbox(), this, sdbb.getName());
15         if        (type.equals("Debug")) {
16             new SlipwayBenkoBox(false, this, "out", true);
17             
18         } else if (type.equals("Execute")) {
19             new SlipwayBenkoBox(false, this, "ihorn", true, true, false);
20             new SlipwayBenkoBox(false, this, "dhorn", true, false, true);
21             
22         } else if (type.equals("Iscratch")) {
23             new SlipwayBenkoBox(true,  this,  "command", true);
24             new SlipwayBenkoBox(false, this, "ihorn",   true, true, false);
25             new SlipwayBenkoBox(false, this, "dhorn",   true, false, true);
26         }
27     }
28
29     private Slipway fleet;
30     private String  type;
31
32     public long resolveLiteral(String s) {
33         if (s.equals("NEG")) return 0;
34         if (s.equals("INC")) return 1;
35         if (s.equals("DEC")) return 2;
36         if (s.equals("ABS")) return 3;
37         if (s.equals("ADD")) return 0;
38         if (s.equals("SUB")) return 1;
39         if (s.equals("MAX")) return 2;
40         if (s.equals("MIN")) return 3;
41         return super.resolveLiteral(s);
42     }
43
44     // this is dumb, the fpga fleet currently requires these in declaration-order; it shouldn't
45     private ArrayList<SlipwayBenkoBox> portlist = new ArrayList<SlipwayBenkoBox>();
46     private HashMap<String,SlipwayBenkoBox> ports = new HashMap<String,SlipwayBenkoBox>();
47
48     public Iterable<BenkoBox> getBenkoBoxes() { return (Iterable<BenkoBox>)(Object)portlist; }
49     public String getType()                   { return type; }
50     public Fleet  getFleet()                  { return fleet; }
51     public Slipway  getSlipway()              { return fleet; }
52
53     void addBenkoBox(String name, SlipwayBenkoBox port) { ports.put(name, port); portlist.add(port); }
54
55 }