From 9ca8c9d22f76bfce410cd3762a856ef5c0f1963f Mon Sep 17 00:00:00 2001 From: droy Date: Fri, 19 Sep 2003 17:19:58 +0000 Subject: [PATCH] worklist version --- .../MCC/IR/DependencyBuilder.java | 2 + Repair/RepairCompiler/MCC/IR/DotExpr.java | 20 + .../RepairCompiler/MCC/IR/ForQuantifier.java | 13 + .../RepairCompiler/MCC/IR/NaiveGenerator.java | 3 + Repair/RepairCompiler/MCC/IR/Quantifier.java | 4 + .../RepairCompiler/MCC/IR/RelationExpr.java | 3 +- .../MCC/IR/RelationInclusion.java | 25 +- .../MCC/IR/RelationQuantifier.java | 17 + Repair/RepairCompiler/MCC/IR/Rule.java | 7 + .../RepairCompiler/MCC/IR/SetInclusion.java | 19 +- .../RepairCompiler/MCC/IR/SetQuantifier.java | 17 + Repair/RepairCompiler/MCC/IR/WorkList.java | 152 ++++++++ .../MCC/IR/WorklistGenerator.java | 346 ++++++++++++++++++ 13 files changed, 618 insertions(+), 10 deletions(-) create mode 100755 Repair/RepairCompiler/MCC/IR/WorkList.java create mode 100755 Repair/RepairCompiler/MCC/IR/WorklistGenerator.java diff --git a/Repair/RepairCompiler/MCC/IR/DependencyBuilder.java b/Repair/RepairCompiler/MCC/IR/DependencyBuilder.java index 3c26256..babdd0e 100755 --- a/Repair/RepairCompiler/MCC/IR/DependencyBuilder.java +++ b/Repair/RepairCompiler/MCC/IR/DependencyBuilder.java @@ -33,6 +33,8 @@ public class DependencyBuilder { Iterator targets = inclusion.getTargetDescriptors().iterator(); String additionallabel = new String(); + /* #ATTN#: is this meant to be while, not if? */ + /* perhaps there is only one descriptor for targets */ if (targets.hasNext()) { Descriptor d = (Descriptor)targets.next(); additionallabel = "\\n" + d.getSymbol(); diff --git a/Repair/RepairCompiler/MCC/IR/DotExpr.java b/Repair/RepairCompiler/MCC/IR/DotExpr.java index 38a7995..b5d0243 100755 --- a/Repair/RepairCompiler/MCC/IR/DotExpr.java +++ b/Repair/RepairCompiler/MCC/IR/DotExpr.java @@ -8,6 +8,18 @@ public class DotExpr extends Expr { String field; Expr index; + /* + static int memoryindents = 0; + + public static void generate_memory_endblocks(CodeWriter cr) { + while (memoryindents > 0) { + memoryindents --; + cr.endblock(); + } + memoryindents = 0; + } + */ + public DotExpr(Expr left, String field, Expr index) { this.left = left; this.field = field; @@ -176,6 +188,14 @@ public class DotExpr extends Expr { String high = VarDescriptor.makeNew("high").getSafeSymbol(); writer.outputline("int " + high + " = " + low + " + " + sizeof.getSafeSymbol() + ";"); writer.outputline("assertvalidmemory(" + low + ", " + high + ");"); + + // we need to null value check and conditionalize the rest of the rule... we'll use a hack + // here where we store the number of indents in this class... and then provide a static + // method to unwind... + //writer.outputline("// assertvalidmemory "); + //DotExpr.memoryindents++; + //writer.outputline("if (" + dest.getSafeSymbol() + " != NULL)"); + //writer.startblock(); } } diff --git a/Repair/RepairCompiler/MCC/IR/ForQuantifier.java b/Repair/RepairCompiler/MCC/IR/ForQuantifier.java index 1052eaa..e4150d2 100755 --- a/Repair/RepairCompiler/MCC/IR/ForQuantifier.java +++ b/Repair/RepairCompiler/MCC/IR/ForQuantifier.java @@ -37,6 +37,19 @@ public class ForQuantifier extends Quantifier { writer.startblock(); } + public int generate_worklistload(CodeWriter writer, int offset) { + String varname = var.getSafeSymbol(); + writer.outputline("int " + varname + " = wi->word" + offset + ";"); + return offset + 1; + } + + public int generate_workliststore(CodeWriter writer, int offset) { + String varname = var.getSafeSymbol(); + writer.outputline("wi->word" + offset + " = " + varname + ";"); + return offset + 1; + } + + public boolean typecheck(SemanticAnalyzer sa) { TypeDescriptor lt = lower.typecheck(sa); TypeDescriptor ut = upper.typecheck(sa); diff --git a/Repair/RepairCompiler/MCC/IR/NaiveGenerator.java b/Repair/RepairCompiler/MCC/IR/NaiveGenerator.java index bc4e6d4..dd46011 100755 --- a/Repair/RepairCompiler/MCC/IR/NaiveGenerator.java +++ b/Repair/RepairCompiler/MCC/IR/NaiveGenerator.java @@ -151,6 +151,9 @@ public class NaiveGenerator { rule.getInclusion().generate(cr); cr.endblock(); + // close startblocks generated by DotExpr memory checks + //DotExpr.generate_memory_endblocks(cr); + while (quantifiers.hasPrevious()) { Quantifier quantifier = (Quantifier) quantifiers.previous(); cr.endblock(); diff --git a/Repair/RepairCompiler/MCC/IR/Quantifier.java b/Repair/RepairCompiler/MCC/IR/Quantifier.java index 4185cff..3f302b8 100755 --- a/Repair/RepairCompiler/MCC/IR/Quantifier.java +++ b/Repair/RepairCompiler/MCC/IR/Quantifier.java @@ -7,4 +7,8 @@ public abstract class Quantifier { public abstract Set getRequiredDescriptors(); public abstract void generate_open(CodeWriter writer); + + public abstract int generate_worklistload(CodeWriter writer, int offset); + public abstract int generate_workliststore(CodeWriter writer, int offset); + } diff --git a/Repair/RepairCompiler/MCC/IR/RelationExpr.java b/Repair/RepairCompiler/MCC/IR/RelationExpr.java index cc2d5de..9f795e2 100755 --- a/Repair/RepairCompiler/MCC/IR/RelationExpr.java +++ b/Repair/RepairCompiler/MCC/IR/RelationExpr.java @@ -22,10 +22,11 @@ public class RelationExpr extends Expr { public void generate(CodeWriter writer, VarDescriptor dest) { VarDescriptor domain = VarDescriptor.makeNew("domain"); + String strinverse = inverse ? "inv" : ""; String found = (VarDescriptor.makeNew("found")).getSafeSymbol(); expr.generate(writer, domain); writer.outputline(relation.getRange().getType().getGenerateType().getSafeSymbol() + " " + dest.getSafeSymbol() + ";"); - writer.outputline("int " + found + " = " + relation.getSafeSymbol() + "_hash->get(" + domain.getSafeSymbol() + ", " + dest.getSafeSymbol() + ");"); + writer.outputline("int " + found + " = " + relation.getSafeSymbol() + "_hash" + strinverse + "->get(" + domain.getSafeSymbol() + ", " + dest.getSafeSymbol() + ");"); writer.outputline("if (!" + found + ") { maybe = 1; }"); } diff --git a/Repair/RepairCompiler/MCC/IR/RelationInclusion.java b/Repair/RepairCompiler/MCC/IR/RelationInclusion.java index 1b9ed5f..840a43a 100755 --- a/Repair/RepairCompiler/MCC/IR/RelationInclusion.java +++ b/Repair/RepairCompiler/MCC/IR/RelationInclusion.java @@ -9,6 +9,7 @@ public class RelationInclusion extends Inclusion { // #TBD#: this flag needs to be set by some static analysis boolean typesafe = true; + static boolean worklist = true; public RelationInclusion(Expr leftelementexpr, Expr rightelementexpr, RelationDescriptor relation) { this.leftelementexpr = leftelementexpr; @@ -57,21 +58,31 @@ public class RelationInclusion extends Inclusion { check += "1;"; // terminate boolean expression writer.outputline(check); - writer.outputline("if (" + typesafecheck + ") {"); - writer.indent(); + writer.outputline("if (" + typesafecheck + ")"); + writer.startblock(); } - + + String addeditem = (VarDescriptor.makeNew("addeditem")).getSafeSymbol(); + writer.outputline("int " + addeditem + ";"); + if (relation.testUsage(RelationDescriptor.IMAGE)) { - writer.outputline(relation.getSafeSymbol() + "_hash->add((int)" + ld.getSafeSymbol() + ", (int)" + rd.getSafeSymbol() + ");"); + writer.outputline(addeditem + " = " + relation.getSafeSymbol() + "_hash->add((int)" + ld.getSafeSymbol() + ", (int)" + rd.getSafeSymbol() + ");"); } if (relation.testUsage(RelationDescriptor.INVIMAGE)) { - writer.outputline(relation.getSafeSymbol() + "_hashinv->add((int)" + rd.getSafeSymbol() + ", (int)" + ld.getSafeSymbol() + ");"); + writer.outputline(addeditem + " = " + relation.getSafeSymbol() + "_hashinv->add((int)" + rd.getSafeSymbol() + ", (int)" + ld.getSafeSymbol() + ");"); } + if (RelationInclusion.worklist) { + writer.outputline("if (" + addeditem + ")"); + writer.startblock(); { + WorkList.generate_dispatch(writer, relation, rd.getSafeSymbol(), ld.getSafeSymbol()); + } + writer.endblock(); + } + if (!typesafe) { - writer.unindent(); - writer.outputline("}"); + writer.endblock(); } //writer.outputline("printf(\"" + relation.getSafeSymbol() + " (add): <%d, %d>\\n\", " + ld.getSafeSymbol() + ", " + rd.getSafeSymbol() + ");"); diff --git a/Repair/RepairCompiler/MCC/IR/RelationQuantifier.java b/Repair/RepairCompiler/MCC/IR/RelationQuantifier.java index d30e862..7281d2e 100755 --- a/Repair/RepairCompiler/MCC/IR/RelationQuantifier.java +++ b/Repair/RepairCompiler/MCC/IR/RelationQuantifier.java @@ -36,4 +36,21 @@ public class RelationQuantifier extends Quantifier { writer.outputline(x.getType().getSafeSymbol() + " " + x.getSafeSymbol() + " = (" + x.getType().getSafeSymbol() + ") " + x.getSafeSymbol() + "_iterator->key();"); } + public int generate_worklistload(CodeWriter writer, int offset) { + String varx = x.getSafeSymbol(); + String vary = y.getSafeSymbol(); + writer.outputline("int " + varx + " = wi->word" + offset + "; // r1"); + writer.outputline("int " + vary + " = wi->word" + (offset + 1) + "; //r2"); + return offset + 2; + } + + public int generate_workliststore(CodeWriter writer, int offset) { + String varx = x.getSafeSymbol(); + String vary = y.getSafeSymbol(); + writer.outputline("wi->word" + offset + " = " + varx + "; // r1"); + writer.outputline("wi->word" + (offset+1) + " = " + vary + "; // r2"); + return offset + 2; + } + + } diff --git a/Repair/RepairCompiler/MCC/IR/Rule.java b/Repair/RepairCompiler/MCC/IR/Rule.java index 16087e2..a482c08 100755 --- a/Repair/RepairCompiler/MCC/IR/Rule.java +++ b/Repair/RepairCompiler/MCC/IR/Rule.java @@ -14,10 +14,17 @@ public class Rule { SymbolTable st = new SymbolTable(); String label; + + int num; public Rule () { + num = count; label = new String("rule" + count++); } + + public int getNum() { + return num; + } public String getLabel() { return label; diff --git a/Repair/RepairCompiler/MCC/IR/SetInclusion.java b/Repair/RepairCompiler/MCC/IR/SetInclusion.java index deb6ea5..22ceb1d 100755 --- a/Repair/RepairCompiler/MCC/IR/SetInclusion.java +++ b/Repair/RepairCompiler/MCC/IR/SetInclusion.java @@ -7,6 +7,8 @@ public class SetInclusion extends Inclusion { Expr elementexpr; SetDescriptor set; + static boolean worklist = true; + public SetInclusion(Expr elementexpr, SetDescriptor set) { this.elementexpr = elementexpr; this.set = set; @@ -25,8 +27,21 @@ public class SetInclusion extends Inclusion { public void generate(CodeWriter writer) { VarDescriptor vd = VarDescriptor.makeNew("element"); elementexpr.generate(writer, vd); - writer.outputline(set.getSafeSymbol() + "_hash->add((int)" + vd.getSafeSymbol() + ", (int)" + vd.getSafeSymbol() + ");"); - //writer.outputline("printf(\"" + set.getSafeSymbol() + " (add): %d\\n\", " + vd.getSafeSymbol() + ");"); + + String addeditem = (VarDescriptor.makeNew("addeditem")).getSafeSymbol(); + writer.outputline("int " + addeditem + ";"); + + writer.outputline(addeditem + " = " + set.getSafeSymbol() + "_hash->add((int)" + vd.getSafeSymbol() + + ", (int)" + vd.getSafeSymbol() + ");"); + + if (SetInclusion.worklist) { + writer.outputline("if (" + addeditem + ")"); + writer.startblock(); { + WorkList.generate_dispatch(writer, set, vd.getSafeSymbol()); + } + writer.endblock(); + } + } public boolean typecheck(SemanticAnalyzer sa) { diff --git a/Repair/RepairCompiler/MCC/IR/SetQuantifier.java b/Repair/RepairCompiler/MCC/IR/SetQuantifier.java index 7b6ad03..c9ef3df 100755 --- a/Repair/RepairCompiler/MCC/IR/SetQuantifier.java +++ b/Repair/RepairCompiler/MCC/IR/SetQuantifier.java @@ -25,6 +25,10 @@ public class SetQuantifier extends Quantifier { return v; } + public VarDescriptor getVar() { + return var; + } + public SetDescriptor getSet() { return set; } @@ -39,4 +43,17 @@ public class SetQuantifier extends Quantifier { writer.outputline(var.getType().getGenerateType() + " " + var.getSafeSymbol() + " = (" + var.getType().getGenerateType() + ") " + var.getSafeSymbol() + "_iterator->next();"); } + public int generate_worklistload(CodeWriter writer, int offset) { + String varname = var.getSafeSymbol(); + writer.outputline("int " + varname + " = wi->word" + offset + ";"); + return offset + 1; + } + + public int generate_workliststore(CodeWriter writer, int offset) { + String varname = var.getSafeSymbol(); + writer.outputline("wi->word" + offset + " = " + varname + ";"); + return offset + 1; + } + + } diff --git a/Repair/RepairCompiler/MCC/IR/WorkList.java b/Repair/RepairCompiler/MCC/IR/WorkList.java new file mode 100755 index 0000000..023b064 --- /dev/null +++ b/Repair/RepairCompiler/MCC/IR/WorkList.java @@ -0,0 +1,152 @@ +package MCC.IR; + +import MCC.State; +import java.util.*; + +public class WorkList { + + + public static Vector getrulelist(Descriptor d) { + + Vector dispatchrules = new Vector(); + Vector rules = State.currentState.vRules; + + for (int i = 0; i < rules.size(); i++) { + Rule rule = (Rule) rules.elementAt(i); + Set requiredsymbols = rule.getRequiredDescriptors(); + + // #TBD#: in general this is wrong because these descriptors may contain descriptors + // bound in "in?" expressions which need to be dealt with in a topologically sorted + // fashion... + + if (rule.getRequiredDescriptors().contains(d)) { + dispatchrules.addElement(rule); + } + } + + return dispatchrules; + } + + + public static void generate_dispatch(CodeWriter cr, RelationDescriptor rd, String leftvar, String rightvar) { + + cr.outputline("// RELATION DISPATCH "); + + Vector dispatchrules = getrulelist(rd); + + if (dispatchrules.size() == 0) { + cr.outputline("// nothing to dispatch"); + return; + } + + for(int i = 0; i < dispatchrules.size(); i++) { + Rule rule = (Rule) dispatchrules.elementAt(i); + cr.outputline("need to dispatch for " + rule.getLabel()); + } + + assert false; // unsupported + + } + + + public static void generate_dispatch(CodeWriter cr, SetDescriptor sd, String setvar) { + + cr.outputline("// SET DISPATCH "); + + Vector dispatchrules = getrulelist(sd); + + if (dispatchrules.size() == 0) { + cr.outputline("// nothing to dispatch"); + return; + } + + for(int i = 0; i < dispatchrules.size(); i++) { + Rule rule = (Rule) dispatchrules.elementAt(i); + + ListIterator quantifiers = rule.quantifiers(); + Vector otherq = new Vector(); // quantifiers that we need to iterate over to add workitems + + cr.outputline("// " + rule.getLabel()); + cr.startblock(); + + + // #ATTN#: this may/does not handle multiple instances of the same quantifier being bound + // solution is probabyl to iterate over all bindings + + // find quantifier that we have bound + String boundname = null; + int size = 4; // starts at 4 because we have to store the ID + while (quantifiers.hasNext()) { + Quantifier quantifier = (Quantifier) quantifiers.next(); + if (quantifier instanceof SetQuantifier) { + size += 4; + SetQuantifier sq = (SetQuantifier) quantifier; + if (sq.getSet() == sd) { + // we have found our quantifier + boundname = sq.getVar().getSafeSymbol(); + + break; + } + } else if (quantifier instanceof RelationQuantifier) { + size += 8; + } else { // ForQuantifier + size += 4; + } + + otherq.addElement(quantifier); + } + + assert boundname != null; + + // bind bound variable + cr.outputline("int " + boundname + " = " + setvar + ";"); + + // add the rest of the quantifiers and continue to calculate size + while (quantifiers.hasNext()) { + Quantifier quantifier = (Quantifier) quantifiers.next(); + if (quantifier instanceof RelationQuantifier) { + size += 8; + } else { + size += 4; + } + } + + ListIterator otheriterator = otherq.listIterator(); + while (otheriterator.hasNext()) { + Quantifier quantifier = (Quantifier) otheriterator.next(); + quantifier.generate_open(cr); + // implicitly opens bracket + } + + cr.outputline("// dispatching to " + rule.getLabel()); + // #TODO#: add code to do worklist addition + + cr.outputline("WORKITEM *wi = (WORKITEM *) malloc(" + size + ");"); + cr.outputline("wi->id = " + rule.getNum() + ";"); + + // reset quantifiers + quantifiers = rule.quantifiers(); + + // list quantifier so the order's match! + int offset = 0; + while (quantifiers.hasNext()) { + Quantifier quantifier = (Quantifier) quantifiers.next(); + offset = quantifier.generate_workliststore(cr, offset); + } + + // now store in worklist! + cr.outputline("WORKLIST->add((int) wi);"); + + // close all those brackets + while (otheriterator.hasPrevious()) { + otheriterator.previous(); // throw away + cr.endblock(); + } + + // end rule + cr.endblock(); + + } + } + +} diff --git a/Repair/RepairCompiler/MCC/IR/WorklistGenerator.java b/Repair/RepairCompiler/MCC/IR/WorklistGenerator.java new file mode 100755 index 0000000..f33363b --- /dev/null +++ b/Repair/RepairCompiler/MCC/IR/WorklistGenerator.java @@ -0,0 +1,346 @@ +package MCC.IR; + +import java.io.*; +import java.util.*; +import MCC.State; + +public class WorklistGenerator { + + State state; + java.io.PrintWriter output = null; + + public WorklistGenerator(State state) { + this.state = state; + } + + public void generate(java.io.OutputStream output) { + this.output = new java.io.PrintWriter(output, true); + + generate_tokentable(); + generate_hashtables(); + generate_worklist(); + generate_rules(); + generate_implicit_checks(); + generate_checks(); + generate_teardown(); + + } + + private void generate_tokentable() { + + CodeWriter cr = new StandardCodeWriter(output); + Iterator tokens = TokenLiteralExpr.tokens.keySet().iterator(); + + cr.outputline(""); + cr.outputline("// Token values"); + cr.outputline(""); + + while (tokens.hasNext()) { + Object token = tokens.next(); + cr.outputline("// " + token.toString() + " = " + TokenLiteralExpr.tokens.get(token).toString()); + } + + cr.outputline(""); + cr.outputline(""); + } + + private void generate_hashtables() { + + CodeWriter cr = new StandardCodeWriter(output); + cr.outputline("int __Success = 1;\n"); + cr.outputline("// creating hashtables "); + + /* build all the hashtables */ + Hashtable hashtables = new Hashtable(); + + /* build sets */ + Iterator sets = state.stSets.descriptors(); + + /* first pass create all the hash tables */ + while (sets.hasNext()) { + SetDescriptor set = (SetDescriptor) sets.next(); + cr.outputline("SimpleHash* " + set.getSafeSymbol() + "_hash = new SimpleHash();"); + } + + /* second pass build relationships between hashtables */ + sets = state.stSets.descriptors(); + + while (sets.hasNext()) { + SetDescriptor set = (SetDescriptor) sets.next(); + Iterator subsets = set.subsets(); + + while (subsets.hasNext()) { + SetDescriptor subset = (SetDescriptor) subsets.next(); + cr.outputline(subset.getSafeSymbol() + "_hash->addParent(" + set.getSafeSymbol() + "_hash);"); + } + } + + /* build relations */ + Iterator relations = state.stRelations.descriptors(); + + /* first pass create all the hash tables */ + while (relations.hasNext()) { + RelationDescriptor relation = (RelationDescriptor) relations.next(); + + if (relation.testUsage(RelationDescriptor.IMAGE)) { + cr.outputline("SimpleHash* " + relation.getSafeSymbol() + "_hash = new SimpleHash();"); + } + + if (relation.testUsage(RelationDescriptor.INVIMAGE)) { + cr.outputline("SimpleHash* " + relation.getSafeSymbol() + "_hashinv = new SimpleHash();"); + } + } + + cr.outputline(""); + cr.outputline(""); + } + + private void generate_worklist() { + + CodeWriter cr = new StandardCodeWriter(output); + cr.outputline("WORKLIST = new SimpleList();"); + + } + + private void generate_teardown() { + + CodeWriter cr = new StandardCodeWriter(output); + cr.outputline("WORKLIST->reset();"); + cr.outputline("while (WORKLIST->hasMoreElements())"); + cr.startblock(); + cr.outputline("free ((WORKITEM *) WORKLIST->nextElement());"); + cr.endblock(); + cr.outputline("delete WORKLIST;"); + + } + + private void generate_rules() { + + /* first we must sort the rules */ + Iterator allrules = state.vRules.iterator(); + + Vector emptyrules = new Vector(); // rules with no quantifiers + Vector worklistrules = new Vector(); // the rest of the rules + + while (allrules.hasNext()) { + Rule rule = (Rule) allrules.next(); + ListIterator quantifiers = rule.quantifiers(); + + boolean noquantifiers = true; + while (quantifiers.hasNext()) { + Quantifier quantifier = (Quantifier) quantifiers.next(); + if (quantifier instanceof ForQuantifier) { + // ok, because integers exist already! + } else { + // real quantifier + noquantifiers = false; + break; + } + } + + if (noquantifiers) { + emptyrules.add(rule); + } else { + worklistrules.add(rule); + } + } + + Iterator iterator_er = emptyrules.iterator(); + while (iterator_er.hasNext()) { + + Rule rule = (Rule) iterator_er.next(); + + { + final SymbolTable st = rule.getSymbolTable(); + CodeWriter cr = new StandardCodeWriter(output) { + public SymbolTable getSymbolTable() { return st; } + }; + + cr.outputline("// build " + rule.getLabel()); + cr.startblock(); + + ListIterator quantifiers = rule.quantifiers(); + + while (quantifiers.hasNext()) { + Quantifier quantifier = (Quantifier) quantifiers.next(); + quantifier.generate_open(cr); + } + + /* pretty print! */ + cr.output("//"); + rule.getGuardExpr().prettyPrint(cr); + cr.outputline(""); + + /* now we have to generate the guard test */ + + VarDescriptor guardval = VarDescriptor.makeNew(); + rule.getGuardExpr().generate(cr, guardval); + + cr.outputline("if (" + guardval.getSafeSymbol() + ")"); + cr.startblock(); + + /* now we have to generate the inclusion code */ + rule.getInclusion().generate(cr); + cr.endblock(); + + while (quantifiers.hasPrevious()) { + Quantifier quantifier = (Quantifier) quantifiers.previous(); + cr.endblock(); + } + + cr.endblock(); + cr.outputline(""); + cr.outputline(""); + } + } + + CodeWriter cr2 = new StandardCodeWriter(output); + + cr2.outputline("WORKLIST->reset();"); + cr2.outputline("while (WORKLIST->hasMoreElements())"); + cr2.startblock(); + cr2.outputline("WORKITEM *wi = (WORKITEM *) WORKLIST->nextElement();"); + + String elseladder = "if"; + + Iterator iterator_rules = worklistrules.iterator(); + while (iterator_rules.hasNext()) { + + Rule rule = (Rule) iterator_rules.next(); + int dispatchid = rule.getNum(); + + { + final SymbolTable st = rule.getSymbolTable(); + CodeWriter cr = new StandardCodeWriter(output) { + public SymbolTable getSymbolTable() { return st; } + }; + + cr.indent(); + cr.outputline(elseladder + " (wi->id == " + dispatchid + ")"); + cr.startblock(); + + cr.outputline("// build " + rule.getLabel()); + + ListIterator quantifiers = rule.quantifiers(); + + int count = 0; + while (quantifiers.hasNext()) { + Quantifier quantifier = (Quantifier) quantifiers.next(); + count = quantifier.generate_worklistload(cr, count ); + } + + /* pretty print! */ + cr.output("//"); + rule.getGuardExpr().prettyPrint(cr); + cr.outputline(""); + + /* now we have to generate the guard test */ + + VarDescriptor guardval = VarDescriptor.makeNew(); + rule.getGuardExpr().generate(cr, guardval); + + cr.outputline("if (" + guardval.getSafeSymbol() + ")"); + cr.startblock(); + + /* now we have to generate the inclusion code */ + rule.getInclusion().generate(cr); + cr.endblock(); + + // close startblocks generated by DotExpr memory checks + //DotExpr.generate_memory_endblocks(cr); + + cr.endblock(); // end else-if WORKLIST ladder + + elseladder = "else if"; + } + } + + cr2.outputline("else"); + cr2.startblock(); + cr2.outputline("printf(\"VERY BAD !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\\n\\n\");"); + cr2.outputline("exit(1);"); + cr2.endblock(); + + // end block created for worklist + cr2.endblock(); + + } + + private void generate_implicit_checks() { + + /* do post checks */ + + CodeWriter cr = new StandardCodeWriter(output); + + // #TBD#: these should be implicit checks added to the set of constraints + //output.println("check multiplicity"); + } + + private void generate_checks() { + + /* do constraint checks */ + Vector constraints = state.vConstraints; + + for (int i = 0; i < constraints.size(); i++) { + + Constraint constraint = (Constraint) constraints.elementAt(i); + + { + + final SymbolTable st = constraint.getSymbolTable(); + + CodeWriter cr = new StandardCodeWriter(output) { + public SymbolTable getSymbolTable() { return st; } + }; + + cr.outputline("// checking " + constraint.getLabel()); + cr.startblock(); + + ListIterator quantifiers = constraint.quantifiers(); + + while (quantifiers.hasNext()) { + Quantifier quantifier = (Quantifier) quantifiers.next(); + quantifier.generate_open(cr); + } + + cr.outputline("int maybe = 0;"); + + /* now we have to generate the guard test */ + + VarDescriptor constraintboolean = VarDescriptor.makeNew("constraintboolean"); + constraint.getLogicStatement().generate(cr, constraintboolean); + + cr.outputline("if (maybe)"); + cr.startblock(); + cr.outputline("__Success = 0;"); + cr.outputline("printf(\"maybe fail " + (i+1) + ". \");"); + cr.outputline("exit(1);"); + cr.endblock(); + + cr.outputline("else if (!" + constraintboolean.getSafeSymbol() + ")"); + cr.startblock(); + + cr.outputline("__Success = 0;"); + cr.outputline("printf(\"fail " + (i+1) + ". \");"); + cr.outputline("exit(1);"); + cr.endblock(); + + while (quantifiers.hasPrevious()) { + Quantifier quantifier = (Quantifier) quantifiers.previous(); + cr.endblock(); + } + + cr.endblock(); + cr.outputline(""); + cr.outputline(""); + } + + } + + output.println("// if (__Success) { printf(\"all tests passed\"); }"); + } + +} + + + -- 2.34.1