generate_call();
generate_start();
generate_rules();
- if (!Compiler.REPAIR) {
+ if (!Compiler.REPAIR||Compiler.GENERATEDEBUGPRINT) {
generate_print();
}
generate_checks();
CodeWriter craux = new StandardCodeWriter(this.outputaux);
crhead.outputline("};");
craux.outputline("}");
+
+ if (Compiler.GENERATEDEBUGHOOKS) {
+ crhead.outputline("void debughook();");
+ craux.outputline("void debughook() {}");
+ }
generatetypechecks(false);
generate_computesizes();
generatetypechecks(true);
cr.outputline("else if (!" + constraintboolean.getSafeSymbol() + ")");
cr.startblock();
- if (!Compiler.REPAIR)
+ if (!Compiler.REPAIR||Compiler.GENERATEDEBUGHOOKS)
cr.outputline("printf(\"fail " + escape(constraint.toString()) + ". \\n\");");
- else {
+
+ if (Compiler.REPAIR) {
/* Do repairs */
/* Build new repair table */
cr.outputline("if ("+repairtable.getSafeSymbol()+")");
cr.outputline("delete "+repairtable.getSafeSymbol()+";");
cr.outputline(repairtable.getSafeSymbol()+"=new RepairHash();");
-
+ if (Compiler.GENERATEDEBUGHOOKS)
+ cr.outputline("debughook();");
/* Compute cost of each repair */
VarDescriptor mincost=VarDescriptor.makeNew("mincost");
VarDescriptor mincostindex=VarDescriptor.makeNew("mincostindex");
- DNFConstraint dnfconst=constraint.dnfconstraint;
+ Vector dnfconst=new Vector();
+ dnfconst.addAll((Set)termination.conjunctionmap.get(constraint));
+
if (dnfconst.size()<=1) {
cr.outputline("int "+mincostindex.getSafeSymbol()+"=0;");
}
cr.outputline("int "+mincostindex.getSafeSymbol()+";");
boolean first=true;
for(int j=0;j<dnfconst.size();j++) {
- Conjunction conj=dnfconst.get(j);
- GraphNode gn=(GraphNode)termination.conjtonodemap.get(conj);
+ GraphNode gn=(GraphNode)dnfconst.get(j);
+ Conjunction conj=((TermNode)gn.getOwner()).getConjunction();
if (removed.contains(gn))
continue;
boolean negate=dpred.isNegated();
VarDescriptor predvalue=VarDescriptor.makeNew("Predicatevalue");
p.generate(cr,predvalue);
+ if (k==0)
+ cr.outputline("int "+costvar.getSafeSymbol()+"=0;");
+
if (negate)
cr.outputline("if (maybe||"+predvalue.getSafeSymbol()+")");
else
cr.outputline("if (maybe||!"+predvalue.getSafeSymbol()+")");
- if (k==0)
- cr.outputline("int "+costvar.getSafeSymbol()+"="+cost.getCost(dpred)+";");
- else
- cr.outputline(costvar.getSafeSymbol()+"+="+cost.getCost(dpred)+";");
+ cr.outputline(costvar.getSafeSymbol()+"+="+cost.getCost(dpred)+";");
}
if(!first) {
}
cr.outputline("switch("+mincostindex.getSafeSymbol()+") {");
for(int j=0;j<dnfconst.size();j++) {
- Conjunction conj=dnfconst.get(j);
- GraphNode gn=(GraphNode)termination.conjtonodemap.get(conj);
+ GraphNode gn=(GraphNode)dnfconst.get(j);
+ Conjunction conj=((TermNode)gn.getOwner()).getConjunction();
+
if (removed.contains(gn))
continue;
cr.outputline("case "+j+":");
+ cr.startblock();
for(int k=0;k<conj.size();k++) {
DNFPredicate dpred=conj.get(k);
Predicate p=dpred.getPredicate();
cr.endblock();
}
/* Update model */
+ cr.endblock();
cr.outputline("break;");
}
cr.outputline("}");
VarDescriptor rightside=VarDescriptor.makeNew("rightside");
VarDescriptor newvalue=VarDescriptor.makeNew("newvalue");
if (!inverted) {
- expr.getLeftExpr().generate(cr,leftside);
+ ((RelationExpr)expr.getLeftExpr()).getExpr().generate(cr,leftside);
expr.getRightExpr().generate(cr,newvalue);
cr.outputline(rd.getRange().getType().getGenerateType().getSafeSymbol()+" "+rightside.getSafeSymbol()+";");
cr.outputline(rd.getSafeSymbol()+"_hash->get("+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+");");
} else {
- expr.getLeftExpr().generate(cr,rightside);
+ ((RelationExpr)expr.getLeftExpr()).getExpr().generate(cr,rightside);
expr.getRightExpr().generate(cr,newvalue);
cr.outputline(rd.getDomain().getType().getGenerateType().getSafeSymbol()+" "+leftside.getSafeSymbol()+";");
- cr.outputline(rd.getSafeSymbol()+"_hashinv->get("+leftside.getSafeSymbol()+","+leftside.getSafeSymbol()+");");
+ cr.outputline(rd.getSafeSymbol()+"_hashinv->get("+rightside.getSafeSymbol()+","+leftside.getSafeSymbol()+");");
}
if (negated)
if (opcode==Opcode.GT) {
Rule r=(Rule)state.vRules.get(i);
if (r.getInclusion().getTargetDescriptors().contains(rd)) {
for(int j=0;j<mun.numUpdates();j++) {
- UpdateNode un=mun.getUpdate(i);
+ UpdateNode un=mun.getUpdate(j);
if (un.getRule()==r) {
/* Update for rule rule r */
String name=(String)updatenames.get(un);
Rule r=(Rule)state.vRules.get(i);
if (r.getInclusion().getTargetDescriptors().contains(sd)) {
for(int j=0;j<mun.numUpdates();j++) {
- UpdateNode un=mun.getUpdate(i);
+ UpdateNode un=mun.getUpdate(j);
if (un.getRule()==r) {
/* Update for rule rule r */
String name=(String)updatenames.get(un);
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+");");
+ VarDescriptor ismdfyptr=VarDescriptor.makeNew("ismodifyptr");
+ cr.outputline("int "+ismdfyptr.getSafeSymbol()+"="+repairtable.getSafeSymbol()+"->ismodify("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
+
+
+
String parttype="";
for(int i=0;i<currentrule.numQuantifiers();i++) {
}
-
+
cr.outputline("void *"+tmpptr.getSafeSymbol()+"=");
cr.outputline("(void *) "+repairtable.getSafeSymbol()+"->getrelation("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
- cr.outputline("if ("+mdfyptr.getSafeSymbol()+")");
+ cr.outputline("if ("+ismdfyptr.getSafeSymbol()+")");
{
cr.startblock();
+ cr.outputline("int "+mdfyptr.getSafeSymbol()+"="+repairtable.getSafeSymbol()+"->getrelation2("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
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(methodcall+");");
cr.endblock();
}
+ cr.outputline("delete "+newmodel.getSafeSymbol()+";");
cr.outputline("goto rebuild;");
}
cr.endblock();
}
methodcall+=");";
cr.outputline(methodcall);
+ cr.outputline("delete "+newmodel.getSafeSymbol()+";");
cr.outputline("goto rebuild;");
}
}
}
String addeditem = (VarDescriptor.makeNew("addeditem")).getSafeSymbol();
- cr.outputline("int " + addeditem + ";");
+ cr.outputline("int " + addeditem + "=0;");
+
+ String ifstring="if (!maybe&&";
+ boolean dogenerate=false;
+ if (rd.getDomain().getType() instanceof StructureTypeDescriptor) {
+ dogenerate=true;
+ ifstring+=leftvar;
+ }
+
+ if (rd.getRange().getType() instanceof StructureTypeDescriptor) {
+ if (dogenerate)
+ ifstring+="&&"+rightvar;
+ else
+ ifstring+=rightvar;
+ dogenerate=true;
+ }
+
+ ifstring+=")";
+
if (rd.testUsage(RelationDescriptor.IMAGE)) {
+ cr.outputline(ifstring);
cr.outputline(addeditem + " = " + rd.getSafeSymbol() + "_hash->add((int)" + leftvar + ", (int)" + rightvar+ ");");
}
if (rd.testUsage(RelationDescriptor.INVIMAGE)) {
+ cr.outputline(ifstring);
cr.outputline(addeditem + " = " + rd.getSafeSymbol() + "_hashinv->add((int)" + rightvar + ", (int)" + leftvar + ");");
}
-
Vector dispatchrules = getrulelist(rd);
Set toremove=new HashSet();
}
methodcall+=");";
cr.outputline(methodcall);
+ cr.outputline("delete "+newmodel.getSafeSymbol()+";");
cr.outputline("goto rebuild;");
}
cr.endblock();
}
methodcall+=");";
cr.outputline(methodcall);
+ cr.outputline("delete "+newmodel.getSafeSymbol()+";");
cr.outputline("goto rebuild;");
}
}
}
String addeditem = (VarDescriptor.makeNew("addeditem")).getSafeSymbol();
- cr.outputline("int " + addeditem + " = 1;");
+ cr.outputline("int " + addeditem + " = 0;");
+ if (sd.getType() instanceof StructureTypeDescriptor) {
+ cr.outputline("if (!maybe&&"+setvar+")");
+ } else
+ cr.outputline("if (!maybe)");
cr.outputline(addeditem + " = " + sd.getSafeSymbol() + "_hash->add((int)" + setvar + ", (int)" + setvar + ");");
cr.startblock();
Vector dispatchrules = getrulelist(sd);