1 package edu.berkeley.fleet.doc;
6 /** the Java representation of a .ship file */
7 public class ShipDescription implements Iterable<BenkoBoxDescription> {
9 public String getName() { return name; }
10 public String getSection(String sectionName) { return sections.get(sectionName); }
11 public Iterator<BenkoBoxDescription> iterator() { return benkoBoxes.iterator(); }
13 public ShipDescription(String name, BufferedReader r) throws IOException {
14 if (name.endsWith(".ship"))
15 name = name.substring(0, name.length() - ".ship".length());
16 while(name.indexOf('/') != -1) name = name.substring(name.indexOf('/')+1);
18 String sectionName = null;
19 StringBuffer sb = new StringBuffer();
21 String s = r.readLine();
22 if (s==null || s.startsWith("==")) {
23 if (sectionName != null) sections.put(sectionName, sb.toString());
25 sb = new StringBuffer();
26 sectionName = s.trim();
27 while(sectionName.startsWith("="))
28 sectionName = sectionName.substring(1);
29 while(sectionName.endsWith("="))
30 sectionName = sectionName.substring(0, sectionName.length()-1);
31 sectionName = sectionName.trim().toLowerCase();
36 for(String s : sections.keySet())
40 // private //////////////////////////////////////////////////////////////////////////////
43 private String texDocumentation;
45 // must keep proper ordering for FPGA (FIXME: should alphabetize when synthesizing)
46 private ArrayList<BenkoBoxDescription> benkoBoxes = new ArrayList<BenkoBoxDescription>();
48 private HashMap<String,String> sections = new HashMap<String,String>();
50 private void processSection(String section) throws IOException {
51 if (section.equals("")) {
52 BufferedReader br = new BufferedReader(new StringReader(sections.get(section)));
53 for(String s = br.readLine(); s != null; s = br.readLine()) {
54 if (s.trim().length()==0) continue;
55 String key = s.substring(0, s.indexOf(':')).trim();
56 String val = s.substring(s.indexOf(':')+1).trim();
57 if (key.toLowerCase().equals("ship"))
60 } else if (section.equals("ports")) {
61 BufferedReader br = new BufferedReader(new StringReader(sections.get(section)));
62 boolean rightSide = false;
63 BenkoBoxDescription p = null;
64 for(String s = br.readLine(); s != null; s = br.readLine()) {
65 if (s.trim().length()==0) { rightSide = true; continue; }
67 String key = s.substring(0, s.indexOf(':')).trim();
68 boolean tokenOnly = false;
69 boolean inbox = false;
70 key = key.replaceAll(" +", " ");
71 if (key.equals("token in")) { tokenOnly = true; inbox = true; }
72 else if (key.equals("token out")) { tokenOnly = true; inbox = false; }
73 else if (key.equals("data in")) { tokenOnly = false; inbox = true; }
74 else if (key.equals("data out")) { tokenOnly = false; inbox = false; }
75 else if (key.equals("in")) { tokenOnly = false; inbox = true; }
76 else if (key.equals("out")) { tokenOnly = false; inbox = false; }
77 else if (key.startsWith("constant")) {
79 } else if (key.startsWith("sibling")) {
81 } else if (key.startsWith("shortcut to")) {
84 else throw new RuntimeException("unknown port type: \""+key+"\"");
87 String val = s.substring(s.indexOf(':')+1).trim();
88 String boxname = val.indexOf('.') != -1 ? val.substring(0, val.indexOf('.')) : val;
89 String dest = val.indexOf('.') != -1 ? val.substring(val.indexOf('.')+1) : "";
90 for (BenkoBoxDescription b : benkoBoxes)
91 if (b.getName().equals(boxname)) { p = b; break; }
92 if (p==null) p = new BenkoBoxDescription(this, boxname, tokenOnly, inbox);
98 void add(BenkoBoxDescription b) { benkoBoxes.add(b); }