== Ports ===========================================================
in: inEnqueue
- sibling: inEnqueueOp
-
in: inEnqueueOp
constant rev: .......................1.............
constant inv: ........................1............
private final boolean tokenOnly;
private ArrayList<String> destinations = new ArrayList<String>();
+ // FIXME
+ public HashMap<String,Constant> constants = new HashMap<String,Constant>();
+
BenkoBoxDescription(ShipDescription ship, String name, boolean tokenOnly, boolean inbox) {
this(ship, name, tokenOnly, inbox, null);
}
void addDest(String dest) { destinations.add(dest); }
+
+ public Constant getConstant(String name) {
+ Constant ret = constants.get(name);
+ if (ret == null) ret = ship.getConstant(name);
+ return ret;
+ }
}
--- /dev/null
+package edu.berkeley.fleet.doc;
+
+import java.io.*;
+import java.util.*;
+
+public class Constant {
+
+ long setbits = 0;
+ long clearbits = 0;
+ boolean signExtend = false;
+ int numberOffset = 0;
+ int numberWidth = 0;
+
+ public Constant(String s) {
+ if (s.startsWith("0x")) {
+ setbits = Long.parseLong(s.substring(2), 16);
+ clearbits = ~setbits;
+ } else if (s.length() == 37) {
+ for(int i=0; i<37; i++) {
+ char c = s.charAt(36-i);
+ switch(c) {
+ case '0': clearbits |= (1<<i); break;
+ case '1': setbits |= (1<<i); break;
+ case '.': break;
+ case 's': signExtend = true; numberOffset = i; numberWidth++; break;
+ case 'u': signExtend = false; numberOffset = i; numberWidth++; break;
+ }
+ }
+ } else {
+ setbits = Long.parseLong(s);
+ clearbits = ~setbits;
+ }
+ }
+
+ public static long resolveConstant(String exp, BenkoBoxDescription bbd) {
+ long ret = 0;
+ for(StringTokenizer st = new StringTokenizer(exp, ",");
+ st.hasMoreTokens();) {
+ String s = st.nextToken();
+ long val = 0;
+ if (s.indexOf('=') != -1) {
+ val = Long.parseLong(s.substring(s.indexOf('=')+1));
+ s = s.substring(0, s.indexOf('='));
+ }
+ Constant c = bbd.getConstant(s);
+ if (c==null) {
+ if (s.startsWith("0x")) ret |= Long.parseLong(s, 16);
+ else ret |= Long.parseLong(s);
+ } else {
+ ret |= c.setbits;
+ ret &= ~c.clearbits;
+ // FIXME: val
+ }
+ }
+ return ret;
+ }
+
+}
\ No newline at end of file
private HashMap<String,String> sections = new HashMap<String,String>();
+ // FIXME
+ public HashMap<String,Constant> constants = new HashMap<String,Constant>();
+
+ public Constant getConstant(String name) {
+ return constants.get(name);
+ }
+
private void processSection(String section) throws IOException {
if (section.equals("")) {
BufferedReader br = new BufferedReader(new StringReader(sections.get(section)));
if (key.toLowerCase().equals("ship"))
name = val.trim();
}
+ } else if (section.equals("constants")) {
+ BufferedReader br = new BufferedReader(new StringReader(sections.get(section)));
+ for(String s = br.readLine(); s != null; s = br.readLine()) {
+ if (s.indexOf(':')==-1) continue;
+ String key = s.substring(0, s.indexOf(':')).trim();
+ if (key.startsWith("constant")) {
+ String constname = key.substring("constant".length()+1).trim();
+ String val = s.substring(s.indexOf(':')+1).trim();
+ constants.put(constname, new Constant(val));
+ }
+ }
} else if (section.equals("ports")) {
BufferedReader br = new BufferedReader(new StringReader(sections.get(section)));
boolean rightSide = false;
else if (key.equals("in")) { tokenOnly = false; inbox = true; }
else if (key.equals("out")) { tokenOnly = false; inbox = false; }
else if (key.startsWith("constant")) {
- continue;
- } else if (key.startsWith("sibling")) {
- continue;
+ String constname = key.substring("constant".length()+1).trim();
+ String val = s.substring(s.indexOf(':')+1).trim();
+ p.constants.put(constname, new Constant(val));
} else if (key.startsWith("shortcut to")) {
continue;
}
}
void add(BenkoBoxDescription b) { benkoBoxes.add(b); }
-
}
\ No newline at end of file