generate_call();
generate_start();
generate_rules();
+ generate_print();
generate_checks();
generate_teardown();
CodeWriter crhead = new StandardCodeWriter(this.outputhead);
cr.endblock();
}
+ private void generate_print() {
+
+ final SymbolTable st = new SymbolTable();
+
+ CodeWriter cr = new StandardCodeWriter(outputaux) {
+ public SymbolTable getSymbolTable() { return st; }
+ };
+
+ cr.outputline("// printing sets!");
+ cr.outputline("printf(\"\\n\\nPRINTING SETS AND RELATIONS\\n\");");
+
+ Iterator setiterator = state.stSets.descriptors();
+ while (setiterator.hasNext()) {
+ SetDescriptor sd = (SetDescriptor) setiterator.next();
+ if (sd.getSymbol().equals("int") || sd.getSymbol().equals("token")) {
+ continue;
+ }
+
+ String setname = sd.getSafeSymbol();
+
+ cr.startblock();
+ cr.outputline("// printing set " + setname);
+ cr.outputline("printf(\"\\nPrinting set " + sd.getSymbol() + " - %d elements \\n\", " + setname + "_hash->count());");
+ cr.outputline("SimpleIterator __setiterator;");
+ cr.outputline("" + setname + "_hash->iterator(__setiterator);");
+ cr.outputline("while (__setiterator.hasNext())");
+ cr.startblock();
+ cr.outputline("int __setval = (int) __setiterator.next();");
+
+ TypeDescriptor td = sd.getType();
+ if (td instanceof StructureTypeDescriptor) {
+ StructureTypeDescriptor std = (StructureTypeDescriptor) td;
+ VarDescriptor vd = new VarDescriptor ("__setval", "__setval", td, false);
+ std.generate_printout(cr, vd);
+ } else { // Missing type descriptor or reserved type, just print int
+ cr.outputline("printf(\"<%d> \", __setval);");
+ }
+
+
+ cr.endblock();
+ cr.endblock();
+ }
+
+ cr.outputline("printf(\"\\n\\n------------------- END PRINTING\\n\");");
+ }
+
Set ruleset=null;
private void generate_rules() {
/* first we must sort the rules */
private void generate_checks() {
/* do constraint checks */
- Vector constraints = state.vConstraints;
+ // Vector constraints = state.vConstraints;
- for (int i = 0; i < constraints.size(); i++) {
- Constraint constraint = (Constraint) constraints.elementAt(i);
+
+ // for (int i = 0; i < constraints.size(); i++) {
+ // Constraint constraint = (Constraint) constraints.elementAt(i);
+ for (Iterator i = termination.constraintdependence.computeOrdering().iterator(); i.hasNext();) {
+ Constraint constraint = (Constraint) ((GraphNode)i.next()).getOwner();
{
final SymbolTable st = constraint.getSymbolTable();
- CodeWriter cr = new StandardCodeWriter(outputaux) {
- public SymbolTable getSymbolTable() { return st; }
- };
+ CodeWriter cr = new StandardCodeWriter(outputaux);
+ cr.pushSymbolTable(constraint.getSymbolTable());
+
cr.outputline("// checking " + escape(constraint.toString()));
cr.startblock();
ListIterator quantifiers = constraint.quantifiers();
while (quantifiers.hasNext()) {
- Quantifier quantifier = (Quantifier) quantifiers.next();
+ Quantifier quantifier = (Quantifier) quantifiers.next();
quantifier.generate_open(cr);
- }
+ }
cr.outputline("int maybe = 0;");
/* Equal */
} else if (opcode==Opcode.EQ) {
/* Equal */
- } else if (opcode==Opcode.NE) {
+ } else if (opcode==Opcode.NE) { /* search for FLAGNE if this is changed*/
cr.outputline(newvalue.getSafeSymbol()+"++;");
} else {
throw new Error("Unrecognized Opcode");
Rule r=(Rule)state.vRules.get(i);
if (r.getInclusion().getTargetDescriptors().contains(rd)) {
for(int j=0;j<munmodify.numUpdates();j++) {
- UpdateNode un=munmodify.getUpdate(i);
+ UpdateNode un=munmodify.getUpdate(j);
if (un.getRule()==r) {
/* Update for rule r */
String name=(String)updatenames.get(un);
ExprPredicate ep=(ExprPredicate)dpred.getPredicate();
OpExpr expr=(OpExpr)ep.expr;
Opcode opcode=expr.getOpcode();
- {
- boolean negated=dpred.isNegated();
- if (negated)
- if (opcode==Opcode.GT) {
- opcode=Opcode.LE;
- } else if (opcode==Opcode.GE) {
- opcode=Opcode.LT;
- } else if (opcode==Opcode.LT) {
- opcode=Opcode.GE;
- } else if (opcode==Opcode.LE) {
- opcode=Opcode.GT;
- } else if (opcode==Opcode.EQ) {
- opcode=Opcode.NE;
- } else if (opcode==Opcode.NE) {
- opcode=Opcode.EQ;
- } else {
- throw new Error("Unrecognized Opcode");
- }
- }
+ opcode=Opcode.translateOpcode(dpred.isNegated(),opcode);
+
MultUpdateNode munremove;
MultUpdateNode munadd;
munremove=getmultupdatenode(conj,dpred,AbstractRepair.REMOVEFROMSET);
munadd=getmultupdatenode(conj,dpred,AbstractRepair.ADDTOSET);
}
- int size=ep.leftsize();
+ int size=ep.rightSize();
VarDescriptor sizevar=VarDescriptor.makeNew("size");
((OpExpr)expr).left.generate(cr, sizevar);
VarDescriptor change=VarDescriptor.makeNew("change");
} else {
throw new Error("Unrecognized Opcode");
}
+
+// In some cases the analysis has determined that generating removes
+// is unnecessary
+ if (generateremove&&munremove==null)
+ generateremove=false;
+
Descriptor d=ep.getDescriptor();
if (generateremove) {
cr.outputline("for(;"+change.getSafeSymbol()+"<0;"+change.getSafeSymbol()+"++)");
}
private boolean need_compensation(Rule r) {
+ if (!Compiler.REPAIR)
+ return false;
GraphNode gn=(GraphNode)termination.scopefalsify.get(r);
for(Iterator edgeit=gn.edges();edgeit.hasNext();) {
GraphNode.Edge edge=(GraphNode.Edge)edgeit.next();
return;
cr.outputline("// RELATION DISPATCH ");
- cr.outputline("if ("+oldmodel.getSafeSymbol()+"&&");
- if (usageimage)
- cr.outputline("!"+oldmodel.getSafeSymbol() +"->"+rd.getJustSafeSymbol()+"_hash->contains("+leftvar+","+rightvar+"))");
- else
- cr.outputline("!"+oldmodel.getSafeSymbol() +"->"+rd.getJustSafeSymbol()+"_hashinv->contains("+rightvar+","+leftvar+"))");
- cr.startblock(); {
- /* Adding new item */
- /* Perform safety checks */
- cr.outputline("if ("+repairtable.getSafeSymbol()+"&&");
- cr.outputline(repairtable.getSafeSymbol()+"->containsrelation("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+"))");
+ if (Compiler.REPAIR) {
+ cr.outputline("if ("+oldmodel.getSafeSymbol()+"&&");
+ if (usageimage)
+ cr.outputline("!"+oldmodel.getSafeSymbol() +"->"+rd.getJustSafeSymbol()+"_hash->contains("+leftvar+","+rightvar+"))");
+ else
+ cr.outputline("!"+oldmodel.getSafeSymbol() +"->"+rd.getJustSafeSymbol()+"_hashinv->contains("+rightvar+","+leftvar+"))");
+
cr.startblock(); {
- /* Have update to call into */
- VarDescriptor mdfyptr=VarDescriptor.makeNew("modifyptr");
- cr.outputline("int "+mdfyptr.getSafeSymbol()+"="+repairtable.getSafeSymbol()+"->getrelation2("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
-
- String parttype="";
- for(int i=0;i<currentrule.numQuantifiers();i++) {
- if (currentrule.getQuantifier(i) instanceof RelationQuantifier)
- parttype=parttype+", int, int";
- else
- parttype=parttype+", int";
- }
- VarDescriptor funptr=VarDescriptor.makeNew("updateptr");
- VarDescriptor tmpptr=VarDescriptor.makeNew("tempupdateptr");
-
- String methodcall="("+funptr.getSafeSymbol()+") (this,"+oldmodel.getSafeSymbol()+","+repairtable.getSafeSymbol();
- for(int i=0;i<currentrule.numQuantifiers();i++) {
- Quantifier q=currentrule.getQuantifier(i);
- if (q instanceof SetQuantifier) {
- SetQuantifier sq=(SetQuantifier) q;
- methodcall+=","+sq.getVar().getSafeSymbol();
- } else if (q instanceof RelationQuantifier) {
- RelationQuantifier rq=(RelationQuantifier) q;
- methodcall+=","+rq.x.getSafeSymbol();
- methodcall+=","+rq.y.getSafeSymbol();
- } else if (q instanceof ForQuantifier) {
- ForQuantifier fq=(ForQuantifier) q;
- methodcall+=","+fq.getVar().getSafeSymbol();
+ /* Adding new item */
+ /* Perform safety checks */
+ cr.outputline("if ("+repairtable.getSafeSymbol()+"&&");
+ cr.outputline(repairtable.getSafeSymbol()+"->containsrelation("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+"))");
+ cr.startblock(); {
+ /* Have update to call into */
+ VarDescriptor mdfyptr=VarDescriptor.makeNew("modifyptr");
+ cr.outputline("int "+mdfyptr.getSafeSymbol()+"="+repairtable.getSafeSymbol()+"->getrelation2("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
+
+ String parttype="";
+ for(int i=0;i<currentrule.numQuantifiers();i++) {
+ if (currentrule.getQuantifier(i) instanceof RelationQuantifier)
+ parttype=parttype+", int, int";
+ else
+ parttype=parttype+", int";
}
- }
-
-
+ VarDescriptor funptr=VarDescriptor.makeNew("updateptr");
+ VarDescriptor tmpptr=VarDescriptor.makeNew("tempupdateptr");
+
+ String methodcall="("+funptr.getSafeSymbol()+") (this,"+oldmodel.getSafeSymbol()+","+repairtable.getSafeSymbol();
+ for(int i=0;i<currentrule.numQuantifiers();i++) {
+ Quantifier q=currentrule.getQuantifier(i);
+ if (q instanceof SetQuantifier) {
+ SetQuantifier sq=(SetQuantifier) q;
+ methodcall+=","+sq.getVar().getSafeSymbol();
+ } else if (q instanceof RelationQuantifier) {
+ RelationQuantifier rq=(RelationQuantifier) q;
+ methodcall+=","+rq.x.getSafeSymbol();
+ methodcall+=","+rq.y.getSafeSymbol();
+ } else if (q instanceof ForQuantifier) {
+ ForQuantifier fq=(ForQuantifier) q;
+ methodcall+=","+fq.getVar().getSafeSymbol();
+ }
+ }
+
+
- cr.outputline("void *"+tmpptr.getSafeSymbol()+"=");
- cr.outputline("(void *) "+repairtable.getSafeSymbol()+"->getrelation("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
- cr.outputline("if ("+mdfyptr.getSafeSymbol()+")");
- {
- cr.startblock();
- cr.outputline("void (*"+funptr.getSafeSymbol()+") ("+name+"_state *,"+name+"*,RepairHash *"+parttype+"int,int,int)="+"(void (*) ("+name+"_state *,"+name+"*,RepairHash *"+parttype+"int,int,int)) "+tmpptr.getSafeSymbol());
- cr.outputline(methodcall+leftvar+", "+rightvar+", "+mdfyptr.getSafeSymbol() +");");
- cr.endblock();
- }
- cr.outputline("else ");
- {
- cr.startblock();
- cr.outputline("void (*"+funptr.getSafeSymbol()+") ("+name+"_state *,"+name+"*,RepairHash *"+parttype+")="+"(void (*) ("+name+"_state *,"+name+"*,RepairHash *"+parttype+")) "+tmpptr.getSafeSymbol());
- cr.outputline(methodcall+");");
- cr.endblock();
+ cr.outputline("void *"+tmpptr.getSafeSymbol()+"=");
+ cr.outputline("(void *) "+repairtable.getSafeSymbol()+"->getrelation("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
+ cr.outputline("if ("+mdfyptr.getSafeSymbol()+")");
+ {
+ cr.startblock();
+ cr.outputline("void (*"+funptr.getSafeSymbol()+") ("+name+"_state *,"+name+"*,RepairHash *"+parttype+",int,int,int)="+"(void (*) ("+name+"_state *,"+name+"*,RepairHash *"+parttype+",int,int,int)) "+tmpptr.getSafeSymbol());
+ cr.outputline(methodcall+leftvar+", "+rightvar+", "+mdfyptr.getSafeSymbol() +");");
+ cr.endblock();
+ }
+ cr.outputline("else ");
+ {
+ cr.startblock();
+ cr.outputline("void (*"+funptr.getSafeSymbol()+") ("+name+"_state *,"+name+"*,RepairHash *"+parttype+")="+"(void (*) ("+name+"_state *,"+name+"*,RepairHash *"+parttype+")) "+tmpptr.getSafeSymbol());
+ cr.outputline(methodcall+");");
+ cr.endblock();
+ }
+ cr.outputline("goto rebuild;");
}
- cr.outputline("goto rebuild;");
- }
- cr.endblock();
- /* Build standard compensation actions */
- if (need_compensation(currentrule)) {
- UpdateNode un=find_compensation(currentrule);
- String name=(String)updatenames.get(un);
- usedupdates.add(un); /* Mark as used */
- String methodcall=name+"(this,"+oldmodel.getSafeSymbol()+","+repairtable.getSafeSymbol();
- for(int i=0;i<currentrule.numQuantifiers();i++) {
- Quantifier q=currentrule.getQuantifier(i);
- if (q instanceof SetQuantifier) {
- SetQuantifier sq=(SetQuantifier) q;
- methodcall+=","+sq.getVar().getSafeSymbol();
- } else if (q instanceof RelationQuantifier) {
- RelationQuantifier rq=(RelationQuantifier) q;
- methodcall+=","+rq.x.getSafeSymbol();
- methodcall+=","+rq.y.getSafeSymbol();
- } else if (q instanceof ForQuantifier) {
- ForQuantifier fq=(ForQuantifier) q;
- methodcall+=","+fq.getVar().getSafeSymbol();
+ cr.endblock();
+
+ /* Build standard compensation actions */
+ if (need_compensation(currentrule)) {
+ UpdateNode un=find_compensation(currentrule);
+ String name=(String)updatenames.get(un);
+ usedupdates.add(un); /* Mark as used */
+ String methodcall=name+"(this,"+oldmodel.getSafeSymbol()+","+repairtable.getSafeSymbol();
+ for(int i=0;i<currentrule.numQuantifiers();i++) {
+ Quantifier q=currentrule.getQuantifier(i);
+ if (q instanceof SetQuantifier) {
+ SetQuantifier sq=(SetQuantifier) q;
+ methodcall+=","+sq.getVar().getSafeSymbol();
+ } else if (q instanceof RelationQuantifier) {
+ RelationQuantifier rq=(RelationQuantifier) q;
+ methodcall+=","+rq.x.getSafeSymbol();
+ methodcall+=","+rq.y.getSafeSymbol();
+ } else if (q instanceof ForQuantifier) {
+ ForQuantifier fq=(ForQuantifier) q;
+ methodcall+=","+fq.getVar().getSafeSymbol();
+ }
}
+ methodcall+=");";
+ cr.outputline(methodcall);
+ cr.outputline("goto rebuild;");
}
- methodcall+=");";
- cr.outputline(methodcall);
- cr.outputline("goto rebuild;");
}
+ cr.endblock();
}
- cr.endblock();
String addeditem = (VarDescriptor.makeNew("addeditem")).getSafeSymbol();
cr.outputline("int " + addeditem + ";");
cr.outputline(addeditem + " = " + rd.getSafeSymbol() + "_hashinv->add((int)" + rightvar + ", (int)" + leftvar + ");");
}
- cr.outputline("if (" + addeditem + ")");
- cr.startblock();
+
Vector dispatchrules = getrulelist(rd);
dispatchrules.removeAll(toremove);
if (dispatchrules.size() == 0) {
cr.outputline("// nothing to dispatch");
- cr.endblock();
return;
}
-
- cr.outputline("if ("+addeditem+")");
+
+ cr.outputline("if (" + addeditem + ")");
cr.startblock();
+
for(int i = 0; i < dispatchrules.size(); i++) {
Rule rule = (Rule) dispatchrules.elementAt(i);
if (rule.getGuardExpr().getRequiredDescriptors().contains(rd)) {
}
}
}
- cr.endblock();
+
cr.endblock();
}
public void generate_dispatch(CodeWriter cr, SetDescriptor sd, String setvar) {
cr.outputline("// SET DISPATCH ");
-
- cr.outputline("if ("+oldmodel.getSafeSymbol()+"&&");
- cr.outputline("!"+oldmodel.getSafeSymbol() +"->"+sd.getJustSafeSymbol()+"_hash->contains("+setvar+"))");
- cr.startblock(); {
- /* Adding new item */
- /* Perform safety checks */
- cr.outputline("if ("+repairtable.getSafeSymbol()+"&&");
- cr.outputline(repairtable.getSafeSymbol()+"->containsset("+sd.getNum()+","+currentrule.getNum()+","+setvar+"))");
+ if (Compiler.REPAIR) {
+ cr.outputline("if ("+oldmodel.getSafeSymbol()+"&&");
+ cr.outputline("!"+oldmodel.getSafeSymbol() +"->"+sd.getJustSafeSymbol()+"_hash->contains("+setvar+"))");
cr.startblock(); {
- /* Have update to call into */
- VarDescriptor funptr=VarDescriptor.makeNew("updateptr");
- String parttype="";
- for(int i=0;i<currentrule.numQuantifiers();i++) {
- if (currentrule.getQuantifier(i) instanceof RelationQuantifier)
- parttype=parttype+", int, int";
- else
- parttype=parttype+", int";
- }
- cr.outputline("void (*"+funptr.getSafeSymbol()+") ("+name+"_state *,"+name+"*,RepairHash *"+parttype+")=");
- cr.outputline("(void (*) ("+name+"_state *,"+name+"*,RepairHash *"+parttype+")) "+repairtable.getSafeSymbol()+"->getset("+sd.getNum()+","+currentrule.getNum()+","+setvar+");");
- String methodcall="("+funptr.getSafeSymbol()+") (this,"+oldmodel.getSafeSymbol()+","+
- repairtable.getSafeSymbol();
- for(int i=0;i<currentrule.numQuantifiers();i++) {
- Quantifier q=currentrule.getQuantifier(i);
- if (q instanceof SetQuantifier) {
- SetQuantifier sq=(SetQuantifier) q;
- methodcall+=","+sq.getVar().getSafeSymbol();
- } else if (q instanceof RelationQuantifier) {
- RelationQuantifier rq=(RelationQuantifier) q;
- methodcall+=","+rq.x.getSafeSymbol();
- methodcall+=","+rq.y.getSafeSymbol();
- } else if (q instanceof ForQuantifier) {
- ForQuantifier fq=(ForQuantifier) q;
- methodcall+=","+fq.getVar().getSafeSymbol();
+ /* Adding new item */
+ /* Perform safety checks */
+ cr.outputline("if ("+repairtable.getSafeSymbol()+"&&");
+ cr.outputline(repairtable.getSafeSymbol()+"->containsset("+sd.getNum()+","+currentrule.getNum()+","+setvar+"))");
+ cr.startblock(); {
+ /* Have update to call into */
+ VarDescriptor funptr=VarDescriptor.makeNew("updateptr");
+ String parttype="";
+ for(int i=0;i<currentrule.numQuantifiers();i++) {
+ if (currentrule.getQuantifier(i) instanceof RelationQuantifier)
+ parttype=parttype+", int, int";
+ else
+ parttype=parttype+", int";
}
+ cr.outputline("void (*"+funptr.getSafeSymbol()+") ("+name+"_state *,"+name+"*,RepairHash *"+parttype+")=");
+ cr.outputline("(void (*) ("+name+"_state *,"+name+"*,RepairHash *"+parttype+")) "+repairtable.getSafeSymbol()+"->getset("+sd.getNum()+","+currentrule.getNum()+","+setvar+");");
+ String methodcall="("+funptr.getSafeSymbol()+") (this,"+oldmodel.getSafeSymbol()+","+
+ repairtable.getSafeSymbol();
+ for(int i=0;i<currentrule.numQuantifiers();i++) {
+ Quantifier q=currentrule.getQuantifier(i);
+ if (q instanceof SetQuantifier) {
+ SetQuantifier sq=(SetQuantifier) q;
+ methodcall+=","+sq.getVar().getSafeSymbol();
+ } else if (q instanceof RelationQuantifier) {
+ RelationQuantifier rq=(RelationQuantifier) q;
+ methodcall+=","+rq.x.getSafeSymbol();
+ methodcall+=","+rq.y.getSafeSymbol();
+ } else if (q instanceof ForQuantifier) {
+ ForQuantifier fq=(ForQuantifier) q;
+ methodcall+=","+fq.getVar().getSafeSymbol();
+ }
+ }
+ methodcall+=");";
+ cr.outputline(methodcall);
+ cr.outputline("goto rebuild;");
}
- methodcall+=");";
- cr.outputline(methodcall);
- cr.outputline("goto rebuild;");
- }
- cr.endblock();
- /* Build standard compensation actions */
- if (need_compensation(currentrule)) {
- UpdateNode un=find_compensation(currentrule);
- String name=(String)updatenames.get(un);
- usedupdates.add(un); /* Mark as used */
-
- String methodcall=name+"(this,"+oldmodel.getSafeSymbol()+","+
- repairtable.getSafeSymbol();
- for(int i=0;i<currentrule.numQuantifiers();i++) {
- Quantifier q=currentrule.getQuantifier(i);
- if (q instanceof SetQuantifier) {
- SetQuantifier sq=(SetQuantifier) q;
- methodcall+=","+sq.getVar().getSafeSymbol();
- } else if (q instanceof RelationQuantifier) {
- RelationQuantifier rq=(RelationQuantifier) q;
- methodcall+=","+rq.x.getSafeSymbol();
- methodcall+=","+rq.y.getSafeSymbol();
- } else if (q instanceof ForQuantifier) {
- ForQuantifier fq=(ForQuantifier) q;
- methodcall+=","+fq.getVar().getSafeSymbol();
+ cr.endblock();
+ /* Build standard compensation actions */
+ if (need_compensation(currentrule)) {
+ UpdateNode un=find_compensation(currentrule);
+ String name=(String)updatenames.get(un);
+ usedupdates.add(un); /* Mark as used */
+
+ String methodcall=name+"(this,"+oldmodel.getSafeSymbol()+","+
+ repairtable.getSafeSymbol();
+ for(int i=0;i<currentrule.numQuantifiers();i++) {
+ Quantifier q=currentrule.getQuantifier(i);
+ if (q instanceof SetQuantifier) {
+ SetQuantifier sq=(SetQuantifier) q;
+ methodcall+=","+sq.getVar().getSafeSymbol();
+ } else if (q instanceof RelationQuantifier) {
+ RelationQuantifier rq=(RelationQuantifier) q;
+ methodcall+=","+rq.x.getSafeSymbol();
+ methodcall+=","+rq.y.getSafeSymbol();
+ } else if (q instanceof ForQuantifier) {
+ ForQuantifier fq=(ForQuantifier) q;
+ methodcall+=","+fq.getVar().getSafeSymbol();
+ }
}
+ methodcall+=");";
+ cr.outputline(methodcall);
+ cr.outputline("goto rebuild;");
}
- methodcall+=");";
- cr.outputline(methodcall);
- cr.outputline("goto rebuild;");
}
+ cr.endblock();
}
- cr.endblock();
String addeditem = (VarDescriptor.makeNew("addeditem")).getSafeSymbol();
cr.outputline("int " + addeditem + " = 1;");
}
}
}
-
cr.endblock();
cr.endblock();
}