From 58b2f949f1caa909924f56bcecb7f13270de4e27 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Wed, 27 Oct 2004 21:04:25 +0000 Subject: [PATCH] Generate code to compute the sum. Bug fix for adding tuples of integers to a relation. --- .../MCC/IR/RepairGenerator.java | 184 +++++++++--------- Repair/RepairCompiler/MCC/IR/SumExpr.java | 14 +- Repair/RepairCompiler/MCC/Makefile | 7 +- 3 files changed, 105 insertions(+), 100 deletions(-) diff --git a/Repair/RepairCompiler/MCC/IR/RepairGenerator.java b/Repair/RepairCompiler/MCC/IR/RepairGenerator.java index 06252cd..bba7b78 100755 --- a/Repair/RepairCompiler/MCC/IR/RepairGenerator.java +++ b/Repair/RepairCompiler/MCC/IR/RepairGenerator.java @@ -120,8 +120,8 @@ public class RepairGenerator { 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->"; @@ -141,7 +141,7 @@ public class RepairGenerator { for (int i=0;iaddParent(" + 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();"); @@ -447,7 +447,7 @@ public class RepairGenerator { if (relation.testUsage(RelationDescriptor.INVIMAGE)) { crhead.outputline("SimpleHash* " + relation.getSafeSymbol() + "_hashinv;"); craux.outputline(relation.getSafeSymbol() + "_hashinv = new SimpleHash();"); - } + } } craux.outputline("}"); @@ -457,27 +457,27 @@ public class RepairGenerator { /* 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;"); - } - + } + /* 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;"); } if (relation.testUsage(RelationDescriptor.INVIMAGE)) { craux.outputline("delete " + relation.getSafeSymbol() + "_hashinv;"); - } + } } craux.outputline("}"); } @@ -496,7 +496,7 @@ public class RepairGenerator { craux.outputline("int rebuildcount;"); craux.outputline("int abstractcount;"); } - + crhead.outputline("void doanalysis();"); craux.outputline("void "+name +"_state::doanalysis()"); craux.startblock(); @@ -525,9 +525,9 @@ public class RepairGenerator { 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);"); @@ -543,7 +543,7 @@ public class RepairGenerator { } private void generate_print() { - + final SymbolTable st = new SymbolTable(); CodeWriter cr = new StandardCodeWriter(outputaux) { @@ -577,7 +577,7 @@ public class RepairGenerator { 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.outputline("printf(\"<%d> \", __setval);"); } @@ -597,7 +597,7 @@ public class RepairGenerator { for(int sccindex=0;sccindexgetid();"); - + 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(); @@ -718,41 +718,41 @@ public class RepairGenerator { 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;jgetrelation("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");"); cr.outputline("if ("+ismdfyptr.getSafeSymbol()+")"); @@ -1597,7 +1597,7 @@ public class RepairGenerator { cr.outputline("goto rebuild;"); } cr.endblock(); - + /* Build standard compensation actions */ if (need_compensation(currentrule)) { UpdateNode un=find_compensation(currentrule); @@ -1630,19 +1630,13 @@ public class RepairGenerator { String addeditem = (VarDescriptor.makeNew("addeditem")).getSafeSymbol(); cr.outputline("int " + addeditem + "=0;"); - String ifstring="if (!maybe&&"; - boolean dogenerate=false; + String ifstring="if (!maybe"; if (rd.getDomain().getType() instanceof StructureTypeDescriptor) { - dogenerate=true; - ifstring+=leftvar; + ifstring+="&&"+leftvar; } if (rd.getRange().getType() instanceof StructureTypeDescriptor) { - if (dogenerate) - ifstring+="&&"+rightvar; - else - ifstring+=rightvar; - dogenerate=true; + ifstring+="&&"+rightvar; } ifstring+=")"; @@ -1651,15 +1645,15 @@ public class RepairGenerator { 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(); for(int i=0;iiterator("+itvd.getSafeSymbol()+");"); + writer.outputline("while ("+itvd.getSafeSymbol()+".hasNext()) {"); + VarDescriptor keyvd=VarDescriptor.makeNew("key"); + writer.outputline("int "+keyvd.getSafeSymbol()+"="+itvd.getSafeSymbol()+".next();"); + VarDescriptor tmpvar=VarDescriptor.makeNew("tmp"); + writer.outputline("int "+tmpvar.getSafeSymbol()+";"); + writer.outputline(rd.getSafeSymbol()+ "_hash->get("+keyvd.getSafeSymbol()+","+tmpvar.getSafeSymbol()+");"); + writer.outputline(dest.getSafeSymbol()+"+="+tmpvar.getSafeSymbol()+";"); + writer.outputline("}"); } public void prettyPrint(PrettyPrinter pp) { diff --git a/Repair/RepairCompiler/MCC/Makefile b/Repair/RepairCompiler/MCC/Makefile index 61e22b4..163f90c 100755 --- a/Repair/RepairCompiler/MCC/Makefile +++ b/Repair/RepairCompiler/MCC/Makefile @@ -42,7 +42,7 @@ IR/ForQuantifier.class IR/GraphNode.class IR/DependencyBuilder.class \ IR/RelationInclusion.class IR/SetInclusion.class IR/TupleOfExpr.class \ IR/ElementOfExpr.class IR/Rule.class IR/Inclusion.class \ IR/CodeWriter.class IR/SymbolTableStack.class \ -IR/StandardCodeWriter.class \ +IR/StandardCodeWriter.class IR/SumExpr.class \ IR/WorkList.class \ IR/RepairGenerator.class IR/AbstractInterferes.class \ IR/PrettyPrinter.class IR/AbstractRepair.class IR/Quantifiers.class \ @@ -67,7 +67,7 @@ ALLJAVA = *.java IR/*.java .PHONY: java clean all tests javadoc -all: $(TARGET).tar.gz $(TARGET).jar +all: $(TARGET).tar.gz $(TARGET).jar tests: $(TARGET).tar.gz $(TARGET).jar # ./tests.pl scanner @@ -75,7 +75,7 @@ tests: $(TARGET).tar.gz $(TARGET).jar $(TARGET).tar.gz: $(TARGET).tar gzip $(TARGET).tar -c > $(TARGET).tar.gz -$(TARGET).tar: $(ALLJAVA) Makefile $(SCANNER).lex +$(TARGET).tar: $(ALLJAVA) Makefile $(SCANNER).lex tar cf $@ $(ALLJAVA) Makefile $(SCANNER).lex $(TARGET).jar: java @@ -109,4 +109,3 @@ $(SCANNER).java: $(SCANNER).lex.java javadoc: javadoc -source 1.4 -classpath ../ -package -d ../javadoc/ -windowtitle MCC $(ALLJAVA) - -- 2.34.1