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(BufferedReader r) throws IOException {
14 String sectionName = "";
15 StringBuffer sb = new StringBuffer();
17 String s = r.readLine();
19 if (s.startsWith("==")) {
20 sections.put(sectionName, sb.toString());
21 sb = new StringBuffer();
22 sectionName = s.trim();
23 while(sectionName.startsWith("="))
24 sectionName = sectionName.substring(1);
25 while(sectionName.endsWith("="))
26 sectionName = sectionName.substring(0, sectionName.length()-1);
27 sectionName = sectionName.trim().toLowerCase();
32 for(String s : sections.keySet())
36 // private //////////////////////////////////////////////////////////////////////////////
39 private String texDocumentation;
41 // must keep proper ordering for FPGA (FIXME: should alphabetize when synthesizing)
42 private ArrayList<BenkoBoxDescription> benkoBoxes = new ArrayList<BenkoBoxDescription>();
44 private HashMap<String,String> sections = new HashMap<String,String>();
46 private void processSection(String section) throws IOException {
47 if (section.equals("")) {
48 BufferedReader br = new BufferedReader(new StringReader(sections.get(section)));
49 for(String s = br.readLine(); s != null; s = br.readLine()) {
50 if (s.trim().length()==0) continue;
51 String key = s.substring(0, s.indexOf(':')).trim();
52 String val = s.substring(s.indexOf(':')+1).trim();
53 if (key.toLowerCase().equals("ship"))
56 } else if (section.equals("ports")) {
57 BufferedReader br = new BufferedReader(new StringReader(sections.get(section)));
58 boolean rightSide = false;
59 BenkoBoxDescription p = null;
60 for(String s = br.readLine(); s != null; s = br.readLine()) {
61 if (s.trim().length()==0) { rightSide = true; continue; }
63 String key = s.substring(0, s.indexOf(':')).trim();
64 boolean tokenOnly = false;
65 boolean inbox = false;
66 key = key.replaceAll(" +", " ");
67 if (key.equals("token in")) { tokenOnly = true; inbox = true; }
68 else if (key.equals("token out")) { tokenOnly = true; inbox = false; }
69 else if (key.equals("data in")) { tokenOnly = false; inbox = true; }
70 else if (key.equals("data out")) { tokenOnly = false; inbox = false; }
71 else if (key.equals("in")) { tokenOnly = false; inbox = true; }
72 else if (key.equals("out")) { tokenOnly = false; inbox = false; }
73 else if (key.startsWith("constant")) {
75 } else if (key.startsWith("shortcut to")) {
78 else throw new RuntimeException("unknown port type: \""+key+"\"");
81 String val = s.substring(s.indexOf(':')+1).trim();
82 String boxname = val.indexOf('.') != -1 ? val.substring(0, val.indexOf('.')) : val;
83 String dest = val.indexOf('.') != -1 ? val.substring(val.indexOf('.')+1) : "";
84 for (BenkoBoxDescription b : benkoBoxes)
85 if (b.getName().equals(boxname)) { p = b; break; }
86 if (p==null) p = new BenkoBoxDescription(this, boxname, tokenOnly, inbox);
92 void add(BenkoBoxDescription b) { benkoBoxes.add(b); }