Changes to allow unique names
[repair.git] / Repair / RepairCompiler / MCC / IR / RepairGenerator.java
index b0bd167a9adc5dd283532d69ed4141c4c1b75f05..80400dc0a84e4bf56aa941dd58904ebc07b96faf 100755 (executable)
@@ -10,7 +10,8 @@ public class RepairGenerator {
     PrintWrapper outputrepair = null;
     PrintWrapper outputaux = null;
     PrintWrapper outputhead = null;
-    String name="foo";
+    public static String name="foo";
+    public static String postfix="";
     String headername;
     static VarDescriptor oldmodel=null;
     static VarDescriptor newmodel=null;
@@ -57,7 +58,6 @@ public class RepairGenerator {
        }
     }
 
-
     private void name_updates() {
        int count=0;
        for(Iterator it=termination.updatenodes.iterator();it.hasNext();) {
@@ -67,7 +67,7 @@ public class RepairGenerator {
            if (togenerate.contains(gn))
            for (int i=0;i<mun.numUpdates();i++) {
                UpdateNode un=mun.getUpdate(i);
-               String name="update"+String.valueOf(count++);
+               String name="update"+RepairGenerator.name+String.valueOf(count++);
                updatenames.put(un,name);
            }
        }
@@ -275,7 +275,7 @@ public class RepairGenerator {
            cr.outputline(vdstate.getSafeSymbol()+"->"+vd.getSafeSymbol()+"=("+vd.getType().getGenerateType().getSafeSymbol()+")"+vd.getSafeSymbol()+";");
        }
        /* Insert repair here */
-       cr.outputline("doanalysis("+vdstate.getSafeSymbol()+");");
+       cr.outputline("doanalysis"+postfix+"("+vdstate.getSafeSymbol()+");");
        globals=state.stGlobals.descriptors();
        while (globals.hasNext()) {
            VarDescriptor vd=(VarDescriptor) globals.next();
@@ -303,6 +303,7 @@ public class RepairGenerator {
 
     private void generate_stateobject() {
         CodeWriter crhead = new StandardCodeWriter(outputhead);
+        CodeWriter craux = new StandardCodeWriter(outputaux);
        crhead.outputline("struct "+name+"_state {");
        Iterator globals=state.stGlobals.descriptors();
        while (globals.hasNext()) {
@@ -310,6 +311,18 @@ public class RepairGenerator {
            crhead.outputline(vd.getType().getGenerateType().getSafeSymbol()+" "+vd.getSafeSymbol()+";");
        }
         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 *);");
     }
@@ -435,7 +448,7 @@ public class RepairGenerator {
                }
            }
        }
-        craux.outputline("struct "+ name+"* "+name+"()");
+        craux.outputline("struct "+ name+"* allocate"+name+"()");
        craux.startblock();
         craux.outputline("/* creating hashtables */");
 
@@ -481,7 +494,7 @@ public class RepairGenerator {
                 craux.outputline(relation.getSafeSymbol() + "_hashinv = noargallocateSimpleHash();");
             }
         }
-
+        craux.outputline("return thisvar;");
         craux.endblock();
         crhead.outputline("};");
         craux.outputline("void free"+name+"(struct "+ name +"* thisvar)");
@@ -531,10 +544,12 @@ public class RepairGenerator {
            craux.outputline("int abstractcount;");
        }
 
-       crhead.outputline("void doanalysis(struct "+name+"_state *);");
-       craux.outputline("void doanalysis(struct "+name+"_state * thisvar)");
+       crhead.outputline("void doanalysis"+postfix+"(struct "+name+"_state *);");
+       craux.outputline("void doanalysis"+postfix+"(struct "+name+"_state * thisvar)");
        craux.startblock();
+       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);");
@@ -544,7 +559,7 @@ public class RepairGenerator {
            craux.outputline("rebuildcount=0;");
            craux.outputline("abstractcount=0;");
        }
-       craux.addDeclaration("int","highmark");
+
 
        craux.addDeclaration("struct "+name+ " * ",oldmodel.getSafeSymbol());
        craux.outputline(oldmodel.getSafeSymbol()+"=0;");
@@ -624,6 +639,51 @@ public class RepairGenerator {
            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("/* 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);");
+
+                cr.outputline("printf(\"<%ld,%ld> \", __relval2,__relval);");
+
+                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);");
+
+                cr.endblock();
+                cr.endblock();
+            }
+
+       }
+
        cr.outputline("printf(\"\\n\\n------------------- END PRINTING\\n\");");
     }