Creating a runtime directory...
[repair.git] / Repair / RepairCompiler / MCC / IR / RepairGenerator.java
index bcf68f565730a2ee8e62c1bddbeaf869ba1b111e..db37cdeae089742a51b41b9c5509fff833bb24c5 100755 (executable)
@@ -75,19 +75,28 @@ public class RepairGenerator {
        CodeWriter crhead = new StandardCodeWriter(this.outputhead);
        CodeWriter craux = new StandardCodeWriter(this.outputaux);
        crhead.outputline("};");
-       craux.outputline("};");
+       craux.outputline("}");
        generate_updates();
     }
 
+    String ststate="state";
+    String stmodel="model";
+    String strepairtable="repairtable";
+    String stleft="left";
+    String stright="right";
+
     private void generate_updates() {
        int count=0;
         CodeWriter crhead = new StandardCodeWriter(outputhead);        
         CodeWriter craux = new StandardCodeWriter(outputaux);        
-       String state="state";
-       String model="model";
-       String repairtable="repairtable";
-       String left="left";
-       String right="right";
+
+       /* Rewrite globals */
+
+       for (Iterator it=this.state.stGlobals.descriptors();it.hasNext();) {
+           VarDescriptor vd=(VarDescriptor)it.next();
+           craux.outputline("#define "+vd.getSafeSymbol()+" "+ststate+"->"+vd.getSafeSymbol());
+       }
+
        for(Iterator it=termination.updatenodes.iterator();it.hasNext();) {
            GraphNode gn=(GraphNode) it.next();
            TermNode tn=(TermNode) gn.getOwner();
@@ -101,19 +110,23 @@ public class RepairGenerator {
                switch(mun.op) {
                case MultUpdateNode.ADD:
                    if (isrelation) {
-                       crhead.outputline("void "+methodname+"("+name+"_state * " +state+","+name+" * "+model+", RepairHash * "+repairtable+", int "+left+", int "+right+");");
-                       craux.outputline("void "+methodname+"("+name+"_state * "+ state+","+name+" * "+model+", RepairHash * "+repairtable+", int "+left+", int "+right+")");
+                       crhead.outputline("void "+methodname+"("+name+"_state * " +ststate+","+name+" * "+stmodel+", RepairHash * "+strepairtable+", int "+stleft+", int "+stright+");");
+                       craux.outputline("void "+methodname+"("+name+"_state * "+ ststate+","+name+" * "+stmodel+", RepairHash * "+strepairtable+", int "+stleft+", int "+stright+")");
                    } else {
-                       crhead.outputline("void "+methodname+"("+name+"_state * "+ state+","+name+" * "+model+", RepairHash * "+repairtable+", int "+left+");");
-                       craux.outputline("void "+methodname+"("+name+"_state * "+state+","+name+" * "+model+", RepairHash * "+repairtable+", int "+left+")");
+                       crhead.outputline("void "+methodname+"("+name+"_state * "+ ststate+","+name+" * "+stmodel+", RepairHash * "+strepairtable+", int "+stleft+");");
+                       craux.outputline("void "+methodname+"("+name+"_state * "+ststate+","+name+" * "+stmodel+", RepairHash * "+strepairtable+", int "+stleft+")");
                    }
                    craux.startblock();
-                   un.generate(craux, false, left,right);
+                   final SymbolTable st = un.getRule().getSymbolTable();                
+                   CodeWriter cr = new StandardCodeWriter(outputaux) {
+                        public SymbolTable getSymbolTable() { return st; }
+                    };
+                   un.generate(cr, false, stleft,stright,this);
                    craux.endblock();
                    break;
                case MultUpdateNode.REMOVE:
                    Rule r=un.getRule();
-                   String methodcall="void "+methodname+"("+name+"_state * "+state+","+name+" * "+model+", RepairHash * "+repairtable;
+                   String methodcall="void "+methodname+"("+name+"_state * "+ststate+","+name+" * "+stmodel+", RepairHash * "+strepairtable;
                    for(int j=0;j<r.numQuantifiers();j++) {
                        Quantifier q=r.getQuantifier(j);
                        if (q instanceof SetQuantifier) {
@@ -133,7 +146,11 @@ public class RepairGenerator {
                    crhead.outputline(methodcall+";");
                    craux.outputline(methodcall);
                    craux.startblock();
-                   un.generate(craux, true, null,null);
+                   final SymbolTable st2 = un.getRule().getSymbolTable();                
+                   CodeWriter cr2 = new StandardCodeWriter(outputaux) {
+                        public SymbolTable getSymbolTable() { return st2; }
+                    };
+                   un.generate(cr2, true, null,null,this);
                    craux.endblock();
                    break;
                case MultUpdateNode.MODIFY:
@@ -301,12 +318,6 @@ public class RepairGenerator {
     
     private void generate_teardown() {
        CodeWriter cr = new StandardCodeWriter(outputaux);        
-       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.endblock();
     }
 
@@ -456,6 +467,7 @@ public class RepairGenerator {
         cr2.outputline("exit(1);");
         cr2.endblock();
         // end block created for worklist
+       cr2.outputline(worklist.getSafeSymbol()+"->pop();");
         cr2.endblock();
     }
 
@@ -527,8 +539,11 @@ public class RepairGenerator {
                VarDescriptor mincost=VarDescriptor.makeNew("mincost");
                VarDescriptor mincostindex=VarDescriptor.makeNew("mincostindex");
                DNFConstraint dnfconst=constraint.dnfconstraint;
-               cr.outputline("int "+mincostindex.getSafeSymbol()+";");
+               if (dnfconst.size()<=1) {
+                   cr.outputline("int "+mincostindex.getSafeSymbol()+"=0;");
+               }
                if (dnfconst.size()>1) {
+                   cr.outputline("int "+mincostindex.getSafeSymbol()+";");
                    boolean first=true;
                    for(int j=0;j<dnfconst.size();j++) {
                        Conjunction conj=dnfconst.get(j);
@@ -606,7 +621,7 @@ public class RepairGenerator {
                cr.outputline("if ("+oldmodel.getSafeSymbol()+")");
                cr.outputline("delete "+oldmodel.getSafeSymbol()+";");
                cr.outputline(oldmodel.getSafeSymbol()+"="+newmodel.getSafeSymbol()+";");
-               cr.outputline("break;");  /* Rebuild model and all */
+               cr.outputline("goto rebuild;");  /* Rebuild model and all */
 
                 cr.endblock();
 
@@ -615,7 +630,17 @@ public class RepairGenerator {
                     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("break;");
+               cr.endblock();
+               cr.outputline("rebuild:");
+               cr.outputline(";");
                 cr.endblock();
                 cr.outputline("");
                 cr.outputline("");