gcc $FLAG -c instrument.c
gcc $FLAG -c libredblack/redblack.c
gcc $FLAG -c stack.c
-
+gcc $FLAG -c size.c
+gcc $FLAG -c cache_aux.c
}
public void generate(CodeWriter writer, VarDescriptor dest) {
- writer.outputline("int " + dest.getSafeSymbol() + " = " + (value ? "1" : "0") + ";");
+ writer.addDeclaration("int", dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol() + " = " + (value ? "1" : "0") + ";");
}
public void prettyPrint(PrettyPrinter pp) {
public void generate(CodeWriter writer, VarDescriptor dest) {
VarDescriptor vd = VarDescriptor.makeNew("expr");
expr.generate(writer, vd);
- writer.outputline("int " + dest.getSafeSymbol() + " = (int) " + vd.getSafeSymbol() + ";");
+ writer.addDeclaration("int", dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol() + " = (int) " + vd.getSafeSymbol() + ";");
}
public void prettyPrint(PrettyPrinter pp) {
public void startblock();
public void endblock();
+ public void startBuffer();
+ public void emptyBuffer();
+ public void addDeclaration(String type, String varname);
+ public void addDeclaration(String function);
public void pushSymbolTable(SymbolTable st);
public SymbolTable popSymbolTable();
public SymbolTable getSymbolTable();
if (writer.getInvariantValue()!=null&&
writer.getInvariantValue().isInvariant(this)) {
- writer.outputline(getType().getGenerateType().getSafeSymbol()+
- " "+dest.getSafeSymbol()+"="+writer.getInvariantValue().getValue(this).getSafeSymbol()+";");
+ writer.addDeclaration(getType().getGenerateType().getSafeSymbol().toString(), dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol()+"="+writer.getInvariantValue().getValue(this).getSafeSymbol()+";");
writer.outputline("maybe="+writer.getInvariantValue().getMaybe(this).getSafeSymbol()+";");
return;
}
boolean doboundscheck=true;
boolean performedboundscheck=false;
- writer.outputline(getType().getGenerateType() + " " + dest.getSafeSymbol()+"=0;");
+ writer.addDeclaration(getType().getGenerateType().toString(),dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol()+"=0;");
if (intindex != null) {
if (intindex instanceof IntegerLiteralExpr && ((IntegerLiteralExpr) intindex).getValue() == 0) {
/* derive offset in bytes */
VarDescriptor offset = VarDescriptor.makeNew("offset");
- writer.outputline("int " + offset.getSafeSymbol() + " = " + ob.getSafeSymbol() + " >> 3;");
+ writer.addDeclaration("int", offset.getSafeSymbol());
+ writer.outputline(offset.getSafeSymbol() + " = " + ob.getSafeSymbol() + " >> 3;");
if (fd.getType() instanceof ReservedTypeDescriptor && !fd.getPtr()) {
VarDescriptor shift = VarDescriptor.makeNew("shift");
- writer.outputline("int " + shift.getSafeSymbol() + " = " + ob.getSafeSymbol() +
+ writer.addDeclaration("int", shift.getSafeSymbol());
+ writer.outputline(shift.getSafeSymbol() + " = " + ob.getSafeSymbol() +
" - (" + offset.getSafeSymbol() + " << 3);");
int mask = bitmask(((IntegerLiteralExpr)fd.getType().getSizeExpr()).getValue());
writer.startblock();
VarDescriptor typevar=VarDescriptor.makeNew("typechecks");
if (DOMEMCHECKS&&(!DOTYPECHECKS)) {
- writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");");
+ writer.addDeclaration("bool", typevar.getSafeSymbol());
+ writer.outputline(typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");");
dotypecheck = true;
} else if (DOTYPECHECKS) {
- writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");");
+ writer.addDeclaration("bool", typevar.getSafeSymbol());
+ writer.outputline(typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + this.td.getId() + ");");
}
if (DOTYPECHECKS||DOMEMCHECKS) {
public void generate(CodeWriter writer, VarDescriptor dest) {
VarDescriptor ed = VarDescriptor.makeNew("element");
element.generate(writer, ed);
- writer.outputline("int " + dest.getSafeSymbol() + " = SimpleHashcontainskey("+set.getSafeSymbol() +"_hash ,"+ ed.getSafeSymbol() + ");");
+ writer.addDeclaration("int", dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol() + " = SimpleHashcontainskey("+set.getSafeSymbol() +"_hash ,"+ ed.getSafeSymbol() + ");");
}
public void prettyPrint(PrettyPrinter pp) {
VarDescriptor ud = VarDescriptor.makeNew();
lower.generate(writer, ld);
upper.generate(writer, ud);
-
- writer.outputline("for (int " + var.getSafeSymbol() + " = " + ld.getSafeSymbol() + "; " + var.getSafeSymbol() + " <= " + ud.getSafeSymbol() + "; " + var.getSafeSymbol() + "++)");
+ writer.addDeclaration("int",var.getSafeSymbol());
+ writer.outputline("for (" + var.getSafeSymbol() + " = " + ld.getSafeSymbol() + "; " + var.getSafeSymbol() + " <= " + ud.getSafeSymbol() + "; " + var.getSafeSymbol() + "++)");
writer.startblock();
}
public int generate_worklistload(CodeWriter writer, int offset) {
String varname = var.getSafeSymbol();
- writer.outputline("int " + varname + " = wi->word" + offset + ";");
+ writer.addDeclaration("int",varname);
+ writer.outputline(varname + " = wi->word" + offset + ";");
return offset + 1;
}
public void generate_inclusion(CodeWriter writer, VarDescriptor dest, VarDescriptor element) {
String hash = inverse ? "_hashinv, " : "_hash, " ;
if (!isimageset) {
- writer.outputline("int " + dest.getSafeSymbol() + " = SimpleHashcontainskeydata(" + rd.getSafeSymbol() + hash + vd.getSafeSymbol() + ", " + element.getSafeSymbol() + ");");
+ writer.addDeclaration("int", dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol() + " = SimpleHashcontainskeydata(" + rd.getSafeSymbol() + hash + vd.getSafeSymbol() + ", " + element.getSafeSymbol() + ");");
} else {
VarDescriptor newset=VarDescriptor.makeNew("newset");
generate_set(writer,newset);
- writer.outputline("int "+dest.getSafeSymbol()+"=SimpleHashcontainskey("+newset.getSafeSymbol()+","+element.getSafeSymbol()+");");
- writer.outputline("delete "+newset.getSafeSymbol()+";");
+ writer.addDeclaration("int", dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol()+"=SimpleHashcontainskey("+newset.getSafeSymbol()+","+element.getSafeSymbol()+");");
+ writer.outputline("freeSimpleHash("+newset.getSafeSymbol()+");");
}
}
assert rd != null;
if (!isimageset) {
String hash = inverse ? "_hashinv, " : "_hash, " ;
- writer.outputline("int " + dest.getSafeSymbol() + " = SimpleHashcount(" + rd.getSafeSymbol() + hash + vd.getSafeSymbol() + ");");
+ writer.addDeclaration("int", dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol() + " = SimpleHashcount(" + rd.getSafeSymbol() + hash + vd.getSafeSymbol() + ");");
} else {
VarDescriptor newset=VarDescriptor.makeNew("newset");
generate_set(writer,newset);
- writer.outputline("int "+dest.getSafeSymbol()+"=SimpleHashcountset("+newset.getSafeSymbol()+");");
- writer.outputline("delete "+newset.getSafeSymbol()+";");
+ writer.addDeclaration("int", dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol()+"=SimpleHashcountset("+newset.getSafeSymbol()+");");
+ writer.outputline("freeSimpleHash("+newset.getSafeSymbol()+");");
}
}
public void generate_leftside(CodeWriter writer, VarDescriptor dest) {
if (!isimageset) {
- writer.outputline(vd.getType().getGenerateType()+" "+dest.getSafeSymbol()+" = "+vd.getSafeSymbol()+";");
+ writer.addDeclaration(vd.getType().getGenerateType().toString(), dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol()+" = "+vd.getSafeSymbol()+";");
} else {
VarDescriptor iseset=VarDescriptor.makeNew("set");
ise.generate_set(writer,iseset);
- writer.outputline("int "+dest.getSafeSymbol()+" = SimpleHashfirstkey("+iseset.getSafeSymbol()+");");
- writer.outputline("delete "+iseset.getSafeSymbol()+";");
+ writer.addDeclaration("int",dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol()+" = SimpleHashfirstkey("+iseset.getSafeSymbol()+");");
+ writer.outputline("freeSimpleHash("+iseset.getSafeSymbol()+");");
}
}
public void generate_set(CodeWriter writer, VarDescriptor dest) {
if (!isimageset) {
String hash = inverse ? "_hashinv, " : "_hash, " ;
- writer.outputline("struct SimpleHash * "+dest.getSafeSymbol()+"=SimpleHashimageSet("+rd.getSafeSymbol()+hash+vd.getSafeSymbol()+");");
+ writer.addDeclaration("struct SimpleHash *",dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol()+"=SimpleHashimageSet("+rd.getSafeSymbol()+hash+vd.getSafeSymbol()+");");
} else {
VarDescriptor iseset=VarDescriptor.makeNew("set");
ise.generate_set(writer,iseset);
VarDescriptor itvd=VarDescriptor.makeNew("iterator");
- writer.outputline("struct SimpleIterator "+itvd.getSafeSymbol()+";");
+ writer.addDeclaration("struct SimpleIterator",itvd.getSafeSymbol());
writer.outputline("SimpleHashiterator("+iseset.getSafeSymbol()+",&"+itvd.getSafeSymbol()+");");
-
- writer.outputline("struct SimpleHash *"+dest.getSafeSymbol()+"=allocateSimpleHash(10);");
+ writer.addDeclaration("struct SimpleHash *", dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol()+"=allocateSimpleHash(10);");
writer.outputline("while (hasNext(&"+itvd.getSafeSymbol()+")) {");
VarDescriptor keyvd=VarDescriptor.makeNew("key");
- writer.outputline("int "+keyvd.getSafeSymbol()+"=next(&"+itvd.getSafeSymbol()+");");
+ writer.addDeclaration("int",keyvd.getSafeSymbol());
+ writer.outputline(keyvd.getSafeSymbol()+"=next(&"+itvd.getSafeSymbol()+");");
String hash = inverse ? "_hashinv, " : "_hash, " ;
VarDescriptor newset=VarDescriptor.makeNew("newset");
- writer.outputline("SimpleHash * "+newset.getSafeSymbol()+"=SimpleHashimageSet("+rd.getSafeSymbol()+hash+keyvd.getSafeSymbol()+");");
+ writer.addDeclaration("struct SimpleHash *", newset.getSafeSymbol());
+ writer.outputline(newset.getSafeSymbol()+"=SimpleHashimageSet("+rd.getSafeSymbol()+hash+keyvd.getSafeSymbol()+");");
writer.outputline("SimpleHashaddAll("+dest.getSafeSymbol()+", "+ newset.getSafeSymbol()+");");
writer.outputline("freeSimpleHash("+newset.getSafeSymbol()+");");
writer.outputline("}");
}
public void generate(CodeWriter writer, VarDescriptor dest) {
- writer.outputline("int " + dest.getSafeSymbol() + " = " + value + ";");
+ writer.addDeclaration("int", dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol() + " = " + value + ";");
}
public void prettyPrint(PrettyPrinter pp) {
public void generate(CodeWriter writer, VarDescriptor dest) {
- writer.outputline("int " + dest.getSafeSymbol() + ";");
+ writer.addDeclaration("int", dest.getSafeSymbol());
if (op == NOT) {
VarDescriptor leftd = VarDescriptor.makeNew("leftboolean");
String lm = (VarDescriptor.makeNew("leftmaybe")).getSafeSymbol();
left.generate(writer, leftd);
- writer.outputline("int " + lm + " = maybe;");
+ writer.addDeclaration("int", lm);
+ writer.outputline(lm + " = maybe;");
writer.outputline("maybe=0;");
VarDescriptor rightd = VarDescriptor.makeNew("rightboolean");
String rm = (VarDescriptor.makeNew("rightmaybe")).getSafeSymbol();
assert right != null;
right.generate(writer, rightd);
- writer.outputline("int " + rm + " = maybe;");
+ writer.addDeclaration("int", rm);
+ writer.outputline(rm + " = maybe;");
String l = leftd.getSafeSymbol();
String r = rightd.getSafeSymbol();
/* Check for loop invariant hoisting. */
if (writer.getInvariantValue()!=null&&
writer.getInvariantValue().isInvariant(this)) {
- writer.outputline("int "+dest.getSafeSymbol()+"="+writer.getInvariantValue().getValue(this).getSafeSymbol()+";");
+ writer.addDeclaration("int",dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol()+"="+writer.getInvariantValue().getValue(this).getSafeSymbol()+";");
writer.outputline("maybe="+writer.getInvariantValue().getMaybe(this).getSafeSymbol()+";");
return;
}
if (right != null) {
if ((opcode==Opcode.OR)||
(opcode==Opcode.AND)) {
- writer.outputline("int "+lm.getSafeSymbol()+"=maybe;");
+ writer.addDeclaration("int",lm.getSafeSymbol());
+ writer.outputline(lm.getSafeSymbol()+"=maybe;");
writer.outputline("maybe=0;");
}
String code;
if (opcode == Opcode.RND) {
- writer.outputline("int " +dest.getSafeSymbol() + " = (" +
+ writer.addDeclaration("int",dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol() + " = (" +
ld.getSafeSymbol() + ">>3)<<3; ");
writer.outputline("if ("+ld.getSafeSymbol()+" % 8) "+dest.getSafeSymbol()+"+=8;");
} else if (opcode == Opcode.NOP) {
- writer.outputline("int " +dest.getSafeSymbol() + " = " +
+ writer.addDeclaration("int", dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol() + " = " +
ld.getSafeSymbol() +"; ");
} else if (opcode == Opcode.AND) {
- writer.outputline("int "+rm.getSafeSymbol()+"=maybe;");
+ writer.addDeclaration("int",rm.getSafeSymbol());
+ writer.outputline(rm.getSafeSymbol()+"=maybe;");
writer.outputline("maybe = (" + ld.getSafeSymbol() + " && " + rm.getSafeSymbol() + ") || (" + rd.getSafeSymbol() + " && " + lm.getSafeSymbol() + ") || (" + lm.getSafeSymbol() + " && " + rm.getSafeSymbol() + ");");
- writer.outputline("int "+dest.getSafeSymbol() + " = " + ld.getSafeSymbol() + " && " + rd.getSafeSymbol() + ";");
+ writer.addDeclaration("int",dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol() + " = " + ld.getSafeSymbol() + " && " + rd.getSafeSymbol() + ";");
} else if (opcode == Opcode.OR) {
- writer.outputline("int "+rm.getSafeSymbol()+"=maybe;");
+ writer.addDeclaration("int",rm.getSafeSymbol());
+ writer.outputline(rm.getSafeSymbol()+"=maybe;");
writer.outputline("maybe = (!" + ld.getSafeSymbol() + " && " + rm.getSafeSymbol() + ") || (!" + rd.getSafeSymbol() +
" && " + lm.getSafeSymbol() + ") || (" + lm.getSafeSymbol() + " && " + rm.getSafeSymbol() + ");");
- writer.outputline("int "+dest.getSafeSymbol() + " = " + ld.getSafeSymbol() + " || " + rd.getSafeSymbol() + ";");
+ writer.addDeclaration("int",dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol() + " = " + ld.getSafeSymbol() + " || " + rd.getSafeSymbol() + ";");
} else if (opcode != Opcode.NOT) { /* two operands */
assert rd != null;
- writer.outputline("int " + dest.getSafeSymbol() + " = " +
+ writer.addDeclaration("int", dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol() + " = " +
ld.getSafeSymbol() + " " + opcode.toString() + " " + rd.getSafeSymbol() + ";");
} else if (opcode == Opcode.NOT) {
- writer.outputline("int " + dest.getSafeSymbol() + " = !" + ld.getSafeSymbol() + ";");
+ writer.addDeclaration("int", dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol() + " = !" + ld.getSafeSymbol() + ";");
}
}
public class PrintWrapper {
java.io.PrintWriter output;
- String buffered="";
+ StringBuffer buffered=new StringBuffer("");
boolean buffer=false;
Hashtable vartable=new Hashtable();
+ public int indent=0;
public PrintWrapper(java.io.PrintWriter output) {
this.output=output;
}
void print(String s) {
if (buffer)
- buffered+=s;
+ buffered.append(s);
else
output.print(s);
}
}
void println(String s) {
if (buffer)
- buffered+=s+"\n";
+ buffered.append(s+"\n");
else
output.println(s);
}
String var=(String)it.next();
output.println(((String)vartable.get(var))+" "+var+";");
}
- output.print(buffered);
- buffered="";
+ output.print(buffered.toString());
+ buffered=new StringBuffer("");
vartable=new Hashtable();
buffer=false;
}
} else
output.println(type+" "+varname+";");
}
+ void addDeclaration(String f) {
+ if (buffer) {
+ buffered.insert(0,f+"\n");
+ } else
+ output.println(f);
+ }
}
String strinverse = inverse ? "inv" : "";
String found = (VarDescriptor.makeNew("found")).getSafeSymbol();
expr.generate(writer, domain);
- writer.outputline(relation.getRange().getType().getGenerateType().getSafeSymbol() + " " + dest.getSafeSymbol() + ";");
- writer.outputline("int "+found+" = SimpleHashget(" +relation.getSafeSymbol()+"_hash"+strinverse+", "+ domain.getSafeSymbol() + ", & " + dest.getSafeSymbol() + ");");
+ writer.addDeclaration(relation.getRange().getType().getGenerateType().getSafeSymbol(), dest.getSafeSymbol());
+ writer.addDeclaration("int",found);
+ writer.outputline(found+" = SimpleHashget(" +relation.getSafeSymbol()+"_hash"+strinverse+", "+ domain.getSafeSymbol() + ", & " + dest.getSafeSymbol() + ");");
writer.outputline("if (!" + found + ") { maybe = 1; }");
}
public void generate(CodeWriter cr, VarDescriptor dest) {
String destname = dest.getSafeSymbol();
- cr.outputline("int " + destname + ";");
+ cr.addDeclaration("int", destname);
// ok... destination is declared... we gotta expand this rule inplace... and instead of the inclusion we
// set the destination in the guard ... otherwise maybe!
String tempvar = (VarDescriptor.makeNew("tempvar")).getSafeSymbol();
// this is to be safe about name overlap because int t = t; sets t to 0!
- cr.outputline("int " + tempvar + " = " + domain.getSafeSymbol() + ";");
- cr.outputline("int " + rulebinding.getSafeSymbol() + " = " + tempvar + ";");
+ cr.addDeclaration("int", tempvar);
+ cr.outputline(tempvar + " = " + domain.getSafeSymbol() + ";");
+ cr.addDeclaration("int", rulebinding.getSafeSymbol());
+ cr.outputline(rulebinding.getSafeSymbol() + " = " + tempvar + ";");
/* pretty print! */
cr.outputline("/* about to inbed relational function*/");
}
public void generate_open(CodeWriter writer) {
- writer.outputline("struct SimpleIterator "+x.getSafeSymbol()+"_iterator;");
- writer.outputline("for (SimpleHashiterator("+relation.getSafeSymbol()+"_hash, "+x.getSafeSymbol()+"_iterator); hasNext("+x.getSafeSymbol()+"_iterator); )");
+ writer.addDeclaration("struct SimpleIterator",x.getSafeSymbol()+"_iterator");
+ writer.outputline("for (SimpleHashiterator("+relation.getSafeSymbol()+"_hash, &"+x.getSafeSymbol()+"_iterator); hasNext(&"+x.getSafeSymbol()+"_iterator); )");
writer.startblock();
- writer.outputline(y.getType().getGenerateType() + " " + y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") next("+x.getSafeSymbol()+"_iterator);");
+ writer.addDeclaration(y.getType().getGenerateType().toString(), y.getSafeSymbol());
+ writer.outputline(y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") next(&"+x.getSafeSymbol()+"_iterator);");
// #ATTN#: key is called second because next() forwards ptr and key does not!
- writer.outputline(x.getType().getGenerateType() + " " + x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") key("+x.getSafeSymbol()+"_iterator);");
+ writer.addDeclaration(x.getType().getGenerateType().toString(), x.getSafeSymbol());
+ writer.outputline(x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") key(&"+x.getSafeSymbol()+"_iterator);");
}
public void generate_open(CodeWriter writer, String type,int number, String left,String right) {
VarDescriptor tmp=VarDescriptor.makeNew("flag");
- writer.outputline("struct SimpleIterator * " + x.getSafeSymbol() + "_iterator = SimpleHashcreateiterator("+relation.getSafeSymbol()+"_hash);");
- writer.outputline("int "+tmp.getSafeSymbol()+"=0;");
+ writer.addDeclaration("struct SimpleIterator", x.getSafeSymbol() + "_iterator");
+ writer.outputline("SimpleHashiterator("+relation.getSafeSymbol()+"_hash,& "+x.getSafeSymbol()+"_iterator);");
+ writer.addDeclaration("int",tmp.getSafeSymbol());
+ writer.outputline(tmp.getSafeSymbol()+"=0;");
writer.outputline("if ("+type+"=="+number+")");
writer.outputline(tmp.getSafeSymbol()+"=1;");
- writer.outputline("while("+tmp.getSafeSymbol()+"||(("+type+"!="+number+")&& hasNext("+x.getSafeSymbol()+"_iterator)))");
+ writer.outputline("while("+tmp.getSafeSymbol()+"||(("+type+"!="+number+")&& hasNext(&"+x.getSafeSymbol()+"_iterator)))");
writer.startblock();
- writer.outputline(x.getType().getGenerateType() + " " + x.getSafeSymbol() + ";");
- writer.outputline(y.getType().getGenerateType() + " " + y.getSafeSymbol() + ";");
+ writer.addDeclaration(x.getType().getGenerateType().toString(), x.getSafeSymbol());
+ writer.addDeclaration(y.getType().getGenerateType().toString(), y.getSafeSymbol());
writer.outputline("if ("+type+"=="+number+")");
writer.startblock();
writer.outputline(tmp.getSafeSymbol()+"=0;");
writer.endblock();
writer.outputline("else");
writer.startblock();
- writer.outputline(y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") next("+x.getSafeSymbol()+"_iterator);");
- writer.outputline(x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") key("+x.getSafeSymbol()+"_iterator);");
+ writer.outputline(y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") next(&"+x.getSafeSymbol()+"_iterator);");
+ writer.outputline(x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") key(&"+x.getSafeSymbol()+"_iterator);");
writer.endblock();
}
public class RepairGenerator {
State state;
- java.io.PrintWriter outputrepair = null;
- java.io.PrintWriter outputaux = null;
- java.io.PrintWriter outputhead = null;
+ PrintWrapper outputrepair = null;
+ PrintWrapper outputaux = null;
+ PrintWrapper outputhead = null;
String name="foo";
String headername;
static VarDescriptor oldmodel=null;
}
public void generate(OutputStream outputrepair, OutputStream outputaux,OutputStream outputhead, String st) {
- this.outputrepair = new java.io.PrintWriter(outputrepair, true);
- this.outputaux = new java.io.PrintWriter(outputaux, true);
- this.outputhead = new java.io.PrintWriter(outputhead, true);
+ this.outputrepair = new PrintWrapper(new java.io.PrintWriter(outputrepair, true));
+ this.outputaux = new PrintWrapper(new java.io.PrintWriter(outputaux, true));
+ this.outputhead = new PrintWrapper(new java.io.PrintWriter(outputhead, true));
headername=st;
name_updates();
generate_teardown();
CodeWriter crhead = new StandardCodeWriter(this.outputhead);
craux = new StandardCodeWriter(this.outputaux);
- craux.outputline("}");
+ craux.emptyBuffer();
+ craux.endblock();
if (Compiler.GENERATEDEBUGHOOKS) {
crhead.outputline("void debughook();");
craux.outputline("void "+methodname+"(struct "+name+"_state * "+ststate+", struct "+name+" * "+stmodel+", struct RepairHash * "+strepairtable+", int "+stleft+")");
}
craux.startblock();
- craux.outputline("int maybe=0;");
+ craux.startBuffer();
+ craux.addDeclaration("int","maybe");
+ craux.outputline("maybe=0;");
if (Compiler.GENERATEINSTRUMENT)
craux.outputline("updatecount++;");
};
un.generate(cr, false, false, stleft,stright, null,this);
craux.outputline("if (maybe) printf(\"REALLY BAD\");");
+ craux.emptyBuffer();
craux.endblock();
break;
case MultUpdateNode.REMOVE: {
crhead.outputline(methodcall+";");
craux.outputline(methodcall);
craux.startblock();
- craux.outputline("int maybe=0;");
+ craux.startBuffer();
+ craux.addDeclaration("int","maybe");
+ craux.outputline("maybe=0;");
if (Compiler.GENERATEINSTRUMENT)
craux.outputline("updatecount++;");
final SymbolTable st2 = un.getRule().getSymbolTable();
};
un.generate(cr2, true, false, null,null, null,this);
craux.outputline("if (maybe) printf(\"REALLY BAD\");");
+ craux.emptyBuffer();
craux.endblock();
}
break;
crhead.outputline(methodcall+";");
craux.outputline(methodcall);
craux.startblock();
+ craux.startBuffer();
craux.outputline("int maybe=0;");
if (Compiler.GENERATEINSTRUMENT)
craux.outputline("updatecount++;");
};
un.generate(cr2, false, true, stleft, stright, stnew, this);
craux.outputline("if (maybe) printf(\"REALLY BAD\");");
+ craux.emptyBuffer();
craux.endblock();
}
break;
private void generate_call() {
CodeWriter cr = new StandardCodeWriter(outputrepair);
VarDescriptor vdstate=VarDescriptor.makeNew("repairstate");
- cr.outputline("struct "+ name+"_state * "+vdstate.getSafeSymbol()+"=allocate"+name+"_state();");
+ cr.addDeclaration("struct "+ name+"_state *", vdstate.getSafeSymbol());
+ cr.outputline(vdstate.getSafeSymbol()+"=allocate"+name+"_state();");
Iterator globals=state.stGlobals.descriptors();
while (globals.hasNext()) {
VarDescriptor vd=(VarDescriptor) globals.next();
public SymbolTable getSymbolTable() { return st; }
};
- cr.outputline("void "+name+"_statecomputesizes(struct "+name+"_state * thisvar,int *sizearray,int **numele) {");
- cr.outputline("int maybe=0;");
+ cr.outputline("void "+name+"_statecomputesizes(struct "+name+"_state * thisvar,int *sizearray,int **numele)");
+ cr.startblock();
+ cr.startBuffer();
+ cr.addDeclaration("int","maybe");
+ cr.outputline("maybe=0;");
for(int i=0;i<max;i++) {
TypeDescriptor td=tdarray[i];
Expr size=td.getSizeExpr();
}
}
cr.outputline("if (maybe) printf(\"BAD ERROR\");");
- cr.outputline("}");
+ cr.emptyBuffer();
+ cr.endblock();
}
private void generate_recomputesizes() {
CodeWriter cr = new StandardCodeWriter(outputaux) {
public SymbolTable getSymbolTable() { return st; }
};
- cr.outputline("void "+name+"_staterecomputesizes(struct "+name+"_state * thisvar) {");
- cr.outputline("int maybe=0;");
+ cr.outputline("void "+name+"_staterecomputesizes(struct "+name+"_state * thisvar)");
+ cr.startblock();
+ cr.startBuffer();
+ cr.addDeclaration("int","maybe");
+ cr.outputline("maybe=0;");
for(int i=0;i<max;i++) {
TypeDescriptor td=tdarray[i];
Expr size=td.getSizeExpr();
}
}
cr.outputline("if (maybe) printf(\"BAD ERROR\");");
- cr.outputline("}");
+ cr.emptyBuffer();
+ cr.endblock();
}
}
}
}
- craux.outputline("struct "+ name+"* "+name+"() {");
+ craux.outputline("struct "+ name+"* "+name+"()");
+ craux.startblock();
craux.outputline("/* creating hashtables */");
/* build sets */
Iterator sets = state.stSets.descriptors();
- craux.outputline("struct "+name+"* thisvar=(struct "+name+"*) malloc(sizeof(struct "+name+"));");
+ craux.addDeclaration("struct "+name+"*", "thisvar");
+ craux.outputline("thisvar=(struct "+name+"*) malloc(sizeof(struct "+name+"));");
/* first pass create all the hash tables */
while (sets.hasNext()) {
}
}
- craux.outputline("}");
+ craux.endblock();
crhead.outputline("};");
- craux.outputline("void free"+name+"(struct "+ name +"* thisvar) {");
+ craux.outputline("void free"+name+"(struct "+ name +"* thisvar)");
+ craux.startblock();
craux.outputline("/* deleting hashtables */");
/* build destructor */
}
}
craux.outputline("free(thisvar);");
- craux.outputline("}");
+ craux.endblock();
}
private void generate_start() {
crhead.outputline("void doanalysis(struct "+name+"_state *);");
craux.outputline("void doanalysis(struct "+name+"_state * thisvar)");
craux.startblock();
+ craux.startBuffer();
if (Compiler.TIME) {
craux.outputline("struct timeval _begin_time,_end_time;");
craux.outputline("gettimeofday(&_begin_time,NULL);");
craux.outputline("rebuildcount=0;");
craux.outputline("abstractcount=0;");
}
- craux.outputline("int highmark;");
- craux.outputline("struct "+name+ " * "+oldmodel.getSafeSymbol()+"=0;");
- craux.outputline("struct WorkList * "+worklist.getSafeSymbol()+" = allocateWorkList();");
- craux.outputline("struct RepairHash * "+repairtable.getSafeSymbol()+"=0;");
+ craux.addDeclaration("int","highmark");
+
+ craux.addDeclaration("struct "+name+ " * ",oldmodel.getSafeSymbol());
+ craux.outputline(oldmodel.getSafeSymbol()+"=0;");
+ craux.addDeclaration("struct WorkList * ",worklist.getSafeSymbol());
+ craux.outputline(worklist.getSafeSymbol()+" = allocateWorkList();");
+ craux.addDeclaration("struct RepairHash * ",repairtable.getSafeSymbol());
+ craux.outputline(repairtable.getSafeSymbol()+"=0;");
craux.outputline("initializestack(&highmark);");
craux.outputline("computesizes(thisvar);");
craux.outputline(name+"_staterecomputesizes(thisvar);");
craux.outputline("while (1)");
craux.startblock();
- craux.outputline("struct "+name+ " * "+newmodel.getSafeSymbol()+"=allocate"+name+"();");
+ craux.addDeclaration("struct "+name+ " * ",newmodel.getSafeSymbol());
+ craux.outputline(newmodel.getSafeSymbol()+"=allocate"+name+"();");
craux.outputline("WorkListreset("+worklist.getSafeSymbol()+");");
if (Compiler.GENERATEINSTRUMENT)
craux.outputline("rebuildcount++;");
cr.startblock();
cr.outputline("/* printing set " + setname+"*/");
cr.outputline("printf(\"\\nPrinting set " + sd.getSymbol() + " - %d elements \\n\", SimpleHashcountset("+setname+"_hash));");
- cr.outputline("struct SimpleIterator __setiterator;");
- cr.outputline("SimpleHashiterator(&"+setname+"_hash,__setiterator);");
+ cr.addDeclaration("struct SimpleIterator","__setiterator");
+ cr.outputline("SimpleHashiterator("+setname+"_hash,&__setiterator);");
cr.outputline("while (hasNext(&__setiterator))");
cr.startblock();
- cr.outputline("int __setval = (int) next(&__setiterator);");
+ cr.addDeclaration("int","__setval");
+ cr.outputline("__setval = (int) next(&__setiterator);");
TypeDescriptor td = sd.getType();
if (td instanceof StructureTypeDescriptor) {
cr.outputline("/* build " +escape(rule.toString())+"*/");
cr.startblock();
- cr.outputline("int maybe=0;");
+ cr.addDeclaration("int","maybe");
+ cr.outputline("maybe=0;");
Expr ruleexpr=rule.getGuardExpr();
HashSet invariantvars=new HashSet();
VarDescriptor tmpvd=VarDescriptor.makeNew("tmpvar");
VarDescriptor maybevd=VarDescriptor.makeNew("maybevar");
invexpr.generate(cr,tmpvd);
- cr.outputline("int "+maybevd.getSafeSymbol()+"=maybe;");
+ cr.addDeclaration("int ",maybevd.getSafeSymbol());
+ cr.outputline(maybevd.getSafeSymbol()+"=maybe;");
cr.outputline("maybe=0;");
ivalue.assignPair(invexpr,tmpvd,maybevd);
openparencount++;
cr2.outputline("while (WorkListhasMoreElements("+worklist.getSafeSymbol()+"))");
cr2.startblock();
VarDescriptor idvar=VarDescriptor.makeNew("id");
- cr2.outputline("int "+idvar.getSafeSymbol()+"=WorkListgetid("+worklist.getSafeSymbol()+");");
+ cr2.addDeclaration("int ",idvar.getSafeSymbol());
+ cr2.outputline(idvar.getSafeSymbol()+"=WorkListgetid("+worklist.getSafeSymbol()+");");
String elseladder = "if";
cr.indent();
cr.outputline(elseladder + " ("+idvar.getSafeSymbol()+" == " + dispatchid + ")");
cr.startblock();
- cr.outputline("int maybe=0;");
+ cr.addDeclaration("int","maybe");
+ cr.outputline("maybe=0;");
VarDescriptor typevar=VarDescriptor.makeNew("type");
VarDescriptor leftvar=VarDescriptor.makeNew("left");
VarDescriptor rightvar=VarDescriptor.makeNew("right");
- cr.outputline("int "+typevar.getSafeSymbol()+"= WorkListgettype("+worklist.getSafeSymbol()+");");
- cr.outputline("int "+leftvar.getSafeSymbol()+"= WorkListgetlvalue("+worklist.getSafeSymbol()+");");
- cr.outputline("int "+rightvar.getSafeSymbol()+"= WorkListgetrvalue("+worklist.getSafeSymbol()+");");
+ cr.addDeclaration("int",typevar.getSafeSymbol());
+ cr.outputline(typevar.getSafeSymbol()+"= WorkListgettype("+worklist.getSafeSymbol()+");");
+ cr.addDeclaration("int",leftvar.getSafeSymbol());
+ cr.outputline(leftvar.getSafeSymbol()+"= WorkListgetlvalue("+worklist.getSafeSymbol()+");");
+ cr.addDeclaration("int",rightvar.getSafeSymbol());
+ cr.outputline(rightvar.getSafeSymbol()+"= WorkListgetrvalue("+worklist.getSafeSymbol()+");");
cr.outputline("/* build " +escape(rule.toString())+"*/");
quantifier.generate_open(cr);
}
- cr.outputline("int maybe = 0;");
+ cr.addDeclaration("int","maybe");
+ cr.outputline("maybe = 0;");
/* now we have to generate the guard test */
dnfconst.addAll((Set)termination.conjunctionmap.get(constraint));
if (dnfconst.size()<=1) {
- cr.outputline("int "+mincostindex.getSafeSymbol()+"=0;");
+ cr.addDeclaration("int",mincostindex.getSafeSymbol());
+ cr.outputline(mincostindex.getSafeSymbol()+"=0;");
}
if (dnfconst.size()>1) {
- cr.outputline("int "+mincostindex.getSafeSymbol()+";");
+ cr.addDeclaration("int",mincostindex.getSafeSymbol());
boolean first=true;
for(int j=0;j<dnfconst.size();j++) {
GraphNode gn=(GraphNode)dnfconst.get(j);
boolean negate=dpred.isNegated();
VarDescriptor predvalue=VarDescriptor.makeNew("Predicatevalue");
p.generate(cr,predvalue);
- if (k==0)
- cr.outputline("int "+costvar.getSafeSymbol()+"=0;");
-
+ if (k==0) {
+ cr.addDeclaration("int",costvar.getSafeSymbol());
+ cr.outputline(costvar.getSafeSymbol()+"=0;");
+ }
if (negate)
cr.outputline("if (maybe||"+predvalue.getSafeSymbol()+")");
else
first=false;
}
}
- cr.outputline("switch("+mincostindex.getSafeSymbol()+") {");
+ cr.outputline("switch("+mincostindex.getSafeSymbol()+")");
+ cr.startblock();
for(int j=0;j<dnfconst.size();j++) {
GraphNode gn=(GraphNode)dnfconst.get(j);
Conjunction conj=((TermNode)gn.getOwner()).getConjunction();
cr.endblock();
cr.outputline("break;");
}
- cr.outputline("}");
+ cr.endblock();
cr.outputline("if ("+oldmodel.getSafeSymbol()+")");
cr.outputline("free"+name+"("+oldmodel.getSafeSymbol()+");");
System.out.println("Warning: need to have individual remove operations for"+dpred.name());
needremoveloop=false;
}
- if (needremoveloop)
- cr.outputline("while (1) {");
-
+ if (needremoveloop) {
+ cr.outputline("while (1)");
+ cr.startblock();
+ }
if (!inverted) {
((RelationExpr)expr.getLeftExpr()).getExpr().generate(cr,leftside);
expr.getRightExpr().generate(cr,newvalue);
- cr.outputline(rd.getRange().getType().getGenerateType().getSafeSymbol()+" "+rightside.getSafeSymbol()+";");
+ cr.addDeclaration(rd.getRange().getType().getGenerateType().getSafeSymbol(),rightside.getSafeSymbol());
cr.outputline("SimpleHashget("+rd.getSafeSymbol()+"_hash,"+leftside.getSafeSymbol()+", &"+rightside.getSafeSymbol()+");");
} else {
((RelationExpr)expr.getLeftExpr()).getExpr().generate(cr,rightside);
if (needremoveloop) {
if (!inverted) {
- cr.outputline("if (SimpleHashcontainskey("+rd.getSafeSymbol()+"_hash, "+leftside.getSafeSymbol()+")) {");
+ cr.outputline("if (SimpleHashcontainskey("+rd.getSafeSymbol()+"_hash, "+leftside.getSafeSymbol()+"))");
+ cr.startblock();
} else {
- cr.outputline("if (SimpleHashcontainskey("+rd.getSafeSymbol()+"_hashinv, "+rightside.getSafeSymbol()+")) {");
+ cr.outputline("if (SimpleHashcontainskey("+rd.getSafeSymbol()+"_hashinv, "+rightside.getSafeSymbol()+"))");
+ cr.startblock();
}
for(int i=0;i<state.vRules.size();i++) {
Rule r=(Rule)state.vRules.get(i);
}
}
cr.outputline("continue;");
- cr.outputline("}");
+ cr.endblock();
}
if (usageimage) {
}
if (needremoveloop) {
cr.outputline("break;");
- cr.outputline("}");
+ cr.endblock();
}
}
VarDescriptor sizevar=VarDescriptor.makeNew("size");
((OpExpr)expr).left.generate(cr, sizevar);
VarDescriptor change=VarDescriptor.makeNew("change");
- cr.outputline("int "+change.getSafeSymbol()+";");
+ cr.addDeclaration("int",change.getSafeSymbol());
boolean generateadd=false;
boolean generateremove=false;
if (opcode==Opcode.GT) {
if (d instanceof RelationDescriptor) {
if (ep.inverted()) {
((ImageSetExpr)((SizeofExpr)expr.left).setexpr).generate_leftside(cr,rightvar);
- cr.outputline("int "+leftvar.getSafeSymbol()+";");
+ cr.addDeclaration("int",leftvar.getSafeSymbol());
cr.outputline("SimpleHashget("+d.getSafeSymbol()+"_hashinv,(int)"+rightvar.getSafeSymbol()+", &"+leftvar.getSafeSymbol()+");");
} else {
((ImageSetExpr)((SizeofExpr)expr.left).setexpr).generate_leftside(cr,leftvar);
- cr.outputline("int "+rightvar.getSafeSymbol()+"=0;");
+ cr.addDeclaration("int",rightvar.getSafeSymbol());
cr.outputline("SimpleHashget("+d.getSafeSymbol()+"_hash ,(int)"+leftvar.getSafeSymbol()+", &"+rightvar.getSafeSymbol()+");");
}
} else {
- cr.outputline("int "+leftvar.getSafeSymbol()+"= SimpleHashfirstkey("+d.getSafeSymbol()+"_hash);");
+ cr.addDeclaration("int",leftvar.getSafeSymbol());
+ cr.outputline(leftvar.getSafeSymbol()+"= SimpleHashfirstkey("+d.getSafeSymbol()+"_hash);");
}
/* Generate abstract remove instruction */
if (d instanceof RelationDescriptor) {
/* Set Source */
SetDescriptor sd=termination.sources.relgetSourceSet(rd,!ep.inverted());
VarDescriptor iterator=VarDescriptor.makeNew("iterator");
- cr.outputline(sd.getType().getGenerateType().getSafeSymbol() +" "+newobject.getSafeSymbol()+";");
- cr.outputline("struct SimpleIterator "+iterator.getSafeSymbol()+";");
- cr.outputline("for(SimpleHashiterator(& "+sd.getSafeSymbol()+"_hash ,"+ iterator.getSafeSymbol() +");"+iterator.getSafeSymbol()+".hasNext();)");
+ cr.addDeclaration(sd.getType().getGenerateType().getSafeSymbol(),newobject.getSafeSymbol());
+ cr.addDeclaration("struct SimpleIterator",iterator.getSafeSymbol());
+ cr.outputline("for(SimpleHashiterator("+sd.getSafeSymbol()+"_hash , &"+ iterator.getSafeSymbol() +"); hasNext(&"+iterator.getSafeSymbol()+");)");
cr.startblock();
if (ep.inverted()) {
cr.outputline("if (!SimpleHashcontainskeydata("+rd.getSafeSymbol()+"_hashinv,"+iterator.getSafeSymbol()+".key(),"+otherside.getSafeSymbol()+"))");
} else {
cr.outputline("if (!SimpleHashcontainskeydata("+rd.getSafeSymbol()+"_hash, "+otherside.getSafeSymbol()+","+iterator.getSafeSymbol()+".key()))");
}
- cr.outputline(newobject.getSafeSymbol()+"=key("+iterator.getSafeSymbol()+");");
- cr.outputline("next("+iterator.getSafeSymbol()+");");
+ cr.outputline(newobject.getSafeSymbol()+"=key(&"+iterator.getSafeSymbol()+");");
+ cr.outputline("next(&"+iterator.getSafeSymbol()+");");
cr.endblock();
} else if (termination.sources.relallocSource(rd,!ep.inverted())) {
/* Allocation Source*/
/* Set Source */
SetDescriptor sourcesd=termination.sources.getSourceSet(sd);
VarDescriptor iterator=VarDescriptor.makeNew("iterator");
- cr.outputline(sourcesd.getType().getGenerateType().getSafeSymbol() +" "+newobject.getSafeSymbol()+";");
- cr.outputline("SimpleIterator "+iterator.getSafeSymbol()+";");
- cr.outputline("for(SimpleHashiterator("+sourcesd.getSafeSymbol()+"_hash, "+iterator.getSafeSymbol()+");"+iterator.getSafeSymbol()+".hasNext();)");
+ cr.addDeclaration(sourcesd.getType().getGenerateType().getSafeSymbol(), newobject.getSafeSymbol());
+ cr.addDeclaration("struct SimpleIterator",iterator.getSafeSymbol());
+ cr.outputline("for(SimpleHashiterator("+sourcesd.getSafeSymbol()+"_hash, &"+iterator.getSafeSymbol()+"); hasNext(&"+iterator.getSafeSymbol()+");)");
cr.startblock();
- cr.outputline("if (!SimpleHashcontainskey("+sd.getSafeSymbol()+"_hash, key("+iterator.getSafeSymbol()+")))");
- cr.outputline(newobject.getSafeSymbol()+"=key("+iterator.getSafeSymbol()+");");
- cr.outputline("next("+iterator.getSafeSymbol()+");");
+ cr.outputline("if (!SimpleHashcontainskey("+sd.getSafeSymbol()+"_hash, key(&"+iterator.getSafeSymbol()+")))");
+ cr.outputline(newobject.getSafeSymbol()+"=key(&"+iterator.getSafeSymbol()+");");
+ cr.outputline("next(&"+iterator.getSafeSymbol()+");");
cr.endblock();
} else if (termination.sources.allocSource(sd)) {
/* Allocation Source*/
/* Have update to call into */
VarDescriptor mdfyptr=VarDescriptor.makeNew("modifyptr");
VarDescriptor ismdfyptr=VarDescriptor.makeNew("ismodifyptr");
- cr.outputline("int "+ismdfyptr.getSafeSymbol()+"=RepairHashismodify("+repairtable.getSafeSymbol()+","+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
+ cr.addDeclaration("int ",ismdfyptr.getSafeSymbol());
+ cr.outputline(ismdfyptr.getSafeSymbol()+"=RepairHashismodify("+repairtable.getSafeSymbol()+","+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
else
parttype=parttype+", int";
}
- VarDescriptor funptr=VarDescriptor.makeNew("updateptr");
+
VarDescriptor tmpptr=VarDescriptor.makeNew("tempupdateptr");
- String methodcall="("+funptr.getSafeSymbol()+") (thisvar,"+oldmodel.getSafeSymbol()+","+repairtable.getSafeSymbol();
+ String methodcall="(thisvar,"+oldmodel.getSafeSymbol()+","+repairtable.getSafeSymbol();
for(int i=0;i<currentrule.numQuantifiers();i++) {
Quantifier q=currentrule.getQuantifier(i);
if (q instanceof SetQuantifier) {
- cr.outputline("void *"+tmpptr.getSafeSymbol()+"=");
+ cr.addDeclaration("void *",tmpptr.getSafeSymbol());
+ cr.outputline(tmpptr.getSafeSymbol()+"=");
cr.outputline("(void *) RepairHashgetrelation("+repairtable.getSafeSymbol()+","+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
cr.outputline("if ("+ismdfyptr.getSafeSymbol()+")");
{
+ VarDescriptor funptr=VarDescriptor.makeNew("updateptr");
+ String methodcallprefix="("+funptr.getSafeSymbol()+") ";
cr.startblock();
- cr.outputline("int "+mdfyptr.getSafeSymbol()+"=RepairHashgetrelation2("+repairtable.getSafeSymbol()+","+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
- cr.outputline("void (*"+funptr.getSafeSymbol()+") (struct "+name+"_state *, struct "+name+"*, struct RepairHash *"+parttype+",int,int,int)="+"(void (*) (struct "+name+"_state *, struct "+name+"*, struct RepairHash *"+parttype+",int,int,int)) "+tmpptr.getSafeSymbol()+";");
- cr.outputline(methodcall+","+leftvar+", "+rightvar+", "+mdfyptr.getSafeSymbol() +");");
+ cr.addDeclaration("int",mdfyptr.getSafeSymbol());
+ cr.outputline(mdfyptr.getSafeSymbol()+"=RepairHashgetrelation2("+repairtable.getSafeSymbol()+","+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
+ cr.addDeclaration("void (*"+funptr.getSafeSymbol()+") (struct "+name+"_state *, struct "+name+"*, struct RepairHash *"+parttype+",int,int,int);");
+ cr.outputline(funptr.getSafeSymbol()+"="+"(void (*) (struct "+name+"_state *, struct "+name+"*, struct RepairHash *"+parttype+",int,int,int)) "+tmpptr.getSafeSymbol()+";");
+ cr.outputline(methodcallprefix+methodcall+","+leftvar+", "+rightvar+", "+mdfyptr.getSafeSymbol() +");");
cr.endblock();
}
cr.outputline("else ");
{
+ VarDescriptor funptr=VarDescriptor.makeNew("updateptr");
+ String methodcallprefix="("+funptr.getSafeSymbol()+") ";
cr.startblock();
- cr.outputline("void (*"+funptr.getSafeSymbol()+") (struct "+name+"_state *, struct "+name+"*,struct RepairHash *"+parttype+")="+"(void (*) (struct "+name+"_state *,struct "+name+"*,struct RepairHash *"+parttype+")) "+tmpptr.getSafeSymbol()+";");
- cr.outputline(methodcall+");");
+ cr.addDeclaration("void (*"+funptr.getSafeSymbol()+") (struct "+name+"_state *, struct "+name+"*,struct RepairHash *"+parttype+");");
+ cr.outputline(funptr.getSafeSymbol()+"="+"(void (*) (struct "+name+"_state *,struct "+name+"*,struct RepairHash *"+parttype+")) "+tmpptr.getSafeSymbol()+";");
+ cr.outputline(methodcallprefix+methodcall+");");
cr.endblock();
}
cr.outputline("free"+name+"("+newmodel.getSafeSymbol()+");");
String addeditem = (VarDescriptor.makeNew("addeditem")).getSafeSymbol();
cr.startblock();
- cr.outputline("int " + addeditem + "=0;");
+ cr.addDeclaration("int" , addeditem);
+ cr.outputline(addeditem + "=0;");
String ifstring="if (!maybe";
if (rd.getDomain().getType() instanceof StructureTypeDescriptor) {
else
parttype=parttype+", int";
}
- cr.outputline("void (*"+funptr.getSafeSymbol()+") (struct "+name+"_state *,struct "+name+"*,struct RepairHash *"+parttype+")=");
+ cr.addDeclaration("void (*"+funptr.getSafeSymbol()+") (struct "+name+"_state *,struct "+name+"*,struct RepairHash *"+parttype+");");
+ cr.outputline(funptr.getSafeSymbol()+"=");
cr.outputline("(void (*) (struct "+name+"_state *,struct "+name+"*,struct RepairHash *"+parttype+")) RepairHashgetset("+repairtable.getSafeSymbol()+","+sd.getNum()+","+currentrule.getNum()+","+setvar+");");
String methodcall="("+funptr.getSafeSymbol()+") (thisvar,"+oldmodel.getSafeSymbol()+","+
repairtable.getSafeSymbol();
cr.startblock();
String addeditem = (VarDescriptor.makeNew("addeditem")).getSafeSymbol();
- cr.outputline("int " + addeditem + " = 0;");
+ cr.addDeclaration("int", addeditem);
+ cr.outputline(addeditem + " = 0;");
if (sd.getType() instanceof StructureTypeDescriptor) {
cr.outputline("if (!maybe&&"+setvar+")");
} else
}
public void generate_inclusion(CodeWriter writer, VarDescriptor dest, VarDescriptor element) {
- writer.outputline("int " + dest.getSafeSymbol() + " = SimpleHashcontainskey(" +sd.getSafeSymbol()+ "_hash, "+element.getSafeSymbol() + ");");
+ writer.addDeclaration("int", dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol() + " = SimpleHashcontainskey(" +sd.getSafeSymbol()+ "_hash, "+element.getSafeSymbol() + ");");
}
public void generate_size(CodeWriter writer, VarDescriptor dest) {
- writer.outputline("int " + dest.getSafeSymbol() + " = SimpleHashcountset("+sd.getSafeSymbol()+"_hash);");
+ writer.addDeclaration("int", dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol() + " = SimpleHashcountset("+sd.getSafeSymbol()+"_hash);");
}
public void prettyPrint(PrettyPrinter pp) {
}
public void generate_open(CodeWriter writer) {
- writer.outputline("struct SimpleIterator "+var.getSafeSymbol()+"_iterator;");
+ writer.addDeclaration("struct SimpleIterator",var.getSafeSymbol()+"_iterator");
writer.outputline("for (SimpleHashiterator("+set.getSafeSymbol()+"_hash, & "+ var.getSafeSymbol()+"_iterator); hasNext(&"+var.getSafeSymbol()+"_iterator); )");
writer.startblock();
- writer.outputline(var.getType().getGenerateType() + " " + var.getSafeSymbol() + " = (" + var.getType().getGenerateType() + ") next(&"+var.getSafeSymbol()+"_iterator);");
+ writer.addDeclaration(var.getType().getGenerateType().toString(), var.getSafeSymbol());
+ writer.outputline(var.getSafeSymbol() + " = (" + var.getType().getGenerateType() + ") next(&"+var.getSafeSymbol()+"_iterator);");
}
public void generate_open(CodeWriter writer, String type,int number, String left,String right) {
VarDescriptor tmp=VarDescriptor.makeNew("flag");
- writer.outputline("struct SimpleIterator "+var.getSafeSymbol()+"_iterator;");
+ writer.addDeclaration("struct SimpleIterator",var.getSafeSymbol()+"_iterator");
writer.outputline("SimpleHashiterator("+set.getSafeSymbol()+"_hash, &"+var.getSafeSymbol()+"_iterator);");
- writer.outputline("int "+tmp.getSafeSymbol()+"=0;");
+ writer.addDeclaration("int",tmp.getSafeSymbol());
+ writer.outputline(tmp.getSafeSymbol()+"=0;");
writer.outputline("if ("+type+"=="+number+")");
writer.outputline(tmp.getSafeSymbol()+"=1;");
writer.outputline("while("+tmp.getSafeSymbol()+"||(("+type+"!="+number+")&&hasNext(&"+var.getSafeSymbol()+"_iterator)))");
writer.startblock();
- writer.outputline(var.getType().getGenerateType() + " " + var.getSafeSymbol() + ";");
+ writer.addDeclaration(var.getType().getGenerateType().toString(), var.getSafeSymbol());
writer.outputline("if ("+type+"=="+number+")");
writer.startblock();
writer.outputline(tmp.getSafeSymbol()+"=0;");
public int generate_worklistload(CodeWriter writer, int offset) {
String varname = var.getSafeSymbol();
- writer.outputline("int " + varname + " = wi->word" + offset + ";");
+ writer.addDeclaration("int", varname);
+ writer.outputline(varname + " = wi->word" + offset + ";");
return offset + 1;
}
// is expand the guard of the rule and if its true then its 1 otherwise 0
String destname = dest.getSafeSymbol();
- cr.outputline("int " + destname + ";");
+ cr.addDeclaration("int", destname);
// ok... destination is declared... we gotta expand this rule inplace... and instead of the inclusion we
// set the destination in the guard ... otherwise maybe!
String tempvar = (VarDescriptor.makeNew("tempvar")).getSafeSymbol();
// this is to be safe about name overlap because int t = t; sets t to 0!
- cr.outputline("int " + tempvar + " = " + domain.getSafeSymbol() + ";");
- cr.outputline("int " + rulebinding.getSafeSymbol() + " = " + tempvar + ";");
+ cr.addDeclaration("int", tempvar);
+ cr.outputline(tempvar + " = " + domain.getSafeSymbol() + ";");
+ cr.addDeclaration("int", rulebinding.getSafeSymbol());
+ cr.outputline(rulebinding.getSafeSymbol() + " = " + tempvar + ";");
/* pretty print! */
cr.outputline("/* about to inbed relational function*/");
cr.pushSymbolTable(state.stGlobals);
e.generate(cr, size);
cr.popSymbolTable();
- cr.outputline(td.getGenerateType().getSafeSymbol()+" "+vd.getSafeSymbol()+"=("+td.getGenerateType().getSafeSymbol()+") calloc(1,"+size.getSafeSymbol()+");");
+ cr.addDeclaration(td.getGenerateType().getSafeSymbol(), vd.getSafeSymbol());
+ cr.outputline(vd.getSafeSymbol()+"=("+td.getGenerateType().getSafeSymbol()+") calloc(1,"+size.getSafeSymbol()+");");
cr.outputline("alloc((void *) "+vd.getSafeSymbol()+","+size.getSafeSymbol()+");");
if (Compiler.ALLOCATECPLUSPLUS) {
if (td instanceof StructureTypeDescriptor) {
import java.util.*;
-public class StandardCodeWriter implements CodeWriter {
+public class StandardCodeWriter implements CodeWriter {
boolean linestarted = false;
- int indent = 0;
- java.io.PrintWriter output;
+ PrintWrapper output;
Stack symboltables = new Stack();
InvariantValue ivalue;
- public StandardCodeWriter(java.io.PrintWriter output) { this.output = output; }
+ public StandardCodeWriter(PrintWrapper output) { this.output = output; }
+ public StandardCodeWriter(java.io.PrintWriter output) { this.output = new PrintWrapper(output);}
+
+ public void startBuffer() {
+ output.startBuffer();
+ }
+ public void emptyBuffer() {
+ output.emptyBuffer();
+ }
public void startblock() {
indent();
outputline("}");
unindent();
}
-
- public void indent() {
- indent++;
+ public void addDeclaration(String type, String varname) {
+ output.addDeclaration(type,varname);
}
-
- public void unindent() {
- indent--;
+ public void addDeclaration(String f) {
+ output.addDeclaration(f);
}
+ public void indent() {
+ output.indent++;
+ }
+
+ public void unindent() {
+ output.indent--;
+ }
+
private void doindent() {
- for (int i = 0; i < indent; i++) {
+ for (int i = 0; i < output.indent; i++) {
output.print(" ");
}
linestarted = true;
}
-
+
public void outputline(String s) {
if (!linestarted) {
doindent();
output.println(s);
linestarted = false;
output.flush();
- }
-
+ }
+
public void output(String s) {
if (!linestarted) {
doindent();
}
output.print(s);
- output.flush();
+ output.flush();
}
public void pushSymbolTable(SymbolTable st) {
return (SymbolTable) symboltables.pop();
}
- public SymbolTable getSymbolTable() {
+ public SymbolTable getSymbolTable() {
if (symboltables.empty()) {
- throw new IRException();
+ throw new IRException();
}
return (SymbolTable) symboltables.peek();
}
str+="};";
cr.outputline(str);
} else
- cr.outputline("int arnumelement"+ttd.getId()+"[0];");
+ cr.outputline("int arnumelement"+ttd.getId()+"[1];"); // c doesn't like 0 length arrays
}
String str="int* arnumelements["+String.valueOf(max)+"]={";
for(int i=0;i<max;i++) {
str+="};";
cr.outputline(str);
} else
- cr.outputline("int argetfield"+ttd.getId()+"[0];");
+ cr.outputline("int argetfield"+ttd.getId()+"[1];"); //c doesn't like zero length arrays
}
int max=TypeDescriptor.counter;
String str="int* argetfield["+String.valueOf(max)+"]={";
str+="};";
cr.outputline(str);
} else
- cr.outputline("int arisArray"+ttd.getId()+"[0];");
+ cr.outputline("int arisArray"+ttd.getId()+"[1];"); // c doesn't like 0 length arrays
}
int max=TypeDescriptor.counter;
String str="int* arisArray["+String.valueOf(max)+"]={";
str+="};";
cr.outputline(str);
} else
- cr.outputline("int arisPtr"+ttd.getId()+"[0];");
+ cr.outputline("int arisPtr"+ttd.getId()+"[1];"); // c doesn't like 0 length arrays
}
int max=TypeDescriptor.counter;
String str="int* arisPtr["+String.valueOf(max)+"]={";
}
public void generate(CodeWriter writer, VarDescriptor dest) {
- writer.outputline("int "+dest.getSafeSymbol()+"=0;");
+ writer.addDeclaration("int",dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol()+"=0;");
+
VarDescriptor itvd=VarDescriptor.makeNew("iterator");
- writer.outputline("struct SimpleIterator "+itvd.getSafeSymbol()+";");
+ writer.addDeclaration("struct SimpleIterator",itvd.getSafeSymbol());
writer.outputline("SimpleHashiterator("+sd.getSafeSymbol()+"_hash , &"+itvd.getSafeSymbol()+");");
writer.outputline("while (hasNext(&"+itvd.getSafeSymbol()+")) {");
VarDescriptor keyvd=VarDescriptor.makeNew("key");
- writer.outputline("int "+keyvd.getSafeSymbol()+"=next(&"+itvd.getSafeSymbol()+");");
+ writer.addDeclaration("int",keyvd.getSafeSymbol());
+ writer.outputline(keyvd.getSafeSymbol()+"=next(&"+itvd.getSafeSymbol()+");");
VarDescriptor tmpvar=VarDescriptor.makeNew("tmp");
- writer.outputline("int "+tmpvar.getSafeSymbol()+";");
+ writer.addDeclaration("int",tmpvar.getSafeSymbol());
writer.outputline("SimpleHashget("+rd.getSafeSymbol()+"_hash, "+keyvd.getSafeSymbol()+", &"+tmpvar.getSafeSymbol()+");");
writer.outputline(dest.getSafeSymbol()+"+="+tmpvar.getSafeSymbol()+";");
writer.outputline("}");
}
public void generate(CodeWriter writer, VarDescriptor dest) {
- writer.outputline("int " + dest.getSafeSymbol() + " = " + num.toString().toString() + ";");
+ writer.addDeclaration("int", dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol() + " = " + num.toString().toString() + ";");
}
public void prettyPrint(PrettyPrinter pp) {
VarDescriptor rd = VarDescriptor.makeNew();
right.generate(writer, rd);
- writer.outputline("int " + dest.getSafeSymbol() + " = SimpleHashcontainskeydata("
+ writer.addDeclaration("int", dest.getSafeSymbol());
+
+ writer.outputline(dest.getSafeSymbol() + " = SimpleHashcontainskeydata("
+relation.getSafeSymbol() +"_hash, "+
ld.getSafeSymbol() + ", " +
rd.getSafeSymbol() + ");");
break;
case Updates.POSITION:
case Updates.ACCESSPATH:
- if (u.getRightPos()==0)
- cr.outputline("int "+right.getSafeSymbol()+"="+slot0+";");
- else if (u.getRightPos()==1)
- cr.outputline("int "+right.getSafeSymbol()+"="+slot1+";");
- else if (u.getRightPos()==2)
- cr.outputline("int "+right.getSafeSymbol()+"="+slot2+";");
- else throw new Error("Error w/ Position");
+ if (u.getRightPos()==0) {
+ cr.addDeclaration("int", right.getSafeSymbol());
+ cr.outputline(right.getSafeSymbol()+"="+slot0+";");
+ } else if (u.getRightPos()==1) {
+ cr.addDeclaration("int", right.getSafeSymbol());
+ cr.outputline(right.getSafeSymbol()+"="+slot1+";");
+ } else if (u.getRightPos()==2) {
+ cr.addDeclaration("int", right.getSafeSymbol());
+ cr.outputline(right.getSafeSymbol()+"="+slot2+";");
+ } else throw new Error("Error w/ Position");
break;
default:
throw new Error();
ArrayAnalysis.AccessPath ap=u.getAccessPath();
VarDescriptor init=VarDescriptor.makeNew("init");
if (ap.isSet()) {
- cr.outputline("int "+init.getSafeSymbol()+"= SimpleHashfirstkey("+ap.getSet().getSafeSymbol()+"_hash);");
+ cr.addDeclaration("int", init.getSafeSymbol());
+ cr.outputline(init.getSafeSymbol()+"= SimpleHashfirstkey("+ap.getSet().getSafeSymbol()+"_hash);");
init.td=ap.getSet().getType();
} else {
init=ap.getVar();
if (b.getType()==Binding.SEARCH) {
VarDescriptor vd=b.getVar();
- cr.outputline(vd.getType().getGenerateType().getSafeSymbol()+" "+vd.getSafeSymbol()+"=SimpleHashfirstkey("+b.getSet().getSafeSymbol()+"_hash);");
+ cr.addDeclaration(vd.getType().getGenerateType().getSafeSymbol(), vd.getSafeSymbol());
+ cr.outputline(vd.getSafeSymbol()+"=SimpleHashfirstkey("+b.getSet().getSafeSymbol()+"_hash);");
} else if (b.getType()==Binding.CREATE) {
throw new Error("Creation not supported");
// source.generateSourceAlloc(cr,vd,b.getSet());
VarDescriptor vd=b.getVar();
switch(b.getPosition()) {
case 0:
- cr.outputline(vd.getType().getGenerateType().getSafeSymbol()+" "+vd.getSafeSymbol()+"="+slot0+";");
+ cr.addDeclaration(vd.getType().getGenerateType().getSafeSymbol(), vd.getSafeSymbol());
+ cr.outputline(vd.getSafeSymbol()+"="+slot0+";");
break;
case 1:
- cr.outputline(vd.getType().getGenerateType().getSafeSymbol()+" "+vd.getSafeSymbol()+"="+slot1+";");
+ cr.addDeclaration(vd.getType().getGenerateType().getSafeSymbol(), vd.getSafeSymbol());
+ cr.outputline(vd.getSafeSymbol()+"="+slot1+";");
break;
default:
throw new Error("Slot >1 doesn't exist.");
if (writer.getInvariantValue()!=null&&
writer.getInvariantValue().isInvariant(this)) {
- writer.outputline(vd.getType().getGenerateType().getSafeSymbol()+
- " "+dest.getSafeSymbol()+"="+writer.getInvariantValue().getValue(this).getSafeSymbol()+";");
+ writer.addDeclaration(vd.getType().getGenerateType().getSafeSymbol(),dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol()+"="+writer.getInvariantValue().getValue(this).getSafeSymbol()+";");
writer.outputline("maybe="+writer.getInvariantValue().getMaybe(this).getSafeSymbol()+";");
return;
}
- writer.outputline(vd.getType().getGenerateType().getSafeSymbol() + " " + dest.getSafeSymbol() +
+ writer.addDeclaration(vd.getType().getGenerateType().getSafeSymbol(),dest.getSafeSymbol());
+ writer.outputline(dest.getSafeSymbol() +
" = (" + 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
- writer.outputline("bool "+typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + td.getId() + ");");
+ if (DOTYPECHECKS) {
+ writer.addDeclaration("bool",typevar.getSafeSymbol());
+ writer.outputline(typevar.getSafeSymbol()+"=assertvalidtype(" + dest.getSafeSymbol() + ", " + td.getId() + ");");
+ } else {
+ writer.addDeclaration("bool",typevar.getSafeSymbol());
+ writer.outputline(typevar.getSafeSymbol()+"=assertvalidmemory(" + dest.getSafeSymbol() + ", " + td.getId() + ");");
+ }
writer.outputline("if (!"+typevar.getSafeSymbol()+")");
writer.startblock();
writer.outputline(dest.getSafeSymbol()+"=0;");