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;
}
}
+ 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);
sa.getErrorReporter().report(null, "Left hand side of . expression must be a structure type, not '" + lefttype.getSymbol() + "'");
return null;
}
-
-
}
-
}
return type.getSizeExpr();
}
}
-
}
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;
}
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;
} 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() + ");");
" && " + 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() + ";");
}
}
}
}
-
-
-
-
-
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];
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];
} else {
rule.addQuantifier(quantifier);
}
- }
+ }
}
/* get guard expr */
boolean ptr = fd.getPtr();
Expr basesize;
if (ptr) { /* ptrs are 32bits */
-
basesize = new IntegerLiteralExpr(32);
} else {
basesize = td.getSizeExpr();
}
if (fd == field) { /* stop, reached target field */
- break;
+ break;
}
size = new OpExpr(Opcode.ADD, fieldsize, size);