Added support for stack allocation. Check for NULL before calling memory checker.
authorbdemsky <bdemsky>
Mon, 8 Mar 2004 00:28:36 +0000 (00:28 +0000)
committerbdemsky <bdemsky>
Mon, 8 Mar 2004 00:28:36 +0000 (00:28 +0000)
Repair/RepairCompiler/MCC/IR/DotExpr.java
Repair/RepairCompiler/MCC/IR/RepairGenerator.java
Repair/RepairCompiler/MCC/IR/StructureGenerator.java
Repair/RepairCompiler/MCC/IR/VarExpr.java

index 7924bb4..38ee61a 100755 (executable)
@@ -168,16 +168,18 @@ public class DotExpr extends Expr {
                 /* type var = [*(int *)] (base + offset) */
                 writer.outputline("int " + dest.getSafeSymbol()+"=0;");
                writer.outputline("if ("+leftd.getSafeSymbol()+")");
+               writer.startblock();
                 writer.outputline(dest.getSafeSymbol() + 
                                   " = " + ptr + "(" + leftd.getSafeSymbol() + " + " + offset + ");");  
-               writer.outputline("else maybe=1;");
                if (fd.getPtr()) {
+                   writer.outputline("if ("+dest.getSafeSymbol()+")");
+                   writer.startblock();
                    VarDescriptor typevar=VarDescriptor.makeNew("typechecks");
                    if (DOMEMCHECKS&&(!DOTYPECHECKS)) {
-                       writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + td.getId() + ");");
+                       writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");");
                        dotypecheck = true;
                    } else if (DOTYPECHECKS) {
-                       writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + td.getId() + ");");
+                       writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");");
                    }
                    writer.outputline("if (!"+typevar.getSafeSymbol()+")");
                    writer.startblock();
@@ -185,7 +187,10 @@ public class DotExpr extends Expr {
                    if (DONULL)
                        writer.outputline(ptr + "(" + leftd.getSafeSymbol() + " + " + offset + ")=0;");
                    writer.endblock();
+                   writer.endblock();
                }
+               writer.endblock();
+               writer.outputline("else maybe=1;");
             }
         } else { /* offset in bits is an expression that must be generated */                        
             VarDescriptor ob = VarDescriptor.makeNew("offsetinbits");
@@ -220,16 +225,18 @@ public class DotExpr extends Expr {
                 /* type var = [*(int *)] (base + offset) */
                 writer.outputline("int " + dest.getSafeSymbol() +"=0;"); 
                writer.outputline("if ("+leftd.getSafeSymbol()+")");
+               writer.startblock();
                 writer.outputline(dest.getSafeSymbol() + 
                                   " = " + ptr + "(" + leftd.getSafeSymbol() + " + " + offset.getSafeSymbol() + ");");  
-               writer.outputline("else maybe=1;");
                if (fd.getPtr()) {
+                   writer.outputline("if ("+dest.getSafeSymbol()+")");
+                   writer.startblock();
                    VarDescriptor typevar=VarDescriptor.makeNew("typechecks");
                    if (DOMEMCHECKS&&(!DOTYPECHECKS)) {
-                       writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + td.getId() + ");");
+                       writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");");
                        dotypecheck = true;
                    } else if (DOTYPECHECKS) {
-                       writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + td.getId() + ");");
+                       writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");");
                    }
                    writer.outputline("if (!"+typevar.getSafeSymbol()+")");
                    writer.startblock();
@@ -237,7 +244,10 @@ public class DotExpr extends Expr {
                    if (DONULL)
                        writer.outputline(ptr + "(" + leftd.getSafeSymbol() + " + " + offset.getSafeSymbol() + ")=0;");
                    writer.endblock();
+                   writer.endblock();
                }
+               writer.endblock();
+               writer.outputline("else maybe=1;");
             }
         }
     }
index 82af1ba..52631d4 100755 (executable)
@@ -410,6 +410,8 @@ public class RepairGenerator {
        crhead.outputline("void doanalysis();");
        craux.outputline("void "+name +"_state::doanalysis()");
        craux.startblock();
+       craux.outputline("int highmark;");
+       craux.outputline("initializestack(&highmark);");
        craux.outputline("typeobject *typeobject1=gettypeobject();");
        craux.outputline("typeobject1->computesizes(this);");
        craux.outputline("recomputesizes();");
index fe8e4b1..e9a94fb 100755 (executable)
@@ -42,6 +42,7 @@ public class StructureGenerator {
     private void generatecalls() {
        int max=TypeDescriptor.counter;
        cr.outputline("int arsize["+max+"];");
+       cr.outputline("int arsizeBytes["+max+"];");
 
        for(int i=0;i<max;i++) {
            TypeDescriptor ttd=tdarray[i];
@@ -72,6 +73,10 @@ public class StructureGenerator {
        cr.outputline("return arsize[type];");
        cr.outputline("}");
 
+       cr.outputline("int typeobject::sizeBytes(int type) {");
+       cr.outputline("return arsizeBytes[type];");
+       cr.outputline("}");
+
        cr.outputline("int typeobject::numElements(int type, int fieldindex) {");
        cr.outputline("return arnumelements[type][fieldindex];");
        cr.outputline("}");
@@ -82,6 +87,12 @@ public class StructureGenerator {
        int max=TypeDescriptor.counter;
        cr.outputline("void typeobject::computesizes("+rg.name+"_state * obj) {");
        cr.outputline("obj->computesizes(arsize,arnumelements);");
+       cr.outputline("for(int i=0;i<"+max+";i++) {");
+       cr.outputline("int bits=arsize[i];");
+       cr.outputline("int bytes=bits>>3;");
+       cr.outputline("if (bits%8) bytes++;");
+       cr.outputline("arsizeBytes[i]=bytes;");
+       cr.outputline("}");
        cr.outputline("}");
     }
 
@@ -95,6 +106,7 @@ public class StructureGenerator {
        crhead.outputline("int isPtr(int type, int fieldindex);");
        crhead.outputline("int numElements(int type, int fieldindex);");
        crhead.outputline("int size(int type);");
+       crhead.outputline("int sizeBytes(int type);");
        crhead.outputline("int getnumfields(int type);");
        crhead.outputline("bool issubtype(int subtype, int type);");
        crhead.outputline("void computesizes("+rg.name+"_state *);");
index 2a71140..51e916a 100755 (executable)
@@ -83,6 +83,8 @@ public class VarExpr extends Expr {
                           " = (" + vd.getType().getGenerateType().getSafeSymbol() + ") " + vd.getSafeSymbol() + "; //varexpr");
        if (vd.isGlobal() && (DOTYPECHECKS||DOMEMCHECKS) && (td instanceof StructureTypeDescriptor)) {
            VarDescriptor typevar=VarDescriptor.makeNew("typechecks");
+           writer.outputline("if ("+dest.getSafeSymbol()+")");
+           writer.startblock();
            if (DOTYPECHECKS)
                writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + td.getId() + ");"); 
            else
@@ -93,6 +95,7 @@ public class VarExpr extends Expr {
            if (DONULL)
                writer.outputline(vd.getSafeSymbol()+"=0;");
            writer.endblock();
+           writer.endblock();
        }
     }