X-Git-Url: http://plrg.eecs.uci.edu/git/?p=repair.git;a=blobdiff_plain;f=Repair%2FRepairCompiler%2FMCC%2FIR%2FRepairGenerator.java;h=80400dc0a84e4bf56aa941dd58904ebc07b96faf;hp=52631d473d6c9928308901a7e2f6170e189d6e02;hb=e8e7caf9f4a4e0c49fdfe97fc529703ebd8a4d8c;hpb=0b318afaec69dfabbaf366bd49dc7fa66c7befbf diff --git a/Repair/RepairCompiler/MCC/IR/RepairGenerator.java b/Repair/RepairCompiler/MCC/IR/RepairGenerator.java index 52631d4..80400dc 100755 --- a/Repair/RepairCompiler/MCC/IR/RepairGenerator.java +++ b/Repair/RepairCompiler/MCC/IR/RepairGenerator.java @@ -3,13 +3,15 @@ package MCC.IR; import java.io.*; import java.util.*; import MCC.State; +import MCC.Compiler; public class RepairGenerator { State state; - java.io.PrintWriter outputrepair = null; - java.io.PrintWriter outputaux = null; - java.io.PrintWriter outputhead = null; - String name="foo"; + PrintWrapper outputrepair = null; + PrintWrapper outputaux = null; + PrintWrapper outputhead = null; + public static String name="foo"; + public static String postfix=""; String headername; static VarDescriptor oldmodel=null; static VarDescriptor newmodel=null; @@ -24,7 +26,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 +36,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; } @@ -55,7 +58,6 @@ public class RepairGenerator { } } - private void name_updates() { int count=0; for(Iterator it=termination.updatenodes.iterator();it.hasNext();) { @@ -65,31 +67,53 @@ public class RepairGenerator { if (togenerate.contains(gn)) for (int i=0;i"+vd.getSafeSymbol()); + } + + 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("}"); + craux = new StandardCodeWriter(this.outputaux); + craux.emptyBuffer(); + craux.endblock(); + + if (Compiler.GENERATEDEBUGHOOKS) { + crhead.outputline("void debughook();"); + craux.outputline("void debughook() {}"); + } generatetypechecks(false); generate_computesizes(); generatetypechecks(true); @@ -106,16 +130,20 @@ 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); + CodeWriter crhead = new StandardCodeWriter(outputhead); + CodeWriter craux = new StandardCodeWriter(outputaux); + RelationDescriptor.prefix = "model->"; + SetDescriptor.prefix = "model->"; /* Rewrite globals */ for (Iterator it=this.state.stGlobals.descriptors();it.hasNext();) { VarDescriptor vd=(VarDescriptor)it.next(); + craux.outputline("#undef "+vd.getSafeSymbol()); craux.outputline("#define "+vd.getSafeSymbol()+" "+ststate+"->"+vd.getSafeSymbol()); } @@ -128,29 +156,35 @@ public class RepairGenerator { for (int i=0;i"+vd.getSafeSymbol()+"=("+vd.getType().getGenerateType().getSafeSymbol()+")"+vd.getSafeSymbol()+";"); } /* Insert repair here */ - cr.outputline(vdstate.getSafeSymbol()+"->doanalysis();"); + cr.outputline("doanalysis"+postfix+"("+vdstate.getSafeSymbol()+");"); globals=state.stGlobals.descriptors(); while (globals.hasNext()) { VarDescriptor vd=(VarDescriptor) globals.next(); cr.outputline("*(("+vd.getType().getGenerateType().getSafeSymbol()+"*) &"+vd.getSafeSymbol()+")="+vdstate.getSafeSymbol()+"->"+vd.getSafeSymbol()+";"); } - cr.outputline("delete "+vdstate.getSafeSymbol()+";"); + cr.outputline("free"+name+"_state("+vdstate.getSafeSymbol()+");"); } private void generate_tokentable() { - CodeWriter cr = new StandardCodeWriter(outputrepair); - Iterator tokens = TokenLiteralExpr.tokens.keySet().iterator(); + CodeWriter cr = new StandardCodeWriter(outputrepair); + Iterator tokens = TokenLiteralExpr.tokens.keySet().iterator(); cr.outputline(""); - cr.outputline("// Token values"); + cr.outputline("/* Token values*/"); cr.outputline(""); while (tokens.hasNext()) { Object token = tokens.next(); - cr.outputline("// " + token.toString() + " = " + TokenLiteralExpr.tokens.get(token).toString()); + cr.outputline("/* " + token.toString() + " = " + TokenLiteralExpr.tokens.get(token).toString()+"*/"); } cr.outputline(""); @@ -225,15 +303,28 @@ public class RepairGenerator { private void generate_stateobject() { CodeWriter crhead = new StandardCodeWriter(outputhead); - crhead.outputline("class "+name+"_state {"); - crhead.outputline("public:"); + CodeWriter craux = new StandardCodeWriter(outputaux); + crhead.outputline("struct "+name+"_state {"); Iterator globals=state.stGlobals.descriptors(); while (globals.hasNext()) { VarDescriptor vd=(VarDescriptor) globals.next(); crhead.outputline(vd.getType().getGenerateType().getSafeSymbol()+" "+vd.getSafeSymbol()+";"); } - crhead.outputline("void computesizes(int *,int **);"); - crhead.outputline("void recomputesizes();"); + crhead.outputline("};"); + crhead.outputline("struct "+name+"_state * allocate"+name+"_state();"); + craux.outputline("struct "+name+"_state * allocate"+name+"_state()"); + craux.startblock(); + craux.outputline("return (struct "+name+"_state *) malloc(sizeof(struct "+name+"_state));"); + craux.endblock(); + + crhead.outputline("void free"+name+"_state(struct "+name+"_state *);"); + craux.outputline("void free"+name+"_state(struct "+name+"_state * thisvar)"); + craux.startblock(); + craux.outputline("free(thisvar);"); + craux.endblock(); + + crhead.outputline("void "+name+"_statecomputesizes(struct "+name+"_state * ,int *,int **);"); + crhead.outputline("void "+name+"_staterecomputesizes(struct "+name+"_state *);"); } private void generate_computesizes() { @@ -243,8 +334,16 @@ public class RepairGenerator { TypeDescriptor ttd=(TypeDescriptor)it.next(); tdarray[ttd.getId()]=ttd; } - CodeWriter cr=new StandardCodeWriter(outputaux); - cr.outputline("void "+name+"_state::computesizes(int *sizearray,int **numele) {"); + final SymbolTable st = state.stGlobals; + CodeWriter cr = new StandardCodeWriter(outputaux) { + public SymbolTable getSymbolTable() { return st; } + }; + + cr.outputline("void "+name+"_statecomputesizes(struct "+name+"_state * thisvar,int *sizearray,int **numele)"); + cr.startblock(); + cr.startBuffer(); + cr.addDeclaration("int","maybe"); + cr.outputline("maybe=0;"); for(int i=0;i"); crhead.outputline("#include "); - crhead.outputline("class "+name+" {"); - crhead.outputline("public:"); - crhead.outputline(name+"();"); - crhead.outputline("~"+name+"();"); + crhead.outputline("struct "+name+" * allocate"+name+"();"); + crhead.outputline("void free"+name+"(struct "+name+" *);"); + crhead.outputline("struct "+name+" {"); craux.outputline("#include \""+headername+"\""); craux.outputline("#include \"size.h\""); + if (Compiler.TIME) { + craux.outputline("#include "); + } + if (Compiler.ALLOCATECPLUSPLUS) { + for(Iterator it=state.stTypes.descriptors();it.hasNext();) { + TypeDescriptor td=(TypeDescriptor)it.next(); + if (td instanceof StructureTypeDescriptor) { + if (((StructureTypeDescriptor)td).size()>0) { + FieldDescriptor fd=((StructureTypeDescriptor)td).get(0); + if (fd.getSymbol().startsWith("_vptr_")) { + String vtable="_ZTV"; + vtable+=td.getSymbol().length(); + vtable+=td.getSymbol(); + craux.outputline("extern void * "+vtable+";"); + } + } + } + } + } + craux.outputline("struct "+ name+"* allocate"+name+"()"); + craux.startblock(); + craux.outputline("/* creating hashtables */"); - craux.outputline(name+"::"+name+"() {"); - craux.outputline("// creating hashtables "); - /* build sets */ Iterator sets = state.stSets.descriptors(); - + craux.addDeclaration("struct "+name+"*", "thisvar"); + craux.outputline("thisvar=(struct "+name+"*) malloc(sizeof(struct "+name+"));"); + /* first pass create all the hash tables */ while (sets.hasNext()) { SetDescriptor set = (SetDescriptor) sets.next(); - crhead.outputline("SimpleHash* " + set.getSafeSymbol() + "_hash;"); - craux.outputline(set.getSafeSymbol() + "_hash = new SimpleHash();"); + crhead.outputline("struct SimpleHash* " + set.getJustSafeSymbol() + "_hash;"); + craux.outputline(set.getSafeSymbol() + "_hash = noargallocateSimpleHash();"); } - + /* 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(); - craux.outputline(subset.getSafeSymbol() + "_hash->addParent(" + set.getSafeSymbol() + "_hash);"); + SetDescriptor subset = (SetDescriptor) subsets.next(); + craux.outputline("SimpleHashaddParent("+subset.getSafeSymbol() +"_hash ,"+ 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)) { - crhead.outputline("SimpleHash* " + relation.getSafeSymbol() + "_hash;"); - craux.outputline(relation.getSafeSymbol() + "_hash = new SimpleHash();"); + crhead.outputline("struct SimpleHash* " + relation.getJustSafeSymbol() + "_hash;"); + craux.outputline(relation.getSafeSymbol() + "_hash = noargallocateSimpleHash();"); } if (relation.testUsage(RelationDescriptor.INVIMAGE)) { - crhead.outputline("SimpleHash* " + relation.getSafeSymbol() + "_hashinv;"); - craux.outputline(relation.getSafeSymbol() + "_hashinv = new SimpleHash();"); - } + crhead.outputline("struct SimpleHash* " + relation.getJustSafeSymbol() + "_hashinv;"); + craux.outputline(relation.getSafeSymbol() + "_hashinv = noargallocateSimpleHash();"); + } } - - craux.outputline("}"); + craux.outputline("return thisvar;"); + craux.endblock(); crhead.outputline("};"); - craux.outputline(name+"::~"+name+"() {"); - craux.outputline("// deleting hashtables"); + craux.outputline("void free"+name+"(struct "+ name +"* thisvar)"); + craux.startblock(); + craux.outputline("/* deleting hashtables */"); /* build destructor */ sets = state.stSets.descriptors(); - + /* first pass create all the hash tables */ while (sets.hasNext()) { SetDescriptor set = (SetDescriptor) sets.next(); - craux.outputline("delete "+set.getSafeSymbol() + "_hash;"); - } - + craux.outputline("freeSimpleHash("+set.getSafeSymbol() + "_hash);"); + } + /* destroy relations */ relations = state.stRelations.descriptors(); - + /* first pass create all the hash tables */ while (relations.hasNext()) { RelationDescriptor relation = (RelationDescriptor) relations.next(); - + if (relation.testUsage(RelationDescriptor.IMAGE)) { - craux.outputline("delete "+relation.getSafeSymbol() + "_hash;"); + craux.outputline("freeSimpleHash("+relation.getSafeSymbol() + "_hash);"); } if (relation.testUsage(RelationDescriptor.INVIMAGE)) { - craux.outputline("delete " + relation.getSafeSymbol() + ";"); - } + craux.outputline("freeSimpleHash(" + relation.getSafeSymbol() + "_hashinv);"); + } } - craux.outputline("}"); + craux.outputline("free(thisvar);"); + craux.endblock(); } - private void generate_worklist() { + private void generate_start() { CodeWriter crhead = new StandardCodeWriter(outputhead); CodeWriter craux = new StandardCodeWriter(outputaux); oldmodel=VarDescriptor.makeNew("oldmodel"); @@ -407,178 +537,345 @@ public class RepairGenerator { worklist=VarDescriptor.makeNew("worklist"); goodflag=VarDescriptor.makeNew("goodflag"); repairtable=VarDescriptor.makeNew("repairtable"); - crhead.outputline("void doanalysis();"); - craux.outputline("void "+name +"_state::doanalysis()"); + + if (Compiler.GENERATEINSTRUMENT) { + craux.outputline("int updatecount;"); + craux.outputline("int rebuildcount;"); + craux.outputline("int abstractcount;"); + } + + crhead.outputline("void doanalysis"+postfix+"(struct "+name+"_state *);"); + craux.outputline("void doanalysis"+postfix+"(struct "+name+"_state * thisvar)"); craux.startblock(); - craux.outputline("int highmark;"); + craux.outputline("int highmark;"); /* This declaration is special...need it to be first */ + craux.startBuffer(); + + if (Compiler.TIME) { + craux.outputline("struct timeval _begin_time,_end_time;"); + craux.outputline("gettimeofday(&_begin_time,NULL);"); + } + if (Compiler.GENERATEINSTRUMENT) { + craux.outputline("updatecount=0;"); + craux.outputline("rebuildcount=0;"); + craux.outputline("abstractcount=0;"); + } + + + craux.addDeclaration("struct "+name+ " * ",oldmodel.getSafeSymbol()); + craux.outputline(oldmodel.getSafeSymbol()+"=0;"); + craux.addDeclaration("struct WorkList * ",worklist.getSafeSymbol()); + craux.outputline(worklist.getSafeSymbol()+" = allocateWorkList();"); + craux.addDeclaration("struct RepairHash * ",repairtable.getSafeSymbol()); + craux.outputline(repairtable.getSafeSymbol()+"=0;"); craux.outputline("initializestack(&highmark);"); - craux.outputline("typeobject *typeobject1=gettypeobject();"); - craux.outputline("typeobject1->computesizes(this);"); - craux.outputline("recomputesizes();"); - craux.outputline(name+ " * "+oldmodel.getSafeSymbol()+"=0;"); - craux.outputline("WorkList * "+worklist.getSafeSymbol()+" = new WorkList();"); - craux.outputline("RepairHash * "+repairtable.getSafeSymbol()+"=0;"); + craux.outputline("computesizes(thisvar);"); + craux.outputline(name+"_staterecomputesizes(thisvar);"); craux.outputline("while (1)"); craux.startblock(); - craux.outputline("int "+goodflag.getSafeSymbol()+"=1;"); - craux.outputline(name+ " * "+newmodel.getSafeSymbol()+"=new "+name+"();"); + craux.addDeclaration("struct "+name+ " * ",newmodel.getSafeSymbol()); + craux.outputline(newmodel.getSafeSymbol()+"=allocate"+name+"();"); + craux.outputline("WorkListreset("+worklist.getSafeSymbol()+");"); + if (Compiler.GENERATEINSTRUMENT) + craux.outputline("rebuildcount++;"); } - + private void generate_teardown() { - CodeWriter cr = new StandardCodeWriter(outputaux); + CodeWriter cr = new StandardCodeWriter(outputaux); cr.endblock(); + if (Compiler.TIME) { + cr.outputline("gettimeofday(&_end_time,NULL);"); + cr.outputline("printf(\"time=%ld uS\\n\",(_end_time.tv_sec-_begin_time.tv_sec)*1000000+_end_time.tv_usec-_begin_time.tv_usec);"); + } + + if (Compiler.GENERATEINSTRUMENT) { + cr.outputline("printf(\"updatecount=%d\\n\",updatecount);"); + cr.outputline("printf(\"rebuildcount=%d\\n\",rebuildcount);"); + cr.outputline("printf(\"abstractcount=%d\\n\",abstractcount);"); + } + } - 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 - RelationDescriptor.prefix = newmodel.getSafeSymbol()+"->"; - SetDescriptor.prefix = newmodel.getSafeSymbol()+"->"; + private void generate_print() { - 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())); + 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\", SimpleHashcountset("+setname+"_hash));"); + cr.addDeclaration("struct SimpleIterator","__setiterator"); + cr.outputline("SimpleHashiterator("+setname+"_hash,&__setiterator);"); + cr.outputline("while (hasNext(&__setiterator))"); + cr.startblock(); + cr.addDeclaration("int","__setval"); + cr.outputline("__setval = (int) next(&__setiterator);"); + + 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(); + } + + Iterator reliterator = state.stRelations.descriptors(); + while (reliterator.hasNext()) { + RelationDescriptor rd = (RelationDescriptor) reliterator.next(); + + + String relname = rd.getSafeSymbol(); + if (rd.testUsage(RelationDescriptor.IMAGE)) { cr.startblock(); - cr.outputline("int maybe=0;"); - ListIterator quantifiers = rule.quantifiers(); - while (quantifiers.hasNext()) { - Quantifier quantifier = (Quantifier) quantifiers.next(); - quantifier.generate_open(cr); - } + cr.outputline("/* printing relation " + relname+"*/"); + cr.outputline("printf(\"\\nPrinting relation " + rd.getSymbol() + " - %d elements \\n\", SimpleHashcountset("+relname+"_hash));"); + cr.addDeclaration("struct SimpleIterator","__reliterator"); + cr.outputline("SimpleHashiterator("+relname+"_hash,&__reliterator);"); + cr.outputline("while (hasNext(&__reliterator))"); + cr.startblock(); + cr.addDeclaration("int","__relval"); + cr.addDeclaration("int","__relval2"); + cr.outputline("__relval2 = (int) key(&__reliterator);"); + cr.outputline("__relval = (int) next(&__reliterator);"); - /* pretty print! */ - cr.output("//"); - rule.getGuardExpr().prettyPrint(cr); - cr.outputline(""); + cr.outputline("printf(\"<%ld,%ld> \", __relval2,__relval);"); - /* now we have to generate the guard test */ - VarDescriptor guardval = VarDescriptor.makeNew(); - rule.getGuardExpr().generate(cr, guardval); - cr.outputline("if (" + guardval.getSafeSymbol() + ")"); + cr.endblock(); + cr.endblock(); + } else if (rd.testUsage(RelationDescriptor.INVIMAGE)) { cr.startblock(); + cr.outputline("/* printing inv relation " + relname+"*/"); + cr.outputline("printf(\"\\nPrinting relation using inv" + rd.getSymbol() + " - %d elements \\n\", SimpleHashcountset("+relname+"_hash));"); + cr.addDeclaration("struct SimpleIterator","__reliterator"); + cr.outputline("SimpleHashiterator("+relname+"_hashinv,&__reliterator);"); + cr.outputline("while (hasNext(&__reliterator))"); + cr.startblock(); + cr.addDeclaration("int","__relval"); + cr.addDeclaration("int","__relval2"); + cr.outputline("__relval2 = (int) key(&__reliterator);"); + cr.outputline("__relval = (int) next(&__reliterator);"); + + + cr.outputline("printf(\"<%ld,%ld> \", __relval,__relval2);"); - /* 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(""); } - } - CodeWriter cr2 = new StandardCodeWriter(outputaux); + } - 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"; + cr.outputline("printf(\"\\n\\n------------------- END PRINTING\\n\");"); + } - Iterator iterator_rules = worklistrules.iterator(); - while (iterator_rules.hasNext()) { + Set ruleset=null; + private void generate_rules() { + /* first we must sort the rules */ + RelationDescriptor.prefix = newmodel.getSafeSymbol()+"->"; + SetDescriptor.prefix = newmodel.getSafeSymbol()+"->"; + System.out.println("SCC="+(mrd.numSCC()-1)); + for(int sccindex=0;sccindexgettype();"); - cr.outputline("int "+leftvar.getSafeSymbol()+"="+worklist.getSafeSymbol()+"->getlvalue();"); - cr.outputline("int "+rightvar.getSafeSymbol()+"="+worklist.getSafeSymbol()+"->getrvalue();"); - cr.outputline("// build " +escape(rule.toString())); + /* 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 */ + currentrule=rule; + rule.getInclusion().generate(cr); + cr.endblock(); + while (quantifiers.hasPrevious()) { + Quantifier quantifier = (Quantifier) quantifiers.previous(); + cr.endblock(); + } + cr.endblock(); + while((openparencount--)>0) + cr.endblock(); + cr.outputline(""); + cr.outputline(""); + } + } + } else { + CodeWriter cr2 = new StandardCodeWriter(outputaux); - for (int j=0;jpop();"); - cr2.endblock(); + 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("WorkListpop("+worklist.getSafeSymbol()+");"); + cr2.endblock(); + } + } } public static String escape(String s) { @@ -594,73 +891,82 @@ public class RepairGenerator { } 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); + Iterator i; + if (Compiler.REPAIR) + i=termination.constraintdependence.computeOrdering().iterator(); + else + i=state.vConstraints.iterator(); + for (; i.hasNext();) { + Constraint constraint; + if (Compiler.REPAIR) + constraint= (Constraint) ((GraphNode)i.next()).getOwner(); + else + constraint=(Constraint)i.next(); { + 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.addDeclaration("int","maybe"); + cr.outputline("maybe = 0;"); - 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("printf(\"maybe fail " + escape(constraint.toString()) + ". \");"); - cr.outputline("exit(1);"); + 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();"); + cr.outputline("freeRepairHash("+repairtable.getSafeSymbol()+");"); + cr.outputline(repairtable.getSafeSymbol()+"=noargallocateRepairHash();"); - + 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.addDeclaration("int",mincostindex.getSafeSymbol()); + cr.outputline(mincostindex.getSafeSymbol()+"=0;"); } if (dnfconst.size()>1) { - cr.outputline("int "+mincostindex.getSafeSymbol()+";"); + cr.addDeclaration("int",mincostindex.getSafeSymbol()); boolean first=true; for(int j=0;jget("+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+");"); + cr.addDeclaration(rd.getRange().getType().getGenerateType().getSafeSymbol(),rightside.getSafeSymbol()); + cr.outputline("SimpleHashget("+rd.getSafeSymbol()+"_hash,"+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("SimpleHashget("+rd.getSafeSymbol()+"_hashinv,"+rightside.getSafeSymbol()+", &"+leftside.getSafeSymbol()+");"); } - 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(negated,opcode); if (opcode==Opcode.GT) { cr.outputline(newvalue.getSafeSymbol()+"++;"); @@ -837,50 +1187,101 @@ 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"); } /* Do abstract repairs */ if (usageimage) { - cr.outputline(rd.getSafeSymbol()+"_hash->remove("+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+");"); + cr.outputline("SimpleHashremove("+rd.getSafeSymbol()+"_hash, "+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+");"); + } + if (usageinvimage) { + cr.outputline("SimpleHashremove("+rd.getSafeSymbol()+"_hashinv, "+rightside.getSafeSymbol()+","+leftside.getSafeSymbol()+");"); + } + + if (needremoveloop) { + if (!inverted) { + cr.outputline("if (SimpleHashcontainskey("+rd.getSafeSymbol()+"_hash, "+leftside.getSafeSymbol()+"))"); + cr.startblock(); + } else { + cr.outputline("if (SimpleHashcontainskey("+rd.getSafeSymbol()+"_hashinv, "+rightside.getSafeSymbol()+"))"); + cr.startblock(); + } + for(int i=0;iadd("+leftside.getSafeSymbol()+","+newvalue.getSafeSymbol()+");"); + cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hash,"+leftside.getSafeSymbol()+","+newvalue.getSafeSymbol()+");"); } else { - cr.outputline(rd.getSafeSymbol()+"_hash->add("+newvalue.getSafeSymbol()+","+rightside.getSafeSymbol()+");"); + cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hash, "+newvalue.getSafeSymbol()+","+rightside.getSafeSymbol()+");"); } } if (usageinvimage) { - cr.outputline(rd.getSafeSymbol()+"_hashinv->remove("+rightside.getSafeSymbol()+","+leftside.getSafeSymbol()+");"); if (!inverted) { - cr.outputline(rd.getSafeSymbol()+"_hashinv->add("+newvalue.getSafeSymbol()+","+leftside.getSafeSymbol()+");"); + cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hashinv, "+newvalue.getSafeSymbol()+","+leftside.getSafeSymbol()+");"); } else { - cr.outputline(rd.getSafeSymbol()+"_hashinv->add("+rightside.getSafeSymbol()+","+newvalue.getSafeSymbol()+");"); + cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hashinv,"+rightside.getSafeSymbol()+","+newvalue.getSafeSymbol()+");"); } } /* 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&&(!ar.mayNeedFunctionEnforcement(state))||(munadd==null)||(ar.needsRemoves(state)&&(munremove==null))) { + for(int i=0;iget((int)"+rightvar.getSafeSymbol()+","+leftvar.getSafeSymbol()+");"); + ((ImageSetExpr)((SizeofExpr)expr.left).setexpr).generate_leftside(cr,rightvar); + cr.addDeclaration("int",leftvar.getSafeSymbol()); + cr.outputline("SimpleHashget("+d.getSafeSymbol()+"_hashinv,(int)"+rightvar.getSafeSymbol()+", &"+leftvar.getSafeSymbol()+");"); } else { - leftvar=((ImageSetExpr)((SizeofExpr)((OpExpr)expr).left).setexpr).getVar(); - cr.outputline("int "+rightvar.getSafeSymbol()+";"); - cr.outputline(d.getSafeSymbol()+"_hash->get((int)"+leftvar.getSafeSymbol()+","+rightvar.getSafeSymbol()+");"); + ((ImageSetExpr)((SizeofExpr)expr.left).setexpr).generate_leftside(cr,leftvar); + cr.addDeclaration("int",rightvar.getSafeSymbol()); + cr.outputline("SimpleHashget("+d.getSafeSymbol()+"_hash ,(int)"+leftvar.getSafeSymbol()+", &"+rightvar.getSafeSymbol()+");"); } } else { - cr.outputline("int "+leftvar.getSafeSymbol()+"="+d.getSafeSymbol()+"_hash->firstkey();"); + cr.addDeclaration("int",leftvar.getSafeSymbol()); + cr.outputline(leftvar.getSafeSymbol()+"= SimpleHashfirstkey("+d.getSafeSymbol()+"_hash);"); } /* Generate abstract remove instruction */ if (d instanceof RelationDescriptor) { @@ -977,25 +1371,25 @@ 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("SimpleHashremove("+rd.getSafeSymbol()+"_hash, (int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");"); if (usageinvimage) - cr.outputline(rd.getSafeSymbol() + "_hashinv->remove((int)" + rightvar + ", (int)" + leftvar + ");"); + cr.outputline("SimpleHashremove("+rd.getSafeSymbol()+"_hashinv ,(int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");"); } else { - cr.outputline(d.getSafeSymbol() + "_hash->remove((int)" + leftvar + ", (int)" + leftvar + ");"); + cr.outputline("SimpleHashremove("+d.getSafeSymbol()+"_hash, (int)" + leftvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");"); } /* Generate concrete remove instruction */ for(int i=0;iaddrelation("+d.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+","+rightvar.getSafeSymbol()+",(int) &"+name+");"); + cr.outputline("RepairHashaddrelation("+repairtable.getSafeSymbol()+","+d.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+","+rightvar.getSafeSymbol()+",(int) &"+name+");"); } else { - cr.outputline(repairtable.getSafeSymbol()+"->addset("+d.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+",(int) &"+name+");"); + cr.outputline("RepairHashaddset("+repairtable.getSafeSymbol()+","+d.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+",(int) &"+name+");"); } } } @@ -1003,77 +1397,87 @@ public class RepairGenerator { } cr.endblock(); } + +// In some cases the analysis has determined that generating removes +// is unnecessary + if (generateadd&&munadd==null) + generateadd=false; + if (generateadd) { cr.outputline("for(;"+change.getSafeSymbol()+">0;"+change.getSafeSymbol()+"--)"); cr.startblock(); VarDescriptor newobject=VarDescriptor.makeNew("newobject"); if (d instanceof RelationDescriptor) { - VarDescriptor otherside=((ImageSetExpr)((SizeofExpr)ep.expr).setexpr).vd; + VarDescriptor otherside=VarDescriptor.makeNew("otherside"); + ((ImageSetExpr)((SizeofExpr)expr.left).setexpr).generate_leftside(cr,otherside); + RelationDescriptor rd=(RelationDescriptor)d; - if (sources.relsetSource(rd,!ep.inverted())) { + if (termination.sources.relsetSource(rd,!ep.inverted())) { /* Set Source */ - SetDescriptor sd=sources.relgetSourceSet(rd,!ep.inverted()); + SetDescriptor sd=termination.sources.relgetSourceSet(rd,!ep.inverted()); VarDescriptor iterator=VarDescriptor.makeNew("iterator"); - cr.outputline(sd.getType().getGenerateType().getSafeSymbol() +" "+newobject.getSafeSymbol()+";"); - cr.outputline("for("+iterator.getSafeSymbol()+"="+sd.getSafeSymbol()+"_hash->iterator();"+iterator.getSafeSymbol()+".hasNext();)"); + cr.addDeclaration(sd.getType().getGenerateType().getSafeSymbol(),newobject.getSafeSymbol()); + cr.addDeclaration("struct SimpleIterator",iterator.getSafeSymbol()); + cr.outputline("for(SimpleHashiterator("+sd.getSafeSymbol()+"_hash , &"+ iterator.getSafeSymbol() +"); hasNext(&"+iterator.getSafeSymbol()+");)"); cr.startblock(); if (ep.inverted()) { - cr.outputline("if !"+rd.getSafeSymbol()+"_hashinv->contains("+iterator.getSafeSymbol()+"->key(),"+otherside.getSafeSymbol()+")"); + cr.outputline("if (!SimpleHashcontainskeydata("+rd.getSafeSymbol()+"_hashinv,"+iterator.getSafeSymbol()+".key(),"+otherside.getSafeSymbol()+"))"); } else { - cr.outputline("if !"+rd.getSafeSymbol()+"_hash->contains("+otherside.getSafeSymbol()+","+iterator.getSafeSymbol()+"->key())"); + cr.outputline("if (!SimpleHashcontainskeydata("+rd.getSafeSymbol()+"_hash, "+otherside.getSafeSymbol()+","+iterator.getSafeSymbol()+".key()))"); } - cr.outputline(newobject.getSafeSymbol()+"="+iterator.getSafeSymbol()+".key();"); - cr.outputline(iterator.getSafeSymbol()+"->next();"); + cr.outputline(newobject.getSafeSymbol()+"=key(&"+iterator.getSafeSymbol()+");"); + cr.outputline("next(&"+iterator.getSafeSymbol()+");"); 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); boolean usageinvimage=rd.testUsage(RelationDescriptor.INVIMAGE); if (usageimage) - cr.outputline(rd.getSafeSymbol()+"_hash->add("+newobject.getSafeSymbol()+","+otherside.getSafeSymbol()+");"); + cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hash, "+newobject.getSafeSymbol()+","+otherside.getSafeSymbol()+");"); if (usageinvimage) - cr.outputline(rd.getSafeSymbol()+"_hashinv->add("+otherside.getSafeSymbol()+","+newobject.getSafeSymbol()+");"); + cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hashinv, "+otherside.getSafeSymbol()+","+newobject.getSafeSymbol()+");"); UpdateNode un=munadd.getUpdate(0); String name=(String)updatenames.get(un); - cr.outputline(name+"(this,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+newobject.getSafeSymbol()+","+otherside.getSafeSymbol()+");"); + cr.outputline(name+"(thisvar,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+newobject.getSafeSymbol()+","+otherside.getSafeSymbol()+");"); } else { boolean usageimage=rd.testUsage(RelationDescriptor.IMAGE); boolean usageinvimage=rd.testUsage(RelationDescriptor.INVIMAGE); if (usageimage) - cr.outputline(rd.getSafeSymbol()+"_hash->add("+otherside.getSafeSymbol()+","+newobject.getSafeSymbol()+");"); + cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hash, "+otherside.getSafeSymbol()+","+newobject.getSafeSymbol()+");"); if (usageinvimage) - cr.outputline(rd.getSafeSymbol()+"_hashinv->add("+newobject.getSafeSymbol()+","+otherside.getSafeSymbol()+");"); + cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hashinv, "+newobject.getSafeSymbol()+","+otherside.getSafeSymbol()+");"); UpdateNode un=munadd.getUpdate(0); String name=(String)updatenames.get(un); - cr.outputline(name+"(this,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+otherside.getSafeSymbol()+","+newobject.getSafeSymbol()+");"); + cr.outputline(name+"(thisvar, "+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+otherside.getSafeSymbol()+","+newobject.getSafeSymbol()+");"); } } 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.addDeclaration(sourcesd.getType().getGenerateType().getSafeSymbol(), newobject.getSafeSymbol()); + cr.addDeclaration("struct SimpleIterator",iterator.getSafeSymbol()); + cr.outputline("for(SimpleHashiterator("+sourcesd.getSafeSymbol()+"_hash, &"+iterator.getSafeSymbol()+"); hasNext(&"+iterator.getSafeSymbol()+");)"); cr.startblock(); - cr.outputline("if !"+sd.getSafeSymbol()+"_hash->contains("+iterator.getSafeSymbol()+"->key())"); - cr.outputline(newobject.getSafeSymbol()+"="+iterator.getSafeSymbol()+".key();"); - cr.outputline(iterator.getSafeSymbol()+"->next();"); + cr.outputline("if (!SimpleHashcontainskey("+sd.getSafeSymbol()+"_hash, key(&"+iterator.getSafeSymbol()+")))"); + cr.outputline(newobject.getSafeSymbol()+"=key(&"+iterator.getSafeSymbol()+");"); + cr.outputline("next(&"+iterator.getSafeSymbol()+");"); 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()+");"); + cr.outputline("SimpleHashadd("+sd.getSafeSymbol()+"_hash, "+newobject.getSafeSymbol()+","+newobject.getSafeSymbol()+");"); UpdateNode un=munadd.getUpdate(0); String name=(String)updatenames.get(un); - cr.outputline(name+"(this,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+newobject.getSafeSymbol()+");"); + cr.outputline(name+"(thisvar,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+newobject.getSafeSymbol()+");"); } cr.endblock(); } @@ -1096,27 +1500,27 @@ 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("SimpleHashremove("+rd.getSafeSymbol()+"_hash, (int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");"); if (usageinvimage) - cr.outputline(rd.getSafeSymbol() + "_hashinv->remove((int)" + leftvar + ", (int)" + rightvar + ");"); + cr.outputline("SimpleHashremove("+rd.getSafeSymbol()+"_hashinv, (int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");"); } else { if (usageimage) - cr.outputline(rd.getSafeSymbol() + "_hash->remove((int)" + leftvar + ", (int)" + rightvar + ");"); + cr.outputline("SimpleHashremove("+rd.getSafeSymbol()+"_hash ,(int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");"); if (usageinvimage) - cr.outputline(rd.getSafeSymbol() + "_hashinv->remove((int)" + rightvar + ", (int)" + leftvar + ");"); + cr.outputline("SimpleHashremove("+rd.getSafeSymbol()+"_hashinv, (int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");"); } for(int i=0;iaddrelation("+rd.getNum()+","+r.getNum()+","+rightvar.getSafeSymbol()+","+leftvar.getSafeSymbol()+",(int) &"+name+");"); + cr.outputline("RepairHashaddrelation("+repairtable.getSafeSymbol()+","+rd.getNum()+","+r.getNum()+","+rightvar.getSafeSymbol()+","+leftvar.getSafeSymbol()+",(int) &"+name+");"); } else { - cr.outputline(repairtable.getSafeSymbol()+"->addrelation("+rd.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+","+rightvar.getSafeSymbol()+",(int) &"+name+");"); + cr.outputline("RepairHashaddrelation("+repairtable.getSafeSymbol()+","+rd.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+","+rightvar.getSafeSymbol()+",(int) &"+name+");"); } } } @@ -1124,17 +1528,17 @@ public class RepairGenerator { } } else { SetDescriptor sd=ip.setexpr.sd; - cr.outputline(sd.getSafeSymbol() + "_hash->remove((int)" + leftvar + ", (int)" + leftvar + ");"); + cr.outputline("SimpleHashremove("+sd.getSafeSymbol()+"_hash, (int)" + leftvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");"); for(int i=0;iaddset("+sd.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+",(int) &"+name+");"); + cr.outputline("RepairHashaddset("+repairtable.getSafeSymbol()+","+sd.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+",(int) &"+name+");"); } } } @@ -1151,36 +1555,34 @@ public class RepairGenerator { boolean usageinvimage=rd.testUsage(RelationDescriptor.INVIMAGE); if (inverse) { if (usageimage) - cr.outputline(rd.getSafeSymbol() + "_hash->add((int)" + rightvar + ", (int)" + leftvar + ");"); + cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hash, (int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");"); if (usageinvimage) - cr.outputline(rd.getSafeSymbol() + "_hashinv->add((int)" + leftvar + ", (int)" + rightvar + ");"); + cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hashinv, (int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");"); } else { if (usageimage) - cr.outputline(rd.getSafeSymbol() + "_hash->add((int)" + leftvar + ", (int)" + rightvar + ");"); + cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hash, (int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");"); if (usageinvimage) - cr.outputline(rd.getSafeSymbol() + "_hashinv->add((int)" + rightvar + ", (int)" + leftvar + ");"); + cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hashinv, (int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");"); } UpdateNode un=mun.getUpdate(0); String name=(String)updatenames.get(un); if (inverse) { - cr.outputline(name+"(this,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+rightvar.getSafeSymbol()+","+leftvar.getSafeSymbol()+");"); + cr.outputline(name+"(thisvar,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+rightvar.getSafeSymbol()+","+leftvar.getSafeSymbol()+");"); } else { - cr.outputline(name+"(this,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+leftvar.getSafeSymbol()+","+rightvar.getSafeSymbol()+");"); + cr.outputline(name+"(thisvar,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+leftvar.getSafeSymbol()+","+rightvar.getSafeSymbol()+");"); } } else { SetDescriptor sd=ip.setexpr.sd; - cr.outputline(sd.getSafeSymbol() + "_hash->add((int)" + leftvar + ", (int)" + leftvar + ");"); + cr.outputline("SimpleHashadd("+sd.getSafeSymbol()+"_hash, (int)" + leftvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");"); UpdateNode un=mun.getUpdate(0); /* Update for rule rule r */ String name=(String)updatenames.get(un); - cr.outputline(name+"(this,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+leftvar.getSafeSymbol()+");"); + cr.outputline(name+"(thisvar,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+leftvar.getSafeSymbol()+");"); } } } - - public static Vector getrulelist(Descriptor d) { Vector dispatchrules = new Vector(); Vector rules = State.currentState.vRules; @@ -1188,7 +1590,7 @@ public class RepairGenerator { 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... @@ -1201,6 +1603,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(); @@ -1241,220 +1645,319 @@ public class RepairGenerator { if (!(usageinvimage||usageimage)) /* not used at all*/ 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+"))"); + cr.outputline("/* RELATION DISPATCH */"); + if (Compiler.REPAIR) { + cr.outputline("if ("+oldmodel.getSafeSymbol()+"&&"); + if (usageimage) + cr.outputline("!SimpleHashcontainskeydata("+oldmodel.getSafeSymbol()+"->"+rd.getJustSafeSymbol() + "_hash, "+leftvar+","+rightvar+"))"); + else + cr.outputline("!SimpleHashcontainskeydata("+oldmodel.getSafeSymbol() +"->"+rd.getJustSafeSymbol()+"_hashinv, "+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;iadd((int)" + leftvar + ", (int)" + rightvar + ");"); + cr.outputline(ifstring); + cr.outputline(addeditem + " = SimpleHashadd("+rd.getSafeSymbol()+"_hash, (int)" + leftvar + ", (int)" + rightvar+ ");"); } - + if (rd.testUsage(RelationDescriptor.INVIMAGE)) { - cr.outputline(addeditem + " = " + rd.getSafeSymbol() + "_hashinv->add((int)" + rightvar + ", (int)" + leftvar + ");"); + cr.outputline(ifstring); + cr.outputline(addeditem + " = SimpleHashadd("+rd.getSafeSymbol()+"_hashinv, (int)" + rightvar + ", (int)" + leftvar + ");"); } - - cr.outputline("if (" + addeditem + ")"); - cr.startblock(); + Vector dispatchrules = getrulelist(rd); - + + Set toremove=new HashSet(); + for(int i=0;iadd("+rule.getNum()+",-1,0,0);"); + cr.outputline("WorkListadd("+worklist.getSafeSymbol()+","+rule.getNum()+",-1,0,0);"); } else { for (int j=0;jadd("+rule.getNum()+","+j+","+leftvar+","+rightvar+");"); + cr.outputline("WorkListadd("+worklist.getSafeSymbol()+","+rule.getNum()+","+j+","+leftvar+","+rightvar+");"); } } } } + 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+"))"); + cr.outputline("/* SET DISPATCH */"); + if (Compiler.REPAIR) { + cr.outputline("if ("+oldmodel.getSafeSymbol()+"&&"); + cr.outputline("!SimpleHashcontainskey("+oldmodel.getSafeSymbol() +"->"+sd.getJustSafeSymbol()+"_hash, "+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;i"+sdrule.getJustSafeSymbol() +"_hash,"+setvar+"))"); + cr.startblock(); + } + cr.outputline(methodcall); + cr.outputline("free"+name+"("+newmodel.getSafeSymbol()+");"); + cr.outputline("goto rebuild;"); + cr.endblock(); } + if (currentrule==itrule) + cr.endblock(); } - methodcall+=");"; - cr.outputline(methodcall); - cr.outputline(goodflag.getSafeSymbol()+"=0;"); - cr.outputline("continue;"); } } - cr.endblock(); + cr.startblock(); String addeditem = (VarDescriptor.makeNew("addeditem")).getSafeSymbol(); - cr.outputline("int " + addeditem + " = 1;"); - cr.outputline(addeditem + " = " + sd.getSafeSymbol() + "_hash->add((int)" + setvar + ", (int)" + setvar + ");"); + cr.addDeclaration("int", addeditem); + cr.outputline(addeditem + " = 0;"); + if (sd.getType() instanceof StructureTypeDescriptor) { + cr.outputline("if (!maybe&&"+setvar+")"); + } else + cr.outputline("if (!maybe)"); + cr.outputline(addeditem + " = SimpleHashadd("+sd.getSafeSymbol()+"_hash, (int)" + setvar + ", (int)" + setvar + ");"); cr.startblock(); Vector dispatchrules = getrulelist(sd); + Set toremove=new HashSet(); + for(int i=0;iadd("+rule.getNum()+",-1,0,0);"); + cr.outputline("WorkListadd("+worklist.getSafeSymbol()+","+rule.getNum()+",-1,0,0);"); } else { for (int j=0;jadd("+rule.getNum()+","+j+","+setvar+",0);"); + cr.outputline("WorkListadd("+worklist.getSafeSymbol()+","+rule.getNum()+","+j+","+setvar+",0);"); } } } } cr.endblock(); + cr.endblock(); + cr.endblock(); } }