X-Git-Url: http://plrg.eecs.uci.edu/git/?p=repair.git;a=blobdiff_plain;f=Repair%2FRepairCompiler%2FMCC%2FIR%2FRepairGenerator.java;h=11c3ea2b956087935b33247b346207097ca58f21;hp=52631d473d6c9928308901a7e2f6170e189d6e02;hb=d086755cbded13a81a70c555327b7a3a766b31b8;hpb=0b318afaec69dfabbaf366bd49dc7fa66c7befbf diff --git a/Repair/RepairCompiler/MCC/IR/RepairGenerator.java b/Repair/RepairCompiler/MCC/IR/RepairGenerator.java index 52631d4..11c3ea2 100755 --- a/Repair/RepairCompiler/MCC/IR/RepairGenerator.java +++ b/Repair/RepairCompiler/MCC/IR/RepairGenerator.java @@ -3,6 +3,7 @@ package MCC.IR; import java.io.*; import java.util.*; import MCC.State; +import MCC.Compiler; public class RepairGenerator { State state; @@ -24,7 +25,7 @@ public class RepairGenerator { HashSet togenerate; static boolean DEBUG=false; Cost cost; - Sources sources; + ModelRuleDependence mrd; public RepairGenerator(State state, Termination t) { this.state = state; @@ -34,10 +35,11 @@ public class RepairGenerator { removed=t.removedset; togenerate=new HashSet(); togenerate.addAll(termination.conjunctions); - togenerate.removeAll(removed); + if (Compiler.REPAIR) + togenerate.removeAll(removed); GraphNode.computeclosure(togenerate,removed); cost=new Cost(); - sources=new Sources(state); + mrd=ModelRuleDependence.doAnalysis(state); Repair.repairgenerator=this; } @@ -82,14 +84,22 @@ public class RepairGenerator { generate_hashtables(); generate_stateobject(); generate_call(); - generate_worklist(); + generate_start(); generate_rules(); + if (!Compiler.REPAIR||Compiler.GENERATEDEBUGPRINT) { + generate_print(); + } generate_checks(); generate_teardown(); CodeWriter crhead = new StandardCodeWriter(this.outputhead); 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); @@ -106,11 +116,14 @@ public class RepairGenerator { String strepairtable="repairtable"; String stleft="left"; String stright="right"; + String stnew="newvalue"; private void generate_updates() { int count=0; CodeWriter crhead = new StandardCodeWriter(outputhead); CodeWriter craux = new StandardCodeWriter(outputaux); + RelationDescriptor.prefix = "model->"; + SetDescriptor.prefix = "model->"; /* Rewrite globals */ @@ -144,11 +157,11 @@ public class RepairGenerator { CodeWriter cr = new StandardCodeWriter(outputaux) { public SymbolTable getSymbolTable() { return st; } }; - un.generate(cr, false, stleft,stright,this); + un.generate(cr, false, false, stleft,stright, null,this); craux.outputline("if (maybe) printf(\"REALLY BAD\");"); craux.endblock(); break; - case MultUpdateNode.REMOVE: + case MultUpdateNode.REMOVE: { Rule r=un.getRule(); String methodcall="void "+methodname+"("+name+"_state * "+ststate+","+name+" * "+stmodel+", RepairHash * "+strepairtable; for(int j=0;j"; - SetDescriptor.prefix = newmodel.getSafeSymbol()+"->"; - - 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(outputaux) { - public SymbolTable getSymbolTable() { return st; } - }; - cr.outputline("// build " +escape(rule.toString())); - cr.startblock(); - cr.outputline("int maybe=0;"); - 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(""); + private void generate_print() { + + final SymbolTable st = new SymbolTable(); - /* now we have to generate the guard test */ - VarDescriptor guardval = VarDescriptor.makeNew(); - rule.getGuardExpr().generate(cr, guardval); - cr.outputline("if (" + guardval.getSafeSymbol() + ")"); - cr.startblock(); + CodeWriter cr = new StandardCodeWriter(outputaux) { + public SymbolTable getSymbolTable() { return st; } + }; - /* now we have to generate the inclusion code */ - currentrule=rule; - rule.getInclusion().generate(cr); - cr.endblock(); - while (quantifiers.hasPrevious()) { - Quantifier quantifier = (Quantifier) quantifiers.previous(); - cr.endblock(); - } - cr.endblock(); - cr.outputline(""); - cr.outputline(""); - } - } + cr.outputline("// printing sets!"); + cr.outputline("printf(\"\\n\\nPRINTING SETS AND RELATIONS\\n\");"); - CodeWriter cr2 = new StandardCodeWriter(outputaux); + Iterator setiterator = state.stSets.descriptors(); + while (setiterator.hasNext()) { + SetDescriptor sd = (SetDescriptor) setiterator.next(); + if (sd.getSymbol().equals("int") || sd.getSymbol().equals("token")) { + continue; + } - cr2.outputline("while ("+goodflag.getSafeSymbol()+"&&"+worklist.getSafeSymbol()+"->hasMoreElements())"); - cr2.startblock(); - VarDescriptor idvar=VarDescriptor.makeNew("id"); - cr2.outputline("int "+idvar.getSafeSymbol()+"="+worklist.getSafeSymbol()+"->getid();"); - - String elseladder = "if"; + String setname = sd.getSafeSymbol(); - Iterator iterator_rules = worklistrules.iterator(); - while (iterator_rules.hasNext()) { + 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();"); - Rule rule = (Rule) iterator_rules.next(); - int dispatchid = rule.getNum(); + 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);"); + } - { - final SymbolTable st = rule.getSymbolTable(); - CodeWriter cr = new StandardCodeWriter(outputaux) { - public SymbolTable getSymbolTable() { return st; } - }; - cr.indent(); - cr.outputline(elseladder + " ("+idvar.getSafeSymbol()+" == " + dispatchid + ")"); - cr.startblock(); - cr.outputline("int maybe=0;"); - VarDescriptor typevar=VarDescriptor.makeNew("type"); - VarDescriptor leftvar=VarDescriptor.makeNew("left"); - VarDescriptor rightvar=VarDescriptor.makeNew("right"); - cr.outputline("int "+typevar.getSafeSymbol()+"="+worklist.getSafeSymbol()+"->gettype();"); - cr.outputline("int "+leftvar.getSafeSymbol()+"="+worklist.getSafeSymbol()+"->getlvalue();"); - cr.outputline("int "+rightvar.getSafeSymbol()+"="+worklist.getSafeSymbol()+"->getrvalue();"); - cr.outputline("// build " +escape(rule.toString())); + cr.endblock(); + cr.endblock(); + } + cr.outputline("printf(\"\\n\\n------------------- END PRINTING\\n\");"); + } - for (int j=0;j"; + SetDescriptor.prefix = newmodel.getSafeSymbol()+"->"; + System.out.println("SCC="+(mrd.numSCC()-1)); + for(int sccindex=0;sccindexadd("+rule.getNum()+",-1,0,0);"); } - // 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.outputline(worklist.getSafeSymbol()+"->pop();"); - cr2.endblock(); + cr2.outputline("while ("+worklist.getSafeSymbol()+"->hasMoreElements())"); + cr2.startblock(); + VarDescriptor idvar=VarDescriptor.makeNew("id"); + cr2.outputline("int "+idvar.getSafeSymbol()+"="+worklist.getSafeSymbol()+"->getid();"); + + String elseladder = "if"; + + Iterator iterator_rules = ruleset.iterator(); + while (iterator_rules.hasNext()) { + + Rule rule = (Rule) iterator_rules.next(); + int dispatchid = rule.getNum(); + + { + final SymbolTable st = rule.getSymbolTable(); + CodeWriter cr = new StandardCodeWriter(outputaux) { + public SymbolTable getSymbolTable() { return st; } + }; + + cr.indent(); + cr.outputline(elseladder + " ("+idvar.getSafeSymbol()+" == " + dispatchid + ")"); + cr.startblock(); + cr.outputline("int maybe=0;"); + VarDescriptor typevar=VarDescriptor.makeNew("type"); + VarDescriptor leftvar=VarDescriptor.makeNew("left"); + VarDescriptor rightvar=VarDescriptor.makeNew("right"); + cr.outputline("int "+typevar.getSafeSymbol()+"="+worklist.getSafeSymbol()+"->gettype();"); + cr.outputline("int "+leftvar.getSafeSymbol()+"="+worklist.getSafeSymbol()+"->getlvalue();"); + cr.outputline("int "+rightvar.getSafeSymbol()+"="+worklist.getSafeSymbol()+"->getrvalue();"); + cr.outputline("// build " +escape(rule.toString())); + + + for (int j=0;jpop();"); + cr2.endblock(); + } + } } public static String escape(String s) { @@ -596,29 +688,28 @@ public class RepairGenerator { private void generate_checks() { /* do constraint checks */ - Vector constraints = state.vConstraints; - - for (int i = 0; i < constraints.size(); i++) { + // Vector constraints = state.vConstraints; - 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); + cr.pushSymbolTable(constraint.getSymbolTable()); - final SymbolTable st = constraint.getSymbolTable(); - - CodeWriter cr = new StandardCodeWriter(outputaux) { - public SymbolTable getSymbolTable() { return st; } - }; - - cr.outputline("// checking " + escape(constraint.toString())); + 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;"); @@ -629,22 +720,24 @@ public class RepairGenerator { cr.outputline("if (maybe)"); cr.startblock(); - cr.outputline("printf(\"maybe fail " + escape(constraint.toString()) + ". \");"); + cr.outputline("printf(\"maybe fail " + escape(constraint.toString()) + ". \\n\");"); cr.outputline("exit(1);"); cr.endblock(); cr.outputline("else if (!" + constraintboolean.getSafeSymbol() + ")"); cr.startblock(); - if (DEBUG) - cr.outputline("printf(\"fail " + escape(constraint.toString()) + ". \");"); - + if (!Compiler.REPAIR||Compiler.GENERATEDEBUGHOOKS) + cr.outputline("printf(\"fail " + escape(constraint.toString()) + ". \\n\");"); + + 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"); @@ -727,36 +820,36 @@ public class RepairGenerator { } cr.outputline("}"); - cr.outputline(goodflag.getSafeSymbol()+"=0;"); cr.outputline("if ("+oldmodel.getSafeSymbol()+")"); cr.outputline("delete "+oldmodel.getSafeSymbol()+";"); cr.outputline(oldmodel.getSafeSymbol()+"="+newmodel.getSafeSymbol()+";"); cr.outputline("goto rebuild;"); /* Rebuild model and all */ - + } cr.endblock(); - + while (quantifiers.hasPrevious()) { Quantifier quantifier = (Quantifier) quantifiers.previous(); cr.endblock(); } - cr.outputline("if ("+goodflag.getSafeSymbol()+")"); - cr.startblock(); - cr.outputline("if ("+repairtable.getSafeSymbol()+")"); - cr.outputline("delete "+repairtable.getSafeSymbol()+";"); - cr.outputline("if ("+oldmodel.getSafeSymbol()+")"); - cr.outputline("delete "+oldmodel.getSafeSymbol()+";"); - cr.outputline("delete "+newmodel.getSafeSymbol()+";"); - cr.outputline("delete "+worklist.getSafeSymbol()+";"); - cr.outputline("resettypemap();"); - cr.outputline("break;"); - cr.endblock(); - cr.outputline("rebuild:"); - cr.outputline(";"); cr.endblock(); cr.outputline(""); cr.outputline(""); } } + CodeWriter cr = new StandardCodeWriter(outputaux); + cr.startblock(); + cr.outputline("if ("+repairtable.getSafeSymbol()+")"); + cr.outputline("delete "+repairtable.getSafeSymbol()+";"); + cr.outputline("if ("+oldmodel.getSafeSymbol()+")"); + cr.outputline("delete "+oldmodel.getSafeSymbol()+";"); + cr.outputline("delete "+newmodel.getSafeSymbol()+";"); + cr.outputline("delete "+worklist.getSafeSymbol()+";"); + cr.outputline("resettypemap();"); + cr.outputline("break;"); + cr.endblock(); + cr.outputline("rebuild:"); + cr.outputline(";"); + } private MultUpdateNode getmultupdatenode(Conjunction conj, DNFPredicate dpred, int repairtype) { @@ -785,7 +878,10 @@ public class RepairGenerator { return mun; } - public void generatecomparisonrepair(Conjunction conj, DNFPredicate dpred, CodeWriter cr){ + /** Generates abstract (and concrete) repair for a comparison */ + + private void generatecomparisonrepair(Conjunction conj, DNFPredicate dpred, CodeWriter cr){ + MultUpdateNode munmodify=getmultupdatenode(conj,dpred,AbstractRepair.MODIFYRELATION); MultUpdateNode munremove=getmultupdatenode(conj,dpred,AbstractRepair.REMOVEFROMRELATION); MultUpdateNode munadd=getmultupdatenode(conj,dpred,AbstractRepair.ADDTORELATION); ExprPredicate ep=(ExprPredicate)dpred.getPredicate(); @@ -800,15 +896,15 @@ public class RepairGenerator { 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) { @@ -837,7 +933,7 @@ public class RepairGenerator { /* 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"); @@ -860,27 +956,44 @@ public class RepairGenerator { } } /* Do concrete repairs */ - /* Start with scheduling removal */ - for(int i=0;iaddrelation("+rd.getNum()+","+r.getNum()+","+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+",(int) &"+name+");"); + if (munmodify!=null) { + for(int i=0;iaddrelation("+rd.getNum()+","+r.getNum()+","+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+",(int) &"+name+","+newvalue.getSafeSymbol()+");"); + } } } } - } - /* Now do addition */ - UpdateNode un=munadd.getUpdate(0); - String name=(String)updatenames.get(un); - if (!inverted) { - cr.outputline(name+"(this,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+leftside.getSafeSymbol()+","+newvalue.getSafeSymbol()+");"); + } else { - cr.outputline(name+"(this,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+newvalue.getSafeSymbol()+","+rightside.getSafeSymbol()+");"); + /* Start with scheduling removal */ + for(int i=0;iaddrelation("+rd.getNum()+","+r.getNum()+","+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+",(int) &"+name+");"); + } + } + } + } + /* Now do addition */ + UpdateNode un=munadd.getUpdate(0); + String name=(String)updatenames.get(un); + if (!inverted) { + cr.outputline(name+"(this,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+leftside.getSafeSymbol()+","+newvalue.getSafeSymbol()+");"); + } else { + cr.outputline(name+"(this,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+newvalue.getSafeSymbol()+","+rightside.getSafeSymbol()+");"); + } } } @@ -888,25 +1001,8 @@ public class RepairGenerator { 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; @@ -917,7 +1013,7 @@ public class RepairGenerator { 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"); @@ -942,7 +1038,10 @@ public class RepairGenerator { generateremove=true; } else if (opcode==Opcode.EQ) { cr.outputline(change.getSafeSymbol()+"="+String.valueOf(size)+"-"+sizevar.getSafeSymbol()+";"); - generateadd=true; + if (size==0) + generateadd=false; + else + generateadd=true; generateremove=true; } else if (opcode==Opcode.NE) { cr.outputline(change.getSafeSymbol()+"="+String.valueOf(size+1)+"-"+sizevar.getSafeSymbol()+";"); @@ -951,6 +1050,12 @@ public class RepairGenerator { } 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()+"++)"); @@ -965,7 +1070,7 @@ public class RepairGenerator { cr.outputline(d.getSafeSymbol()+"_hashinv->get((int)"+rightvar.getSafeSymbol()+","+leftvar.getSafeSymbol()+");"); } else { leftvar=((ImageSetExpr)((SizeofExpr)((OpExpr)expr).left).setexpr).getVar(); - cr.outputline("int "+rightvar.getSafeSymbol()+";"); + cr.outputline("int "+rightvar.getSafeSymbol()+"=0;"); cr.outputline(d.getSafeSymbol()+"_hash->get((int)"+leftvar.getSafeSymbol()+","+rightvar.getSafeSymbol()+");"); } } else { @@ -977,18 +1082,18 @@ public class RepairGenerator { boolean usageimage=rd.testUsage(RelationDescriptor.IMAGE); boolean usageinvimage=rd.testUsage(RelationDescriptor.INVIMAGE); if (usageimage) - cr.outputline(rd.getSafeSymbol() + "_hash->remove((int)" + leftvar + ", (int)" + rightvar + ");"); + cr.outputline(rd.getSafeSymbol() + "_hash->remove((int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");"); if (usageinvimage) - cr.outputline(rd.getSafeSymbol() + "_hashinv->remove((int)" + rightvar + ", (int)" + leftvar + ");"); + cr.outputline(rd.getSafeSymbol() + "_hashinv->remove((int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");"); } else { - cr.outputline(d.getSafeSymbol() + "_hash->remove((int)" + leftvar + ", (int)" + leftvar + ");"); + cr.outputline(d.getSafeSymbol() + "_hash->remove((int)" + leftvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");"); } /* Generate concrete remove instruction */ for(int i=0;iiterator();"+iterator.getSafeSymbol()+".hasNext();)"); + cr.outputline("SimpleIterator "+iterator.getSafeSymbol()+";"); + cr.outputline("for("+sd.getSafeSymbol()+"_hash->iterator("+ iterator.getSafeSymbol() +");"+iterator.getSafeSymbol()+".hasNext();)"); cr.startblock(); if (ep.inverted()) { - cr.outputline("if !"+rd.getSafeSymbol()+"_hashinv->contains("+iterator.getSafeSymbol()+"->key(),"+otherside.getSafeSymbol()+")"); + cr.outputline("if (!"+rd.getSafeSymbol()+"_hashinv->contains("+iterator.getSafeSymbol()+".key(),"+otherside.getSafeSymbol()+"))"); } else { - cr.outputline("if !"+rd.getSafeSymbol()+"_hash->contains("+otherside.getSafeSymbol()+","+iterator.getSafeSymbol()+"->key())"); + cr.outputline("if (!"+rd.getSafeSymbol()+"_hash->contains("+otherside.getSafeSymbol()+","+iterator.getSafeSymbol()+".key()))"); } cr.outputline(newobject.getSafeSymbol()+"="+iterator.getSafeSymbol()+".key();"); - cr.outputline(iterator.getSafeSymbol()+"->next();"); + cr.outputline(iterator.getSafeSymbol()+".next();"); cr.endblock(); - } else if (sources.relallocSource(rd,!ep.inverted())) { + } else if (termination.sources.relallocSource(rd,!ep.inverted())) { /* Allocation Source*/ - sources.relgenerateSourceAlloc(cr,newobject,rd,!ep.inverted()); + termination.sources.relgenerateSourceAlloc(cr,newobject,rd,!ep.inverted()); } else throw new Error("No source for adding to Relation"); if (ep.inverted()) { boolean usageimage=rd.testUsage(RelationDescriptor.IMAGE); @@ -1054,21 +1160,22 @@ public class RepairGenerator { } } else { SetDescriptor sd=(SetDescriptor)d; - if (sources.setSource(sd)) { + if (termination.sources.setSource(sd)) { /* Set Source */ /* Set Source */ - SetDescriptor sourcesd=sources.getSourceSet(sd); + SetDescriptor sourcesd=termination.sources.getSourceSet(sd); VarDescriptor iterator=VarDescriptor.makeNew("iterator"); cr.outputline(sourcesd.getType().getGenerateType().getSafeSymbol() +" "+newobject.getSafeSymbol()+";"); - cr.outputline("for("+iterator.getSafeSymbol()+"="+sourcesd.getSafeSymbol()+"_hash->iterator();"+iterator.getSafeSymbol()+".hasNext();)"); + cr.outputline("SimpleIterator "+iterator.getSafeSymbol()+";"); + cr.outputline("for("+sourcesd.getSafeSymbol()+"_hash->iterator("+iterator.getSafeSymbol()+");"+iterator.getSafeSymbol()+".hasNext();)"); cr.startblock(); - cr.outputline("if !"+sd.getSafeSymbol()+"_hash->contains("+iterator.getSafeSymbol()+"->key())"); + cr.outputline("if (!"+sd.getSafeSymbol()+"_hash->contains("+iterator.getSafeSymbol()+".key()))"); cr.outputline(newobject.getSafeSymbol()+"="+iterator.getSafeSymbol()+".key();"); - cr.outputline(iterator.getSafeSymbol()+"->next();"); + cr.outputline(iterator.getSafeSymbol()+".next();"); cr.endblock(); - } else if (sources.allocSource(sd)) { + } else if (termination.sources.allocSource(sd)) { /* Allocation Source*/ - sources.generateSourceAlloc(cr,newobject,sd); + termination.sources.generateSourceAlloc(cr,newobject,sd); } else throw new Error("No source for adding to Set"); cr.outputline(sd.getSafeSymbol()+"_hash->add("+newobject.getSafeSymbol()+","+newobject.getSafeSymbol()+");"); UpdateNode un=munadd.getUpdate(0); @@ -1096,14 +1203,14 @@ public class RepairGenerator { boolean usageinvimage=rd.testUsage(RelationDescriptor.INVIMAGE); if (inverse) { if (usageimage) - cr.outputline(rd.getSafeSymbol() + "_hash->remove((int)" + rightvar + ", (int)" + leftvar + ");"); + cr.outputline(rd.getSafeSymbol() + "_hash->remove((int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");"); if (usageinvimage) - cr.outputline(rd.getSafeSymbol() + "_hashinv->remove((int)" + leftvar + ", (int)" + rightvar + ");"); + cr.outputline(rd.getSafeSymbol() + "_hashinv->remove((int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");"); } else { if (usageimage) - cr.outputline(rd.getSafeSymbol() + "_hash->remove((int)" + leftvar + ", (int)" + rightvar + ");"); + cr.outputline(rd.getSafeSymbol() + "_hash->remove((int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");"); if (usageinvimage) - cr.outputline(rd.getSafeSymbol() + "_hashinv->remove((int)" + rightvar + ", (int)" + leftvar + ");"); + cr.outputline(rd.getSafeSymbol() + "_hashinv->remove((int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");"); } for(int i=0;iremove((int)" + leftvar + ", (int)" + leftvar + ");"); + cr.outputline(sd.getSafeSymbol() + "_hash->remove((int)" + leftvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");"); for(int i=0;iadd((int)" + rightvar + ", (int)" + leftvar + ");"); + cr.outputline(rd.getSafeSymbol() + "_hash->add((int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");"); if (usageinvimage) - cr.outputline(rd.getSafeSymbol() + "_hashinv->add((int)" + leftvar + ", (int)" + rightvar + ");"); + cr.outputline(rd.getSafeSymbol() + "_hashinv->add((int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");"); } else { if (usageimage) - cr.outputline(rd.getSafeSymbol() + "_hash->add((int)" + leftvar + ", (int)" + rightvar + ");"); + cr.outputline(rd.getSafeSymbol() + "_hash->add((int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");"); if (usageinvimage) - cr.outputline(rd.getSafeSymbol() + "_hashinv->add((int)" + rightvar + ", (int)" + leftvar + ");"); + cr.outputline(rd.getSafeSymbol() + "_hashinv->add((int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");"); } UpdateNode un=mun.getUpdate(0); String name=(String)updatenames.get(un); @@ -1169,7 +1276,7 @@ public class RepairGenerator { } } else { SetDescriptor sd=ip.setexpr.sd; - cr.outputline(sd.getSafeSymbol() + "_hash->add((int)" + leftvar + ", (int)" + leftvar + ");"); + cr.outputline(sd.getSafeSymbol() + "_hash->add((int)" + leftvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");"); UpdateNode un=mun.getUpdate(0); /* Update for rule rule r */ @@ -1179,8 +1286,6 @@ public class RepairGenerator { } } - - public static Vector getrulelist(Descriptor d) { Vector dispatchrules = new Vector(); Vector rules = State.currentState.vRules; @@ -1201,6 +1306,8 @@ public class RepairGenerator { } 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(); @@ -1242,97 +1349,146 @@ public class RepairGenerator { 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 funptr=VarDescriptor.makeNew("updateptr"); - String parttype=""; - for(int i=0;igetrelation("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");"); - String methodcall="("+funptr.getSafeSymbol()+") (this,"+oldmodel.getSafeSymbol()+","+repairtable.getSafeSymbol(); - for(int i=0;icontainsrelation("+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;igetrelation("+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;"); } - methodcall+=");"; - cr.outputline(methodcall); - cr.outputline(goodflag.getSafeSymbol()+"=0;"); - cr.outputline("continue;"); - } - 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;iadd((int)" + leftvar + ", (int)" + rightvar + ");"); + 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 + ");"); } - cr.outputline("if (" + addeditem + ")"); - cr.startblock(); Vector dispatchrules = getrulelist(rd); + Set toremove=new HashSet(); + for(int i=0;i"+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;igetset("+sd.getNum()+","+currentrule.getNum()+","+setvar+");"); - String methodcall="("+funptr.getSafeSymbol()+") (this,"+oldmodel.getSafeSymbol()+","+ - repairtable.getSafeSymbol(); - for(int i=0;icontainsset("+sd.getNum()+","+currentrule.getNum()+","+setvar+"))"); + cr.startblock(); { + /* Have update to call into */ + VarDescriptor funptr=VarDescriptor.makeNew("updateptr"); + String parttype=""; + for(int i=0;igetset("+sd.getNum()+","+currentrule.getNum()+","+setvar+");"); + String methodcall="("+funptr.getSafeSymbol()+") (this,"+oldmodel.getSafeSymbol()+","+ + repairtable.getSafeSymbol(); + for(int i=0;iadd((int)" + setvar + ", (int)" + setvar + ");"); cr.startblock(); Vector dispatchrules = getrulelist(sd); + Set toremove=new HashSet(); + for(int i=0;i