Bug fixes to make Cristian happy...
authorbdemsky <bdemsky>
Thu, 15 Apr 2004 00:53:00 +0000 (00:53 +0000)
committerbdemsky <bdemsky>
Thu, 15 Apr 2004 00:53:00 +0000 (00:53 +0000)
Repair/RepairCompiler/MCC/IR/DotExpr.java
Repair/RepairCompiler/MCC/IR/FieldDescriptor.java
Repair/RepairCompiler/MCC/IR/OpExpr.java
Repair/RepairCompiler/MCC/IR/RepairGenerator.java
Repair/RepairCompiler/MCC/IR/SemanticChecker.java
Repair/RepairCompiler/MCC/IR/StructureTypeDescriptor.java

index 08a5618baacdc627d83ac83c41704d4384164998..1c5fb47f0055c7ec9c88d7d9b599a21e390939f0 100755 (executable)
@@ -122,37 +122,38 @@ public class DotExpr extends Expr {
         Expr intindex = index;
         Expr offsetbits;
 
-        // #ATTN#: getOffsetExpr needs to be called with the fielddescriptor obect that is in teh vector list
+        // #ATTN#: getOffsetExpr needs to be called with the fielddescriptor object that is in the vector list
         // this means that if the field is an arraydescriptor you have to call getOffsetExpr with the array 
         // descriptor not the underlying field descriptor
 
         /* we calculate the offset in bits */
+        
         offsetbits = struct.getOffsetExpr(fd);
 
-        if (fd instanceof ArrayDescriptor) {
-            fd = ((ArrayDescriptor) fd).getField();
-        } 
-        
+       FieldDescriptor fd=this.fd;
+       if (fd instanceof ArrayDescriptor)
+           fd=((ArrayDescriptor)fd).getField();
+
         if (intindex != null) {
             if (intindex instanceof IntegerLiteralExpr && ((IntegerLiteralExpr) intindex).getValue() == 0) {
-                /* short circuit for constant 0 */                
+                /* short circuit for constant 0 */
             } else {
                 Expr basesize = fd.getBaseSizeExpr();
                 offsetbits = new OpExpr(Opcode.ADD, offsetbits, new OpExpr(Opcode.MULT, basesize, intindex));
             }
         }
-        
-        final SymbolTable st = writer.getSymbolTable();
-        TypeDescriptor td = offsetbits.typecheck(new SemanticAnalyzer() {
-                public IRErrorReporter getErrorReporter() { throw new IRException("badness"); }
-                public SymbolTable getSymbolTable() { return st; }
-            });
-
-        if (td == null) {
-            throw new IRException();
-        } else if (td != ReservedTypeDescriptor.INT) {
-            throw new IRException();
-        }
+
+       final SymbolTable st = writer.getSymbolTable();
+        TypeDescriptor td2 = offsetbits.typecheck(new SemanticAnalyzer() {
+               public IRErrorReporter getErrorReporter() { throw new IRException("badness"); }
+               public SymbolTable getSymbolTable() { return st; }
+           });
+       
+        if (td2 == null) {
+           throw new IRException();
+        } else if (td2 != ReservedTypeDescriptor.INT) {
+           throw new IRException();
+       }
                
         boolean dotypecheck = false;
 
@@ -281,7 +282,11 @@ public class DotExpr extends Expr {
         }
     }
 
+    boolean typechecked=false;
     public TypeDescriptor typecheck(SemanticAnalyzer sa) {
+       if (typechecked)
+           return this.td;
+       else typechecked=true;
         TypeDescriptor lefttype = left.typecheck(sa);
         TypeDescriptor indextype = index == null ? null : index.typecheck(sa);
        
@@ -358,9 +363,6 @@ public class DotExpr extends Expr {
             sa.getErrorReporter().report(null, "Left hand side of . expression must be a structure type, not '" + lefttype.getSymbol() + "'");
             return null;
         }
-        
-        
     }
-
 }
         
index 352a41b584bfb382ba2b2a7082659fae735577ed..0d43dba40b2fb2785bee129419a6f980f2e6acba 100755 (executable)
@@ -40,5 +40,4 @@ public class FieldDescriptor extends Descriptor {
             return type.getSizeExpr();
         }
     }
-
 }
index 83d72576c8f50fe7aa2239b59b7a8b2ec67b7f7c..8693aa3965a77d8ff08cc692b9c5b18f96040143 100755 (executable)
@@ -16,7 +16,7 @@ public class OpExpr extends Expr {
 
     public static boolean isInt(Expr e) {
        if ((e instanceof IntegerLiteralExpr)||
-           ((e instanceof OpExpr)&&(((OpExpr)e).getLeftExpr() instanceof IntegerLiteralExpr)))
+           ((e instanceof OpExpr)&&(((OpExpr)e).opcode==Opcode.NOP)&&(((OpExpr)e).getLeftExpr() instanceof IntegerLiteralExpr)))
            return true;
        return false;
     }
@@ -83,7 +83,13 @@ public class OpExpr extends Expr {
                    value+=8;
            } else throw new Error("Unrecognized Opcode");
            this.left=new IntegerLiteralExpr(value);
-           } else {
+       } else if ((opcode==Opcode.MULT)&&
+                  ((isInt(left)&&(getInt(left)==0))
+                   ||(isInt(right)&&(getInt(right)==0)))) {
+           this.opcode=Opcode.NOP;
+           this.right=null;
+           this.left=new IntegerLiteralExpr(0);
+       } else {
            this.opcode = opcode;
            this.left = left;
            this.right = right;
@@ -279,10 +285,6 @@ public class OpExpr extends Expr {
        } else if (opcode == Opcode.NOP) {
            writer.outputline("int " +dest.getSafeSymbol() + " = " +
                              ld.getSafeSymbol() +"; ");
-       } else if (opcode != Opcode.NOT) { /* two operands */
-            assert rd != null;
-            writer.outputline("int " + dest.getSafeSymbol() + " = " + 
-                              ld.getSafeSymbol() + " " + opcode.toString() + " " + rd.getSafeSymbol() + ";");
         } else if (opcode == Opcode.AND) {
            writer.outputline("int "+rm.getSafeSymbol()+"=maybe;");
            writer.outputline("maybe = (" + ld.getSafeSymbol() + " && " + rm.getSafeSymbol() + ") || (" + rd.getSafeSymbol() + " && " + lm.getSafeSymbol() + ") || (" + lm.getSafeSymbol() + " && " + rm.getSafeSymbol() + ");");
@@ -293,7 +295,11 @@ public class OpExpr extends Expr {
                              " && " + lm.getSafeSymbol() + ") || (" + lm.getSafeSymbol() + " && " + rm.getSafeSymbol() + ");");
            writer.outputline(dest.getSafeSymbol() + " = " + ld.getSafeSymbol() + " || " + rd.getSafeSymbol() +
                              ";");
-       } else {
+       } else if (opcode != Opcode.NOT) { /* two operands */
+            assert rd != null;
+            writer.outputline("int " + dest.getSafeSymbol() + " = " + 
+                              ld.getSafeSymbol() + " " + opcode.toString() + " " + rd.getSafeSymbol() + ";");
+        } else if (opcode == Opcode.NOT) {
             writer.outputline("int " + dest.getSafeSymbol() + " = !" + ld.getSafeSymbol() + ";");
         }
     }
@@ -355,8 +361,3 @@ public class OpExpr extends Expr {
     }
 
 }
-
-
-
-
-
index 58b3b631904ca543c98ddbc9bcc8d7c0a5b4a6cf..1419a6856587d768d07a4674fb258ad901bdbe2c 100755 (executable)
@@ -282,7 +282,11 @@ public class RepairGenerator {
            TypeDescriptor ttd=(TypeDescriptor)it.next();
            tdarray[ttd.getId()]=ttd;
        }
-       CodeWriter cr=new StandardCodeWriter(outputaux);
+       final SymbolTable st = state.stGlobals;
+       CodeWriter cr = new StandardCodeWriter(outputaux) {
+               public SymbolTable getSymbolTable() { return st; }
+           };
+
        cr.outputline("void "+name+"_state::computesizes(int *sizearray,int **numele) {");
        for(int i=0;i<max;i++) {
            TypeDescriptor td=tdarray[i];
@@ -317,7 +321,10 @@ public class RepairGenerator {
            TypeDescriptor ttd=(TypeDescriptor)it.next();
            tdarray[ttd.getId()]=ttd;
        }
-       CodeWriter cr=new StandardCodeWriter(outputaux);
+       final SymbolTable st = state.stGlobals;
+       CodeWriter cr = new StandardCodeWriter(outputaux) {
+               public SymbolTable getSymbolTable() { return st; }
+           };
        cr.outputline("void "+name+"_state::recomputesizes() {");
        for(int i=0;i<max;i++) {
            TypeDescriptor td=tdarray[i];
index 5339bb74f4ab956d1dad7e28584884d63060c1ce..0b9598d40a67cc0aeb020ff4c65ce6800921cad8 100755 (executable)
@@ -290,7 +290,7 @@ public class SemanticChecker {
                 } else {
                     rule.addQuantifier(quantifier);
                 }
-            }             
+            }
         }
         
         /* get guard expr */
index f0808e825020ba07d1ba938f4e9d67244b94613f..9128a4335087750a10ee2ed4dce2451aeeaf15fe 100755 (executable)
@@ -49,7 +49,6 @@ public class StructureTypeDescriptor extends TypeDescriptor {
             boolean ptr = fd.getPtr();
             Expr basesize; 
             if (ptr) { /* ptrs are 32bits */
-               
                basesize = new IntegerLiteralExpr(32);
             } else {
                basesize = td.getSizeExpr();
@@ -79,7 +78,7 @@ public class StructureTypeDescriptor extends TypeDescriptor {
            }
 
             if (fd == field) { /* stop, reached target field */
-                break; 
+                break;
             }
 
             size = new OpExpr(Opcode.ADD, fieldsize, size);