From: bdemsky Date: Thu, 15 Apr 2004 00:53:00 +0000 (+0000) Subject: Bug fixes to make Cristian happy... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=repair.git;a=commitdiff_plain;h=42d062915995953ad3e0eb1baf823a1db2fe3971 Bug fixes to make Cristian happy... --- diff --git a/Repair/RepairCompiler/MCC/IR/DotExpr.java b/Repair/RepairCompiler/MCC/IR/DotExpr.java index 08a5618..1c5fb47 100755 --- a/Repair/RepairCompiler/MCC/IR/DotExpr.java +++ b/Repair/RepairCompiler/MCC/IR/DotExpr.java @@ -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; } - - } - } diff --git a/Repair/RepairCompiler/MCC/IR/FieldDescriptor.java b/Repair/RepairCompiler/MCC/IR/FieldDescriptor.java index 352a41b..0d43dba 100755 --- a/Repair/RepairCompiler/MCC/IR/FieldDescriptor.java +++ b/Repair/RepairCompiler/MCC/IR/FieldDescriptor.java @@ -40,5 +40,4 @@ public class FieldDescriptor extends Descriptor { return type.getSizeExpr(); } } - } diff --git a/Repair/RepairCompiler/MCC/IR/OpExpr.java b/Repair/RepairCompiler/MCC/IR/OpExpr.java index 83d7257..8693aa3 100755 --- a/Repair/RepairCompiler/MCC/IR/OpExpr.java +++ b/Repair/RepairCompiler/MCC/IR/OpExpr.java @@ -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 { } } - - - - - diff --git a/Repair/RepairCompiler/MCC/IR/RepairGenerator.java b/Repair/RepairCompiler/MCC/IR/RepairGenerator.java index 58b3b63..1419a68 100755 --- a/Repair/RepairCompiler/MCC/IR/RepairGenerator.java +++ b/Repair/RepairCompiler/MCC/IR/RepairGenerator.java @@ -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