6 public class WorkList {
9 public static Vector getrulelist(Descriptor d) {
11 Vector dispatchrules = new Vector();
12 Vector rules = State.currentState.vRules;
14 for (int i = 0; i < rules.size(); i++) {
15 Rule rule = (Rule) rules.elementAt(i);
16 Set requiredsymbols = rule.getRequiredDescriptors();
18 // #TBD#: in general this is wrong because these descriptors may contain descriptors
19 // bound in "in?" expressions which need to be dealt with in a topologically sorted
22 if (rule.getRequiredDescriptors().contains(d)) {
23 dispatchrules.addElement(rule);
31 public static void generate_dispatch(CodeWriter cr, RelationDescriptor rd, String leftvar, String rightvar) {
33 cr.outputline("// RELATION DISPATCH ");
35 Vector dispatchrules = getrulelist(rd);
37 if (dispatchrules.size() == 0) {
38 cr.outputline("// nothing to dispatch");
42 for(int i = 0; i < dispatchrules.size(); i++) {
43 Rule rule = (Rule) dispatchrules.elementAt(i);
44 cr.outputline("need to dispatch for " + rule.getLabel());
47 assert false; // unsupported
52 public static void generate_dispatch(CodeWriter cr, SetDescriptor sd, String setvar) {
54 cr.outputline("// SET DISPATCH ");
56 Vector dispatchrules = getrulelist(sd);
58 if (dispatchrules.size() == 0) {
59 cr.outputline("// nothing to dispatch");
63 for(int i = 0; i < dispatchrules.size(); i++) {
64 Rule rule = (Rule) dispatchrules.elementAt(i);
66 ListIterator quantifiers = rule.quantifiers();
67 Vector otherq = new Vector(); // quantifiers that we need to iterate over to add workitems
69 cr.outputline("// " + rule.getLabel());
73 // #ATTN#: this may/does not handle multiple instances of the same quantifier being bound
74 // solution is probabyl to iterate over all bindings
76 // find quantifier that we have bound
77 String boundname = null;
78 int size = 4; // starts at 4 because we have to store the ID
79 while (quantifiers.hasNext()) {
80 Quantifier quantifier = (Quantifier) quantifiers.next();
81 if (quantifier instanceof SetQuantifier) {
83 SetQuantifier sq = (SetQuantifier) quantifier;
84 if (sq.getSet() == sd) {
85 // we have found our quantifier
86 boundname = sq.getVar().getSafeSymbol();
90 } else if (quantifier instanceof RelationQuantifier) {
92 } else { // ForQuantifier
96 otherq.addElement(quantifier);
99 assert boundname != null;
101 // bind bound variable
102 cr.outputline("int " + boundname + " = " + setvar + ";");
104 // add the rest of the quantifiers and continue to calculate size
105 while (quantifiers.hasNext()) {
106 Quantifier quantifier = (Quantifier) quantifiers.next();
107 if (quantifier instanceof RelationQuantifier) {
114 ListIterator otheriterator = otherq.listIterator();
115 while (otheriterator.hasNext()) {
116 Quantifier quantifier = (Quantifier) otheriterator.next();
117 quantifier.generate_open(cr);
118 // implicitly opens bracket
121 cr.outputline("// dispatching to " + rule.getLabel());
122 // #TODO#: add code to do worklist addition
124 cr.outputline("WORKITEM *wi = (WORKITEM *) malloc(" + size + ");");
125 cr.outputline("wi->id = " + rule.getNum() + ";");
128 quantifiers = rule.quantifiers();
130 // list quantifier so the order's match!
132 while (quantifiers.hasNext()) {
133 Quantifier quantifier = (Quantifier) quantifiers.next();
134 offset = quantifier.generate_workliststore(cr, offset);
137 // now store in worklist!
138 cr.outputline("WORKLIST->add((int) wi);");
140 // close all those brackets
141 while (otheriterator.hasPrevious()) {
142 otheriterator.previous(); // throw away