1) Generate C99 code instead of C++ code. The code should still work with a C++ compiler.
2) PrintWrapper class to enable putting declarations at top of
functions so we can make old versions of gcc work.
}
/* SIMPLE HASH ********************************************************/
-struct SimpleIterator* createiterator(struct SimpleHash * thisvar) {
+struct SimpleIterator* SimpleHashcreateiterator(struct SimpleHash * thisvar) {
return allocateSimpleIterator(thisvar->listhead,thisvar->listtail,thisvar->tailindex/*,thisvar*/);
}
-void iterator(struct SimpleHash *thisvar, struct SimpleIterator * it) {
+void SimpleHashiterator(struct SimpleHash *thisvar, struct SimpleIterator * it) {
it->cur=thisvar->listhead;
it->index=0;
it->tailindex=thisvar->tailindex;
#define SETFLAG (1<<31)
-int addset(struct RepairHash *thisvar, int setv, int rule, int value, int data) {
- return addrelation(thisvar, setv||SETFLAG, rule, value,0,data);
+int RepairHashaddset(struct RepairHash *thisvar, int setv, int rule, int value, int data) {
+ return RepairHashaddrelation(thisvar, setv||SETFLAG, rule, value,0,data);
}
-int addrelation(struct RepairHash *thisvar, int relation, int rule, int lvalue, int rvalue, int data) {
+int RepairHashaddrelation(struct RepairHash *thisvar, int relation, int rule, int lvalue, int rvalue, int data) {
unsigned int hashkey = ((unsigned int)(relation ^ rule ^ lvalue ^ rvalue)) % thisvar->size;
struct RepairHashNode **ptr = &thisvar->bucket[hashkey];
return 1;
}
-int addrelation2(struct RepairHash *thisvar, int relation, int rule, int lvalue, int rvalue, int data, int data2) {
+int RepairHashaddrelation2(struct RepairHash *thisvar, int relation, int rule, int lvalue, int rvalue, int data, int data2) {
unsigned int hashkey = ((unsigned int)(relation ^ rule ^ lvalue ^ rvalue)) % thisvar->size;
struct RepairHashNode **ptr = &thisvar->bucket[hashkey];
return 1;
}
-bool containsset(struct RepairHash *thisvar, int setv, int rule, int value) {
- return containsrelation(thisvar, setv||SETFLAG, rule, value,0);
+bool RepairHashcontainsset(struct RepairHash *thisvar, int setv, int rule, int value) {
+ return RepairHashcontainsrelation(thisvar, setv||SETFLAG, rule, value,0);
}
-bool containsrelation(struct RepairHash *thisvar, int relation, int rule, int lvalue, int rvalue) {
+bool RepairHashcontainsrelation(struct RepairHash *thisvar, int relation, int rule, int lvalue, int rvalue) {
unsigned int hashkey = ((unsigned int)(relation ^ rule ^ lvalue ^ rvalue)) % thisvar->size;
struct RepairHashNode **ptr = &thisvar->bucket[hashkey];
return false;
}
-int getset(struct RepairHash *thisvar, int setv, int rule, int value) {
- return getrelation(thisvar, setv||SETFLAG, rule, value,0);
+int RepairHashgetset(struct RepairHash *thisvar, int setv, int rule, int value) {
+ return RepairHashgetrelation(thisvar, setv||SETFLAG, rule, value,0);
}
-int ismodify(struct RepairHash *thisvar, int relation, int rule, int lvalue,int rvalue) {
+int RepairHashismodify(struct RepairHash *thisvar, int relation, int rule, int lvalue,int rvalue) {
unsigned int hashkey = ((unsigned int)(relation ^ rule ^ lvalue ^ rvalue)) % thisvar->size;
struct RepairHashNode **ptr = &thisvar->bucket[hashkey];
return 0;
}
-int getrelation2(struct RepairHash *thisvar, int relation, int rule, int lvalue,int rvalue) {
+int RepairHashgetrelation2(struct RepairHash *thisvar, int relation, int rule, int lvalue,int rvalue) {
unsigned int hashkey = ((unsigned int)(relation ^ rule ^ lvalue ^ rvalue)) % thisvar->size;
struct RepairHashNode **ptr = &thisvar->bucket[hashkey];
return 0;
}
-int getrelation(struct RepairHash *thisvar, int relation, int rule, int lvalue,int rvalue) {
+int RepairHashgetrelation(struct RepairHash *thisvar, int relation, int rule, int lvalue,int rvalue) {
unsigned int hashkey = ((unsigned int)(relation ^ rule ^ lvalue ^ rvalue)) % thisvar->size;
struct RepairHashNode **ptr = &thisvar->bucket[hashkey];
int SimpleHashcountdata(struct SimpleHash *,int data);
void SimpleHashaddParent(struct SimpleHash *,struct SimpleHash* parent);
int SimpleHashfirstkey(struct SimpleHash *);
-struct SimpleIterator* SimpleHashcreateiterator(struct SimpleHash *, struct SimpleHash *);
+struct SimpleIterator* SimpleHashcreateiterator(struct SimpleHash *);
void SimpleHashiterator(struct SimpleHash *, struct SimpleIterator * it);
int SimpleHashcount(struct SimpleHash *, int key);
void SimpleHashaddAll(struct SimpleHash *, struct SimpleHash * set);
int tailindex;
};
-inline int count(struct SimpleHash * thisvar) {
+inline int SimpleHashcountset(struct SimpleHash * thisvar) {
return thisvar->numelements;
}
struct RepairHash * noargallocateRepairHash();
struct RepairHash * allocateRepairHash(int size);
void freeRepairHash(struct RepairHash *);
-int addset(struct RepairHash *, int setv, int rule, int value, int data);
-int addrelation(struct RepairHash *, int relation, int rule, int lvalue, int rvalue, int data);
-int addrelation2(struct RepairHash *, int relation, int rule, int lvalue, int rvalue, int data, int data2);
-bool containsset(struct RepairHash *, int setv, int rule, int value);
-bool containsrelation(struct RepairHash *, int relation, int rule, int lvalue, int rvalue);
-int getset(struct RepairHash *, int setv, int rule, int value);
-int getrelation(struct RepairHash *, int relation, int rule, int lvalue, int rvalue);
-int getrelation2(struct RepairHash *, int relation, int rule, int lvalue, int rvalue);
-int ismodify(struct RepairHash *, int relation, int rule, int lvalue, int rvalue);
+int RepairHashaddset(struct RepairHash *, int setv, int rule, int value, int data);
+int RepairHashaddrelation(struct RepairHash *, int relation, int rule, int lvalue, int rvalue, int data);
+int RepairHashaddrelation2(struct RepairHash *, int relation, int rule, int lvalue, int rvalue, int data, int data2);
+bool RepairHashcontainsset(struct RepairHash *, int setv, int rule, int value);
+bool RepairHashcontainsrelation(struct RepairHash *, int relation, int rule, int lvalue, int rvalue);
+int RepairHashgetset(struct RepairHash *, int setv, int rule, int value);
+int RepairHashgetrelation(struct RepairHash *, int relation, int rule, int lvalue, int rvalue);
+int RepairHashgetrelation2(struct RepairHash *, int relation, int rule, int lvalue, int rvalue);
+int RepairHashismodify(struct RepairHash *, int relation, int rule, int lvalue, int rvalue);
struct RepairHash {
int numelements;
-struct foo_state {int l;};
+#include "specs/x86/cache_aux.h"
int getfield(int type, int fieldindex);
int isArray(int type, int fieldindex);
int isPtr(int type, int fieldindex);
* <ul>
* <li>
* nothing.
- * </li>
+ * </li>
* <ul>
*
* @author <b>Daniel Roy</b> droy (at) mit (dot) edu
- * @version %I, %G
+ * @version %I, %G
*/
public class Compiler {
public static boolean GENERATEINSTRUMENT=false;
public static boolean ALLOCATECPLUSPLUS=false;
public static boolean TIME=false;
-
+
public static Vector debuggraphs=new Vector();
public static void main(String[] args) {
System.err.println("\nError: no input file specified");
System.exit(-1);
}
-
+
if (state.debug) {
System.out.println("Compiling " + cli.infile + ".");
}
-
+
success = scan(state) || error(state, "Scanning failed, not attempting to parse.");
success = parse(state) || error(state, "Parsing failed, not attempting semantic analysis.");
success = semantics(state) || error(state, "Semantic analysis failed, not attempting variable initialization.");
-
-
+
+
state.setanalysis=new SetAnalysis(state);
Termination termination=null;
/* Check partition constraints */
(new ImplicitSchema(state)).update();
termination=new Termination(state);
-
+
state.printall();
(new DependencyBuilder(state)).calculate();
-
+
try {
Vector nodes = new Vector(state.constraintnodes.values());
nodes.addAll(state.rulenodes.values());
-
+
FileOutputStream dotfile;
dotfile = new FileOutputStream(cli.infile + ".dependencies.edgelabels.dot");
GraphNode.useEdgeLabels = true;
GraphNode.DOTVisitor.visit(dotfile, nodes);
dotfile.close();
-
+
dotfile = new FileOutputStream(cli.infile + ".dependencies.dot");
GraphNode.useEdgeLabels = false;
- GraphNode.DOTVisitor.visit(dotfile, nodes);
+ GraphNode.DOTVisitor.visit(dotfile, nodes);
dotfile.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
-
+
try {
- FileOutputStream gcode = new FileOutputStream(cli.infile + ".cc");
-
-
+ FileOutputStream gcode = new FileOutputStream(cli.infile + ".c");
+
+
// do model optimizations
//(new Optimizer(state)).optimize();
-
- FileOutputStream gcode2 = new FileOutputStream(cli.infile + "_aux.cc");
+
+ FileOutputStream gcode2 = new FileOutputStream(cli.infile + "_aux.c");
FileOutputStream gcode3 = new FileOutputStream(cli.infile + "_aux.h");
RepairGenerator wg = new RepairGenerator(state,termination);
wg.generate(gcode,gcode2,gcode3, cli.infile + "_aux.h");
e.printStackTrace();
System.exit(-1);
}
-
+
if (state.debug) {
System.out.println("Compilation of " + state.infile + " successful.");
System.out.println("#SUCCESS#");
}
public static boolean parse(State state) {
-
+
/* parse structure file */
try {
debugMessage(1, "Parsing structure file");
return false;
}
- boolean success =
- !CUP$TDLParser$actions.errors &&
- !CUP$SDLParser$actions.errors &&
- !CUP$CDLParser$actions.errors &&
+ boolean success =
+ !CUP$TDLParser$actions.errors &&
+ !CUP$SDLParser$actions.errors &&
+ !CUP$CDLParser$actions.errors &&
!CUP$MDLParser$actions.errors;
-
+
// if verbosity is on, then output parse trees as .dot files
if (success && state.verbose > 0) {
try {
FileOutputStream dotfile;
dotfile = new FileOutputStream(state.infile + ".struct.dot");
- ParseNodeDOTVisitor.visit(dotfile, state.ptStructures);
+ ParseNodeDOTVisitor.visit(dotfile, state.ptStructures);
dotfile.close();
dotfile = new FileOutputStream(state.infile + ".model.dot");
- ParseNodeDOTVisitor.visit(dotfile, state.ptModel);
+ ParseNodeDOTVisitor.visit(dotfile, state.ptModel);
dotfile.close();
dotfile = new FileOutputStream(state.infile + ".space.dot");
- ParseNodeDOTVisitor.visit(dotfile, state.ptSpace);
+ ParseNodeDOTVisitor.visit(dotfile, state.ptSpace);
dotfile.close();
dotfile = new FileOutputStream(state.infile + ".constraints.dot");
- ParseNodeDOTVisitor.visit(dotfile, state.ptConstraints);
+ ParseNodeDOTVisitor.visit(dotfile, state.ptConstraints);
dotfile.close();
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
-
+
return success;
}
System.err.println("Unable to open file: " + filename);
System.exit(-1);
}
-
+
lexer = new Lexer(infile);
-
+
try {
while (true) {
java_cup.runtime.Symbol symbol;
-
+
symbol = lexer.next_token();
-
+
if (symbol.sym == Sym.EOF) {
break;
} else if (symbol.sym == Sym.BAD) {
errors = true;
}
-
+
if (State.verbose > 2) {
System.out.println("Got token: " + symbol.value);
}
}
-
import MCC.Compiler;
public class DotExpr extends Expr {
-
+
Expr left;
String field;
Expr index;
-
+
static boolean DOMEMCHECKS=false;
static boolean DOTYPECHECKS=false;
static boolean DONULL=false;
-
+
public DotExpr(Expr left, String field, Expr index) {
this.left = left;
this.field = field;
name+="["+index.name()+"]";
return name;
}
-
+
public void findmatch(Descriptor d, Set s) {
if (d==fd)
s.add(this);
public Set getRequiredDescriptors() {
Set v = left.getRequiredDescriptors();
-
+
if (intindex != null) {
v.addAll(intindex.getRequiredDescriptors());
}
if (writer.getInvariantValue()!=null&&
writer.getInvariantValue().isInvariant(this)) {
- writer.outputline("maybe="+writer.getInvariantValue().getMaybe(this).getSafeSymbol()+";");
writer.outputline(getType().getGenerateType().getSafeSymbol()+
" "+dest.getSafeSymbol()+"="+writer.getInvariantValue().getValue(this).getSafeSymbol()+";");
+ writer.outputline("maybe="+writer.getInvariantValue().getMaybe(this).getSafeSymbol()+";");
return;
}
- writer.output("// " + leftd.getSafeSymbol() + " <-- ");
+ writer.output("/* " + leftd.getSafeSymbol() + " <-- ");
left.prettyPrint(writer);
- writer.outputline("");
+ writer.outputline("*/");
left.generate(writer, leftd);
- writer.output("// " + leftd.getSafeSymbol() + " = ");
+ writer.output("/* " + leftd.getSafeSymbol() + " = ");
left.prettyPrint(writer);
- writer.outputline("");
-
+ writer.outputline("*/");
+
StructureTypeDescriptor struct = (StructureTypeDescriptor) left.getType();
Expr offsetbits;
// #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
+ // 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);
FieldDescriptor fd=this.fd;
indexvd.setType(ReservedTypeDescriptor.INT);
writer.getSymbolTable().add(indexvd);
- writer.output("// " + indexvd.getSafeSymbol() + " <-- ");
+ writer.output("/* " + indexvd.getSafeSymbol() + " <-- ");
intindex.prettyPrint(writer);
- writer.outputline("");
+ writer.outputline("*/");
intindex.generate(writer, indexvd);
- writer.output("// " + indexvd.getSafeSymbol() + " = ");
+ writer.output("/* " + indexvd.getSafeSymbol() + " = ");
intindex.prettyPrint(writer);
- writer.outputline("");
+ writer.outputline("*/");
Expr indexbound=((ArrayDescriptor)this.fd).getIndexBound();
VarDescriptor indexboundvd=VarDescriptor.makeNew("indexbound");
indexbound.generate(writer,indexboundvd);
-
+
writer.outputline("if ("+indexvd.getSafeSymbol()+">=0 &&"+indexvd.getSafeSymbol()+"<"+indexboundvd.getSafeSymbol()+")");
writer.startblock();
VarExpr indexve=new VarExpr(indexvd);
offsetbits = new OpExpr(Opcode.ADD, offsetbits, new OpExpr(Opcode.MULT, basesize, indexve));
-
+
performedboundscheck=true;
} else
offsetbits = new OpExpr(Opcode.ADD, offsetbits, new OpExpr(Opcode.MULT, basesize, intindex));
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;
VarDescriptor ob = VarDescriptor.makeNew("offsetinbits");
- writer.output("// " + ob.getSafeSymbol() + " <-- ");
+ writer.output("/* " + ob.getSafeSymbol() + " <-- ");
offsetbits.prettyPrint(writer);
- writer.outputline("");
+ writer.outputline("*/");
offsetbits.generate(writer, ob);
- writer.output("// " + ob.getSafeSymbol() + " = ");
+ writer.output("/* " + ob.getSafeSymbol() + " = ");
offsetbits.prettyPrint(writer);
- writer.outputline("");
-
+ writer.outputline("*/");
+
/* derive offset in bytes */
VarDescriptor offset = VarDescriptor.makeNew("offset");
writer.outputline("int " + 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.outputline("int " + shift.getSafeSymbol() + " = " + ob.getSafeSymbol() +
" - (" + offset.getSafeSymbol() + " << 3);");
int mask = bitmask(((IntegerLiteralExpr)fd.getType().getSizeExpr()).getValue());
-
+
/* type var = ((*(int *) (base + offset)) >> shift) & mask */
writer.outputline("if ("+leftd.getSafeSymbol()+")");
- writer.outputline(dest.getSafeSymbol() + " = ((*(int *)" +
- "(" + leftd.getSafeSymbol() + " + " + offset.getSafeSymbol() + ")) " +
- " >> " + shift.getSafeSymbol() + ") & 0x" + Integer.toHexString(mask) + ";");
+ writer.outputline(dest.getSafeSymbol() + " = ((*(int *)" +
+ "(" + leftd.getSafeSymbol() + " + " + offset.getSafeSymbol() + ")) " +
+ " >> " + shift.getSafeSymbol() + ") & 0x" + Integer.toHexString(mask) + ";");
writer.outputline("else maybe=1;");
} else { /* a structure address or a ptr */
String ptr = fd.getPtr() ? "*(int *)" : "";
/* type var = [*(int *)] (base + offset) */
writer.outputline("if ("+leftd.getSafeSymbol()+")");
writer.startblock();
- writer.outputline(dest.getSafeSymbol() +
- " = " + ptr + "(" + leftd.getSafeSymbol() + " + " + offset.getSafeSymbol() + ");");
+ writer.outputline(dest.getSafeSymbol() +
+ " = " + ptr + "(" + leftd.getSafeSymbol() + " + " + offset.getSafeSymbol() + ");");
if (fd.getPtr()) {
writer.outputline("if ("+dest.getSafeSymbol()+")");
writer.startblock();
private int bitmask(int bits) {
int mask = 0;
-
+
for (int i = 0; i < bits; i++) {
mask <<= 1;
mask += 1;
}
- return mask;
+ return mask;
}
public void prettyPrint(PrettyPrinter pp) {
tmpfd=((ArrayDescriptor)tmpfd).getField();
return (tmpfd.getPtr()||(tmpfd.getType() instanceof ReservedTypeDescriptor));
}
-
+
public boolean isPtr() {
FieldDescriptor tmpfd=fd;
if (tmpfd instanceof ArrayDescriptor)
else typechecked=true;
TypeDescriptor lefttype = left.typecheck(sa);
TypeDescriptor indextype = index == null ? null : index.typecheck(sa);
-
+
{
/* finished typechecking...so we can fill the fields in */
StructureTypeDescriptor struct = (StructureTypeDescriptor) left.getType();
}
}
- if (lefttype instanceof StructureTypeDescriptor) {
+ if (lefttype instanceof StructureTypeDescriptor) {
StructureTypeDescriptor struct = (StructureTypeDescriptor) lefttype;
FieldDescriptor fd = struct.getField(field);
LabelDescriptor ld = struct.getLabel(field);
if (indextype == null && fd instanceof ArrayDescriptor) {
sa.getErrorReporter().report(null, "Must specify an index what accessing array field '" + struct.getSymbol() + "." + fd.getSymbol() + "'");
- return null;
+ return null;
} else if (indextype != null && !(fd instanceof ArrayDescriptor)) {
sa.getErrorReporter().report(null, "Cannot specify an index when accessing non-array field '" + struct.getSymbol() + "." + fd.getSymbol() + "'");
return null;
}
-
+
this.td = fd.getType();
} else if (ld != null) { /* label */
assert fd == null;
- if (index != null) {
+ if (index != null) {
sa.getErrorReporter().report(null, "A label cannot be accessed as an array");
return null;
}
-
+
this.td = ld.getType();
} else {
sa.getErrorReporter().report(null, "No such field or label '" + field + "' in structure '" + struct.getSymbol() + "'");
}
}
}
-
public void generate(CodeWriter writer, VarDescriptor dest) {
VarDescriptor ed = VarDescriptor.makeNew("element");
element.generate(writer, ed);
- writer.outputline("int " + dest.getSafeSymbol() + " = " +
- set.getSafeSymbol() + "_hash->contains(" + ed.getSafeSymbol() + ");");
+ writer.outputline("int " + dest.getSafeSymbol() + " = SimpleHashcontainskey("+set.getSafeSymbol() +"_hash ,"+ ed.getSafeSymbol() + ");");
}
-
+
public void prettyPrint(PrettyPrinter pp) {
element.prettyPrint(pp);
pp.output(" in? " + set.getSafeSymbol());
public TypeDescriptor typecheck(SemanticAnalyzer sa) {
TypeDescriptor td = element.typecheck(sa);
-
+
if (td == null) {
return null;
}
sa.getErrorReporter().report(null, "Type mismatch: attempting to test for types '" + td.getSymbol() + "' in set of type '" + settype.getSymbol() + "'");
return null;
}
-
+
this.td = ReservedTypeDescriptor.INT;
return this.td;
}
}
-
}
public void generate_inclusion(CodeWriter writer, VarDescriptor dest, VarDescriptor element) {
- String hash = inverse ? "_hashinv->contains(" : "_hash->contains(" ;
+ String hash = inverse ? "_hashinv, " : "_hash, " ;
if (!isimageset) {
- writer.outputline("int " + dest.getSafeSymbol() + " = " + rd.getSafeSymbol() + hash + vd.getSafeSymbol() + ", " + element.getSafeSymbol() + ");");
+ writer.outputline("int " + 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()+"="+newset.getSafeSymbol()+"->contains("+element.getSafeSymbol()+");");
+ writer.outputline("int "+dest.getSafeSymbol()+"=SimpleHashcontainskey("+newset.getSafeSymbol()+","+element.getSafeSymbol()+");");
writer.outputline("delete "+newset.getSafeSymbol()+";");
}
}
assert dest != null;
assert rd != null;
if (!isimageset) {
- String hash = inverse ? "_hashinv->count(" : "_hash->count(" ;
- writer.outputline("int " + dest.getSafeSymbol() + " = " + rd.getSafeSymbol() + hash + vd.getSafeSymbol() + ");");
+ String hash = inverse ? "_hashinv, " : "_hash, " ;
+ writer.outputline("int " + dest.getSafeSymbol() + " = SimpleHashcount(" + rd.getSafeSymbol() + hash + vd.getSafeSymbol() + ");");
} else {
VarDescriptor newset=VarDescriptor.makeNew("newset");
generate_set(writer,newset);
- writer.outputline("int "+dest.getSafeSymbol()+"="+newset.getSafeSymbol()+"->count();");
+ writer.outputline("int "+dest.getSafeSymbol()+"=SimpleHashcountset("+newset.getSafeSymbol()+");");
writer.outputline("delete "+newset.getSafeSymbol()+";");
- }
+ }
}
public void generate_leftside(CodeWriter writer, VarDescriptor dest) {
} else {
VarDescriptor iseset=VarDescriptor.makeNew("set");
ise.generate_set(writer,iseset);
- writer.outputline("int "+dest.getSafeSymbol()+" = "+iseset.getSafeSymbol()+"->firstkey();");
+ writer.outputline("int "+dest.getSafeSymbol()+" = SimpleHashfirstkey("+iseset.getSafeSymbol()+");");
writer.outputline("delete "+iseset.getSafeSymbol()+";");
}
}
public void generate_set(CodeWriter writer, VarDescriptor dest) {
if (!isimageset) {
- String hash = inverse ? "_hashinv->imageSet(" : "_hash->imageSet(" ;
- writer.outputline("SimpleHash * "+dest.getSafeSymbol()+"="+rd.getSafeSymbol()+hash+vd.getSafeSymbol()+");");
+ String hash = inverse ? "_hashinv, " : "_hash, " ;
+ writer.outputline("struct SimpleHash * "+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("SimpleIterator "+itvd.getSafeSymbol()+";");
- writer.outputline(iseset.getSafeSymbol()+"->iterator("+itvd.getSafeSymbol()+");");
+ writer.outputline("struct SimpleIterator "+itvd.getSafeSymbol()+";");
+ writer.outputline("SimpleHashiterator("+iseset.getSafeSymbol()+",&"+itvd.getSafeSymbol()+");");
+
+ writer.outputline("struct SimpleHash *"+dest.getSafeSymbol()+"=allocateSimpleHash(10);");
+ writer.outputline("while (hasNext(&"+itvd.getSafeSymbol()+")) {");
- writer.outputline("SimpleHash *"+dest.getSafeSymbol()+"=new SimpleHash(10);");
- writer.outputline("while ("+itvd.getSafeSymbol()+".hasNext()) {");
-
VarDescriptor keyvd=VarDescriptor.makeNew("key");
-
- writer.outputline("int "+keyvd.getSafeSymbol()+"="+itvd.getSafeSymbol()+".next();");
- String hash = inverse ? "_hashinv->imageSet(" : "_hash->imageSet(" ;
+
+ writer.outputline("int "+keyvd.getSafeSymbol()+"=next(&"+itvd.getSafeSymbol()+");");
+ String hash = inverse ? "_hashinv, " : "_hash, " ;
VarDescriptor newset=VarDescriptor.makeNew("newset");
- writer.outputline("SimpleHash * "+newset.getSafeSymbol()+"="+rd.getSafeSymbol()+hash+keyvd.getSafeSymbol()+");");
- writer.outputline(dest.getSafeSymbol()+"->addAll("+newset.getSafeSymbol()+");");
- writer.outputline("delete "+newset.getSafeSymbol()+";");
+ writer.outputline("SimpleHash * "+newset.getSafeSymbol()+"=SimpleHashimageSet("+rd.getSafeSymbol()+hash+keyvd.getSafeSymbol()+");");
+ writer.outputline("SimpleHashaddAll("+dest.getSafeSymbol()+", "+ newset.getSafeSymbol()+");");
+ writer.outputline("freeSimpleHash("+newset.getSafeSymbol()+");");
writer.outputline("}");
- writer.outputline("delete "+iseset.getSafeSymbol()+";");
- }
+ writer.outputline("freeSimpleHash("+iseset.getSafeSymbol()+");");
+ }
}
public void prettyPrint(PrettyPrinter pp) {
}
return set;
}
-
+
public TypeDescriptor typecheck(SemanticAnalyzer sa) {
TypeDescriptor lt=left.typecheck(sa);
if (lt!=ReservedTypeDescriptor.INT)
VarDescriptor leftd = VarDescriptor.makeNew("leftboolean");
left.generate(writer, leftd);
- writer.outputline("// 3-valued NOT");
+ writer.outputline("/* 3-valued NOT*/");
// writer.outputline("if (!maybe)"); //this isn't really necessary
writer.startblock();
writer.outputline(dest.getSafeSymbol() + " = !" + leftd.getSafeSymbol() + ";");
String l = leftd.getSafeSymbol();
String r = rightd.getSafeSymbol();
-
+
if (op == AND) {
- /*
+ /*
* 3-value AND LOGIC
*
* LRLR
* M = (L*RM) + (R*LM) + (LM*RM)
* O = (L*R)
*/
-
+
// maybe = (l && rm) || (r && lm) || (lm && rm)
writer.outputline("maybe = (" + l + " && " + rm + ") || (" + r + " && " + lm + ") || (" + lm + " && " + rm + ");");
writer.outputline(dest.getSafeSymbol() + " = " + l + " && " + r + ";");
} else if (op == OR) {
- /*
+ /*
* 3-value OR LOGIC
*
* LRLR
writer.outputline(dest.getSafeSymbol() + " = " + l + " || " + r + ";");
} else {
throw new IRException();
- }
+ }
}
- }
+ }
}
-
-
-
-
-
-
-
-
-
-
-
-
-
import java.util.*;
public class MetaInclusion extends Inclusion {
-
+
Inclusion inclusion;
Vector rules;
Vector constraints;
}
public void generate(CodeWriter cr) {
-
+
this.inclusion.generate(cr);
// for each of the rules, since they are guaranteed to be single quantifiers, and in fact,
- // even stricter, there only quantifier is the same quantifier just generated by
- // the inclusion constraint, we only need to bind each of there vardescriptors in there
+ // even stricter, there only quantifier is the same quantifier just generated by
+ // the inclusion constraint, we only need to bind each of there vardescriptors in there
// own blocks (to avoid name space clashes) to the newly quantified variable.
// we know that the inclusion is a setinlusion
cr.outputline("if (" + addeditem + ")");
cr.startblock();
-
+
ListIterator allrules = rules.listIterator();
while (allrules.hasNext()) {
Rule rule = (Rule) allrules.next();
-
+
// we need to grab the vardescriptor of the first quantifeir (which is a setquantifier)
// and we need to instantiate it inside a new block scope and set it equal to the value
// in "result" .... we then need to generate the guard and inclusion inside of inner rule
-
+
cr.startblock();{
- cr.outputline("// embedding " + rule.getLabel() );
-
+ cr.outputline("/* embedding " + rule.getLabel() +"*/");
+
SetQuantifier sq = (SetQuantifier) rule.quantifiers().next(); // get first qunatifier
VarDescriptor vd = sq.getVar();
cr.outputline("int " + vd.getSafeSymbol() + " = " + result + ";");
cr.pushSymbolTable(rule.getSymbolTable());
-
+
VarDescriptor guardval = VarDescriptor.makeNew();
rule.getGuardExpr().generate(cr, guardval);
-
+
cr.outputline("if (" + guardval.getSafeSymbol() + ")");
cr.startblock(); {
rule.getInclusion().generate(cr);
} cr.endblock();
cr.popSymbolTable();
-
- } cr.endblock();
+
+ } cr.endblock();
}
cr.endblock();
ListIterator allconstraints = constraints.listIterator();
while (allconstraints.hasNext()) {
Constraint constraint = (Constraint) allconstraints.next();
-
+
// ok... um... we need to grab teh vardescripntor of the first quantifier which is guaranteed
// to be a setquantifier... we then need to bind it to variable, generatedresult.
// once this is done we can generated the logicstatement and we can then test for pass/fail
cr.startblock(); {
- cr.outputline("// checking embedded " + constraint.getLabel() );
-
+ cr.outputline("/* checking embedded " + constraint.getLabel()+"*/" );
+
SetQuantifier sq = (SetQuantifier) constraint.quantifiers().next(); // get first qunatifier
VarDescriptor vd = sq.getVar();
cr.outputline("int " + vd.getSafeSymbol() + " = " + result + ";");
cr.pushSymbolTable(constraint.getSymbolTable());
-
+
cr.outputline("int maybe = 0;");
-
+
/* now we have to generate the guard test */
-
+
VarDescriptor constraintboolean = VarDescriptor.makeNew("constraintboolean");
constraint.getLogicStatement().generate(cr, constraintboolean);
-
+
cr.outputline("if (maybe)");
cr.startblock(); {
cr.outputline("__Success = 0;");
cr.outputline("printf(\"maybe fail " + constraint.getNum() + ". \");");
cr.outputline("exit(1);");
-
+
} cr.endblock();
- cr.outputline("else if (!" + constraintboolean.getSafeSymbol() + ")");
+ cr.outputline("else if (!" + constraintboolean.getSafeSymbol() + ")");
cr.startblock(); {
-
+
cr.outputline("__Success = 0;");
cr.outputline("printf(\"fail " + constraint.getNum() + ". \");");
cr.outputline("exit(1);");
} cr.endblock();
cr.popSymbolTable();
-
- } cr.endblock();
+
+ } cr.endblock();
}
}
}
-
State state;
java.io.PrintWriter output = null;
-
+
public NaiveGenerator(State state) {
this.state = state;
}
public void generate(java.io.OutputStream output) {
- this.output = new java.io.PrintWriter(output, true);
-
+ this.output = new java.io.PrintWriter(output, true);
+
generate_tokentable();
generate_hashtables();
generate_rules();
private void generate_tokentable() {
- CodeWriter cr = new StandardCodeWriter(output);
- Iterator tokens = TokenLiteralExpr.tokens.keySet().iterator();
+ CodeWriter cr = new StandardCodeWriter(output);
+ Iterator tokens = TokenLiteralExpr.tokens.keySet().iterator();
cr.outputline("");
- cr.outputline("// Token values");
+ cr.outputline("/* Token values*/");
cr.outputline("");
while (tokens.hasNext()) {
Object token = tokens.next();
- cr.outputline("// " + token.toString() + " = " + TokenLiteralExpr.tokens.get(token).toString());
+ cr.outputline("/* " + token.toString() + " = " + TokenLiteralExpr.tokens.get(token).toString()+"*/");
}
cr.outputline("");
private void generate_hashtables() {
CodeWriter cr = new StandardCodeWriter(output);
- cr.outputline("int __Success = 1;\n");
- cr.outputline("// creating hashtables ");
-
+ cr.outputline("int __Success = 1;\n");
+ cr.outputline("/* creating hashtables */");
+
/* build all the hashtables */
Hashtable hashtables = new Hashtable();
/* build sets */
Iterator sets = state.stSets.descriptors();
-
+
/* first pass create all the hash tables */
while (sets.hasNext()) {
SetDescriptor set = (SetDescriptor) sets.next();
cr.outputline("SimpleHash* " + set.getSafeSymbol() + "_hash = new SimpleHash();");
- }
-
+ }
+
/* second pass build relationships between hashtables */
sets = state.stSets.descriptors();
-
+
while (sets.hasNext()) {
SetDescriptor set = (SetDescriptor) sets.next();
Iterator subsets = set.subsets();
-
+
while (subsets.hasNext()) {
- SetDescriptor subset = (SetDescriptor) subsets.next();
+ SetDescriptor subset = (SetDescriptor) subsets.next();
cr.outputline(subset.getSafeSymbol() + "_hash->addParent(" + set.getSafeSymbol() + "_hash);");
}
- }
+ }
/* build relations */
Iterator relations = state.stRelations.descriptors();
-
+
/* first pass create all the hash tables */
while (relations.hasNext()) {
RelationDescriptor relation = (RelationDescriptor) relations.next();
-
+
if (relation.testUsage(RelationDescriptor.IMAGE)) {
cr.outputline("SimpleHash* " + relation.getSafeSymbol() + "_hash = new SimpleHash();");
}
if (relation.testUsage(RelationDescriptor.INVIMAGE)) {
cr.outputline("SimpleHash* " + relation.getSafeSymbol() + "_hashinv = new SimpleHash();");
- }
+ }
}
cr.outputline("");
return g2.getFinishingTime() - g1.getFinishingTime();
}
});
-
- topologicalsort.addAll(state.rulenodes.values());
+
+ topologicalsort.addAll(state.rulenodes.values());
/* build all the rules */
Iterator rules = topologicalsort.iterator();
-
+
while (rules.hasNext()) {
GraphNode rulenode = (GraphNode) rules.next();
- Rule rule = (Rule) rulenode.getOwner();
+ Rule rule = (Rule) rulenode.getOwner();
if (!state.vRules.contains(rule)) {
// this is no longer a top-level rule
{
CodeWriter cr = new StandardCodeWriter(output);
- cr.pushSymbolTable(rule.getSymbolTable());
-
- cr.outputline("// build " + rule.getLabel());
+ cr.pushSymbolTable(rule.getSymbolTable());
+
+ cr.outputline("/* build " + rule.getLabel()+"*/");
cr.startblock();
ListIterator quantifiers = rule.quantifiers();
while (quantifiers.hasNext()) {
- Quantifier quantifier = (Quantifier) quantifiers.next();
+ Quantifier quantifier = (Quantifier) quantifiers.next();
quantifier.generate_open(cr);
- }
-
+ }
+
/* pretty print! */
- cr.output("//");
+ cr.output("/*");
rule.getGuardExpr().prettyPrint(cr);
- cr.outputline("");
+ cr.outputline("*/");
/* now we have to generate the guard test */
-
+
VarDescriptor guardval = VarDescriptor.makeNew();
rule.getGuardExpr().generate(cr, guardval);
-
+
cr.outputline("if (" + guardval.getSafeSymbol() + ")");
cr.startblock();
private void generate_implicit_checks() {
/* do post checks */
-
+
CodeWriter cr = new StandardCodeWriter(output);
-
+
// #TBD#: these should be implicit checks added to the set of constraints
//output.println("check multiplicity");
}
for (int i = 0; i < constraints.size(); i++) {
- Constraint constraint = (Constraint) constraints.elementAt(i);
+ Constraint constraint = (Constraint) constraints.elementAt(i);
{
CodeWriter cr = new StandardCodeWriter(output);
cr.pushSymbolTable(constraint.getSymbolTable());
-
- cr.outputline("// checking " + constraint.getLabel());
+
+ cr.outputline("/* checking " + constraint.getLabel()+"*/");
cr.startblock();
ListIterator quantifiers = constraint.quantifiers();
while (quantifiers.hasNext()) {
- Quantifier quantifier = (Quantifier) quantifiers.next();
+ Quantifier quantifier = (Quantifier) quantifiers.next();
quantifier.generate_open(cr);
- }
+ }
cr.outputline("int maybe = 0;");
-
+
/* now we have to generate the guard test */
-
+
VarDescriptor constraintboolean = VarDescriptor.makeNew("constraintboolean");
constraint.getLogicStatement().generate(cr, constraintboolean);
-
+
cr.outputline("if (maybe)");
cr.startblock();
cr.outputline("__Success = 0;");
cr.outputline("");
cr.outputline("");
}
-
+
}
- output.println("//if (__Success) { printf(\"all tests passed\"); }");
- }
+ output.println("/*if (__Success) { printf(\"all tests passed\"); }*/");
+ }
}
-
-
-
newset.addAll(right.useDescriptor(d));
return newset;
}
-
+
public int[] getRepairs(boolean negated, Termination t) {
if (left instanceof RelationExpr)
return new int[] {AbstractRepair.MODIFYRELATION};
AbstractRepair.REMOVEFROMRELATION};
}
} else if (op==Opcode.GE||op==Opcode.GT) {
- return new int[]{AbstractRepair.ADDTORELATION};
+ return new int[]{AbstractRepair.ADDTORELATION};
} else if (op==Opcode.LE||op==Opcode.LT) {
if ((op==Opcode.LT&&maxsize!=-1&&maxsize<size)||(op==Opcode.LE&&maxsize!=-1&&maxsize<=size))
return new int[0];
} else {
if (op==Opcode.EQ) {
if (size==0)
- return new int[] {AbstractRepair.REMOVEFROMSET};
+ return new int[] {AbstractRepair.REMOVEFROMSET};
else {
if (maxsize<=size&&maxsize!=-1)
return new int[] {AbstractRepair.ADDTOSET};
AbstractRepair.REMOVEFROMSET};
}
} else if (op==Opcode.GE||op==Opcode.GT) {
- return new int[] {AbstractRepair.ADDTOSET};
+ return new int[] {AbstractRepair.ADDTOSET};
} else if (op==Opcode.LE||op==Opcode.LT) {
if ((op==Opcode.LT&&maxsize<size&&maxsize!=-1)||(op==Opcode.LE&&maxsize<=size&&maxsize!=-1))
return new int[0];
}
throw new Error("BAD");
}
-
+
public Descriptor getDescriptor() {
return left.getDescriptor();
}
public Set getRequiredDescriptors() {
Set v = left.getRequiredDescriptors();
-
+
if (right != null) {
v.addAll(right.getRequiredDescriptors());
}
return v;
- }
+ }
public void generate(CodeWriter writer, VarDescriptor dest) {
VarDescriptor ld = VarDescriptor.makeNew("leftop");
/* Check for loop invariant hoisting. */
if (writer.getInvariantValue()!=null&&
writer.getInvariantValue().isInvariant(this)) {
- writer.outputline("maybe="+writer.getInvariantValue().getMaybe(this).getSafeSymbol()+";");
writer.outputline("int "+dest.getSafeSymbol()+"="+writer.getInvariantValue().getValue(this).getSafeSymbol()+";");
+ writer.outputline("maybe="+writer.getInvariantValue().getMaybe(this).getSafeSymbol()+";");
return;
}
writer.outputline("int "+dest.getSafeSymbol() + " = " + ld.getSafeSymbol() + " || " + rd.getSafeSymbol() + ";");
} else if (opcode != Opcode.NOT) { /* two operands */
assert rd != null;
- writer.outputline("int " + dest.getSafeSymbol() + " = " +
+ writer.outputline("int " + dest.getSafeSymbol() + " = " +
ld.getSafeSymbol() + " " + opcode.toString() + " " + rd.getSafeSymbol() + ";");
} else if (opcode == Opcode.NOT) {
writer.outputline("int " + dest.getSafeSymbol() + " = !" + ld.getSafeSymbol() + ";");
} else if (opcode == Opcode.RND) {
pp.output("RND ");
left.prettyPrint(pp);
- } else {
+ } else {
left.prettyPrint(pp);
pp.output(" " + opcode.toString() + " ");
assert right != null;
--- /dev/null
+package MCC.IR;
+import java.util.*;
+
+public class PrintWrapper {
+ java.io.PrintWriter output;
+ String buffered="";
+ boolean buffer=false;
+ Hashtable vartable=new Hashtable();
+
+ public PrintWrapper(java.io.PrintWriter output) {
+ this.output=output;
+ }
+ void print(String s) {
+ if (buffer)
+ buffered+=s;
+ else
+ output.print(s);
+ }
+ void flush() {
+ if (!buffer)
+ output.flush();
+ }
+ void println(String s) {
+ if (buffer)
+ buffered+=s+"\n";
+ else
+ output.println(s);
+ }
+ void startBuffer() {
+ buffer=true;
+ }
+ void emptyBuffer() {
+ //Print out declarations
+ for(Iterator it=vartable.keySet().iterator();it.hasNext();) {
+ String var=(String)it.next();
+ output.println(((String)vartable.get(var))+" "+var+";");
+ }
+ output.print(buffered);
+ buffered="";
+ vartable=new Hashtable();
+ buffer=false;
+ }
+ void addDeclaration(String type, String varname) {
+ if (buffer) {
+ if (vartable.containsKey(varname)) {
+ String oldtype=(String)vartable.get(varname);
+ if (!oldtype.equals(type)) {
+ throw new Error("Internal error: Inconsistent declarations for:"+varname);
+ }
+ } else {
+ vartable.put(varname,type);
+ }
+ } else
+ output.println(type+" "+varname+";");
+ }
+}
if (exprfunctions!=null)
functions.addAll(exprfunctions);
functions.add(new ConstraintDependence.Function(relation,expr.getSet(),inverse,this));
-
+
return functions;
}
newset.addAll(expr.useDescriptor(rd));
return newset;
}
-
+
public RelationDescriptor getRelation() {
return relation;
}
}
public Set getRequiredDescriptors() {
- Set v = expr.getRequiredDescriptors();
+ Set v = expr.getRequiredDescriptors();
v.add(relation);
return v;
}
String found = (VarDescriptor.makeNew("found")).getSafeSymbol();
expr.generate(writer, domain);
writer.outputline(relation.getRange().getType().getGenerateType().getSafeSymbol() + " " + dest.getSafeSymbol() + ";");
- writer.outputline("int "+found+" = "+relation.getSafeSymbol() + "_hash" + strinverse + "->get(" + domain.getSafeSymbol() + ", " + dest.getSafeSymbol() + ");");
+ writer.outputline("int "+found+" = SimpleHashget(" +relation.getSafeSymbol()+"_hash"+strinverse+", "+ domain.getSafeSymbol() + ", & " + dest.getSafeSymbol() + ");");
writer.outputline("if (!" + found + ") { maybe = 1; }");
}
public void prettyPrint(PrettyPrinter pp) {
expr.prettyPrint(pp);
pp.output(".");
-
+
if (inverse) {
pp.output("~");
}
public TypeDescriptor typecheck(SemanticAnalyzer sa) {
TypeDescriptor type = expr.typecheck(sa);
-
+
if (type == null) {
return null;
}
/* check to make sure that the types of the relation match up */
if (inverse) {
TypeDescriptor rangetype = relation.getRange().getType();
-
+
if (rangetype != type) {
- sa.getErrorReporter().report(null, "Type of left side of relation operator '.' is '" + type.getSymbol() +
- "' but must be '" + rangetype.getSymbol() +
+ sa.getErrorReporter().report(null, "Type of left side of relation operator '.' is '" + type.getSymbol() +
+ "' but must be '" + rangetype.getSymbol() +
"', the type of the range of the relation '" + relation.getSymbol() + "'");
return null;
}
-
+
this.td = relation.getDomain().getType();
return this.td;
} else { /* not inverse */
TypeDescriptor domaintype = relation.getDomain().getType();
-
+
if (domaintype != type) {
- sa.getErrorReporter().report(null, "Type of left side of relation operator '.' is '" + type.getSymbol() +
- "' but must be '" + domaintype.getSymbol() +
+ sa.getErrorReporter().report(null, "Type of left side of relation operator '.' is '" + type.getSymbol() +
+ "' but must be '" + domaintype.getSymbol() +
"', the type of the domain of the relation '" + relation.getSymbol() + "'");
return null;
}
}
public Set getRequiredDescriptors() {
- Set v = expr.getRequiredDescriptors();
+ Set v = expr.getRequiredDescriptors();
v.add(relation);
return v;
}
}
public void generate(CodeWriter cr, VarDescriptor dest) {
-
+
String destname = dest.getSafeSymbol();
cr.outputline("int " + destname + ";");
- // ok... destination is declared... we gotta expand this rule inplace... and instead of the inclusion we
+ // ok... destination is declared... we gotta expand this rule inplace... and instead of the inclusion we
// set the destination in the guard ... otherwise maybe!
-
+
VarDescriptor domain = VarDescriptor.makeNew("domain");
expr.generate(cr, domain);
SetQuantifier sq = ((SetQuantifier) rule.quantifiers().next());
VarDescriptor rulebinding = sq.getVar();
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 + ";");
-
+
/* pretty print! */
- cr.outputline("// about to inbed relational function");
- cr.output("// ");
+ cr.outputline("/* about to inbed relational function*/");
+ cr.output("/* ");
rule.getGuardExpr().prettyPrint(cr);
- cr.outputline("");
-
+ cr.outputline("*/");
+
/* now we have to generate the guard test */
VarDescriptor guardval = VarDescriptor.makeNew();
rule.getGuardExpr().generate(cr, guardval);
-
+
cr.outputline("if (" + guardval.getSafeSymbol() + ")");
cr.startblock(); {
-
+
/* now we have to generate the inclusion code */
RelationInclusion ri = (RelationInclusion) rule.getInclusion();
-
- // basically, destname = righthandside<r, r.field>
+
+ // basically, destname = righthandside<r, r.field>
VarDescriptor tempdest = VarDescriptor.makeNew("tempdest");
Expr rhs = ri.getRightExpr();
rhs.generate(cr, tempdest);
-
+
cr.outputline(destname + " = " + tempdest.getSafeSymbol() + ";");
-
+
} cr.endblock();
cr.outputline("else");
cr.startblock(); {
import java.util.*;
public class RelationInclusion extends Inclusion {
-
+
Expr leftelementexpr, rightelementexpr;
RelationDescriptor relation;
public Expr getLeftExpr() {
return leftelementexpr;
}
-
+
public Expr getRightExpr() {
return rightelementexpr;
}
String check = "int " + typesafecheck + " = " ;
if (!(relation.getDomain() instanceof ReservedSetDescriptor)) {
- check += relation.getDomain().getSafeSymbol() + "_hash->contains(" + ld.getSafeSymbol() + ") && ";
+ check += "SimpleHashcontainskey("+relation.getDomain().getSafeSymbol() + "_hash, "+ld.getSafeSymbol() + ") && ";
}
if (!(relation.getRange() instanceof ReservedSetDescriptor)) {
- check += relation.getRange().getSafeSymbol() + "_hash->contains(" + rd.getSafeSymbol() + ") && ";
+ check += "SimpleHashcontainskey("+relation.getRange().getSafeSymbol() +"_hash, "+ rd.getSafeSymbol() + ") && ";
}
check += "1;"; // terminate boolean expression
}
String addeditem = (VarDescriptor.makeNew("addeditem")).getSafeSymbol();
- /* if (!Compiler.REPAIR) {
- writer.outputline("int " + addeditem + ";");
- if (relation.testUsage(RelationDescriptor.IMAGE)) {
- writer.outputline(addeditem + " = " + relation.getSafeSymbol() + "_hash->add((int)" + ld.getSafeSymbol() + ", (int)" + rd.getSafeSymbol() + ");");
- }
-
- if (relation.testUsage(RelationDescriptor.INVIMAGE)) {
- writer.outputline(addeditem + " = " + relation.getSafeSymbol() + "_hashinv->add((int)" + rd.getSafeSymbol() + ", (int)" + ld.getSafeSymbol() + ");");
- }
- } else {*/
- Repair.generate_dispatch(writer, relation, ld.getSafeSymbol(), rd.getSafeSymbol());
- // }
-
+ Repair.generate_dispatch(writer, relation, ld.getSafeSymbol(), rd.getSafeSymbol());
+
if (RelationInclusion.worklist) {
writer.outputline("if (" + addeditem + ")");
writer.startblock(); {
public boolean typecheck(SemanticAnalyzer sa) {
TypeDescriptor ld = leftelementexpr.typecheck(sa);
TypeDescriptor rd = rightelementexpr.typecheck(sa);
-
+
if (ld == null || rd == null) {
return false;
}
boolean ok = true;
- /* #ATTN#: this check makes sure that the types match up,
- a runtime check needs to made that the set relationships
+ /* #ATTN#: this check makes sure that the types match up,
+ a runtime check needs to made that the set relationships
are correct */
- if (ld != relation.getDomain().getType()) {
+ if (ld != relation.getDomain().getType()) {
sa.getErrorReporter().report(null, "Type of left element '" + ld.getSymbol() + "' must match domain type '" + relation.getDomain().getType().getSymbol() + "'");
ok = false;
}
public RelationQuantifier() {}
public void setRelation(RelationDescriptor rd) {
- relation = rd;
+ relation = rd;
}
public RelationDescriptor getRelation() {
}
public void generate_open(CodeWriter writer) {
- writer.outputline("SimpleIterator "+x.getSafeSymbol()+"_iterator;");
- writer.outputline("for ("+relation.getSafeSymbol() + "_hash->iterator("+x.getSafeSymbol()+"_iterator); " + x.getSafeSymbol() + "_iterator.hasNext(); )");
+ writer.outputline("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() + ") " + x.getSafeSymbol() + "_iterator.next();");
- // #ATTN#: key is called second because next() forwards ptr and key does not!
- writer.outputline(x.getType().getGenerateType() + " " + x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") " + x.getSafeSymbol() + "_iterator.key();");
+ writer.outputline(y.getType().getGenerateType() + " " + 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);");
}
public void generate_open(CodeWriter writer, String type,int number, String left,String right) {
VarDescriptor tmp=VarDescriptor.makeNew("flag");
- writer.outputline("SimpleIterator* " + x.getSafeSymbol() + "_iterator = " + relation.getSafeSymbol() + "_hash->iterator();");
+ writer.outputline("struct SimpleIterator * " + x.getSafeSymbol() + "_iterator = SimpleHashcreateiterator("+relation.getSafeSymbol()+"_hash);");
writer.outputline("int "+tmp.getSafeSymbol()+"=0;");
writer.outputline("if ("+type+"=="+number+")");
writer.outputline(tmp.getSafeSymbol()+"=1;");
-
- writer.outputline("while("+tmp.getSafeSymbol()+"||(("+type+"!="+number+")&&"+x.getSafeSymbol() + "_iterator->hasNext()))");
+
+ 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.endblock();
writer.outputline("else");
writer.startblock();
- writer.outputline(y.getSafeSymbol() + " = (" + y.getType().getGenerateType() + ") " + x.getSafeSymbol() + "_iterator->next();");
- writer.outputline(x.getSafeSymbol() + " = (" + x.getType().getGenerateType() + ") " + x.getSafeSymbol() + "_iterator->key();");
+ 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 int generate_worklistload(CodeWriter writer, int offset) {
+ public int generate_worklistload(CodeWriter writer, int offset) {
String varx = x.getSafeSymbol();
String vary = y.getSafeSymbol();
- writer.outputline("int " + varx + " = wi->word" + offset + "; // r1");
- writer.outputline("int " + vary + " = wi->word" + (offset + 1) + "; //r2");
- return offset + 2;
+ writer.outputline("int " + varx + " = wi->word" + offset + "; /* r1*/");
+ writer.outputline("int " + vary + " = wi->word" + (offset + 1) + "; /*r2*/");
+ return offset + 2;
}
- public int generate_workliststore(CodeWriter writer, int offset) {
+ public int generate_workliststore(CodeWriter writer, int offset) {
String varx = x.getSafeSymbol();
String vary = y.getSafeSymbol();
- writer.outputline("wi->word" + offset + " = " + varx + "; // r1");
- writer.outputline("wi->word" + (offset+1) + " = " + vary + "; // r2");
- return offset + 2;
+ writer.outputline("wi->word" + offset + " = " + varx + "; /* r1*/");
+ writer.outputline("wi->word" + (offset+1) + " = " + vary + "; /* r2*/");
+ return offset + 2;
}
this.outputrepair = new java.io.PrintWriter(outputrepair, true);
this.outputaux = new java.io.PrintWriter(outputaux, true);
this.outputhead = new java.io.PrintWriter(outputhead, true);
+
headername=st;
name_updates();
generatetypechecks(true);
generate_tokentable();
+ RelationDescriptor.prefix = "thisvar->";
+ SetDescriptor.prefix = "thisvar->";
+
generate_hashtables();
generate_stateobject();
+
+
+ /* Rewrite globals */
+ CodeWriter craux = new StandardCodeWriter(this.outputaux);
+ for (Iterator it=this.state.stGlobals.descriptors();it.hasNext();) {
+ VarDescriptor vd=(VarDescriptor)it.next();
+ craux.outputline("#define "+vd.getSafeSymbol()+" thisvar->"+vd.getSafeSymbol());
+ }
+
+
generate_call();
generate_start();
generate_rules();
generate_checks();
generate_teardown();
CodeWriter crhead = new StandardCodeWriter(this.outputhead);
- CodeWriter craux = new StandardCodeWriter(this.outputaux);
- crhead.outputline("};");
+ craux = new StandardCodeWriter(this.outputaux);
craux.outputline("}");
if (Compiler.GENERATEDEBUGHOOKS) {
for (Iterator it=this.state.stGlobals.descriptors();it.hasNext();) {
VarDescriptor vd=(VarDescriptor)it.next();
+ craux.outputline("#undef "+vd.getSafeSymbol());
craux.outputline("#define "+vd.getSafeSymbol()+" "+ststate+"->"+vd.getSafeSymbol());
}
switch(mun.op) {
case MultUpdateNode.ADD:
if (isrelation) {
- crhead.outputline("void "+methodname+"("+name+"_state * " +ststate+","+name+" * "+stmodel+", RepairHash * "+strepairtable+", int "+stleft+", int "+stright+");");
- craux.outputline("void "+methodname+"("+name+"_state * "+ ststate+","+name+" * "+stmodel+", RepairHash * "+strepairtable+", int "+stleft+", int "+stright+")");
+ crhead.outputline("void "+methodname+"(struct "+name+"_state * " +ststate+",struct "+name+" * "+stmodel+", struct RepairHash * "+strepairtable+", int "+stleft+", int "+stright+");");
+ craux.outputline("void "+methodname+"(struct "+name+"_state * "+ ststate+", struct "+name+" * "+stmodel+", struct RepairHash * "+strepairtable+", int "+stleft+", int "+stright+")");
} else {
- crhead.outputline("void "+methodname+"("+name+"_state * "+ ststate+","+name+" * "+stmodel+", RepairHash * "+strepairtable+", int "+stleft+");");
- craux.outputline("void "+methodname+"("+name+"_state * "+ststate+","+name+" * "+stmodel+", RepairHash * "+strepairtable+", int "+stleft+")");
+ crhead.outputline("void "+methodname+"(struct "+name+"_state * "+ ststate+", struct "+name+" * "+stmodel+", struct RepairHash * "+strepairtable+", int "+stleft+");");
+ craux.outputline("void "+methodname+"(struct "+name+"_state * "+ststate+", struct "+name+" * "+stmodel+", struct RepairHash * "+strepairtable+", int "+stleft+")");
}
craux.startblock();
craux.outputline("int maybe=0;");
break;
case MultUpdateNode.REMOVE: {
Rule r=un.getRule();
- String methodcall="void "+methodname+"("+name+"_state * "+ststate+","+name+" * "+stmodel+", RepairHash * "+strepairtable;
+ String methodcall="void "+methodname+"(struct "+name+"_state * "+ststate+", struct "+name+" * "+stmodel+", struct RepairHash * "+strepairtable;
for(int j=0;j<r.numQuantifiers();j++) {
Quantifier q=r.getQuantifier(j);
if (q instanceof SetQuantifier) {
break;
case MultUpdateNode.MODIFY: {
Rule r=un.getRule();
- String methodcall="void "+methodname+"("+name+"_state * "+ststate+","+name+" * "+stmodel+", RepairHash * "+strepairtable;
+ String methodcall="void "+methodname+"(struct "+name+"_state * "+ststate+", struct "+name+" * "+stmodel+", struct RepairHash * "+strepairtable;
for(int j=0;j<r.numQuantifiers();j++) {
Quantifier q=r.getQuantifier(j);
if (q instanceof SetQuantifier) {
private void generate_call() {
CodeWriter cr = new StandardCodeWriter(outputrepair);
VarDescriptor vdstate=VarDescriptor.makeNew("repairstate");
- cr.outputline(name+"_state * "+vdstate.getSafeSymbol()+"=new "+name+"_state();");
+ cr.outputline("struct "+ name+"_state * "+vdstate.getSafeSymbol()+"=allocate"+name+"_state();");
Iterator globals=state.stGlobals.descriptors();
while (globals.hasNext()) {
VarDescriptor vd=(VarDescriptor) globals.next();
cr.outputline(vdstate.getSafeSymbol()+"->"+vd.getSafeSymbol()+"=("+vd.getType().getGenerateType().getSafeSymbol()+")"+vd.getSafeSymbol()+";");
}
/* Insert repair here */
- cr.outputline(vdstate.getSafeSymbol()+"->doanalysis();");
+ cr.outputline("doanalysis("+vdstate.getSafeSymbol()+");");
globals=state.stGlobals.descriptors();
while (globals.hasNext()) {
VarDescriptor vd=(VarDescriptor) globals.next();
cr.outputline("*(("+vd.getType().getGenerateType().getSafeSymbol()+"*) &"+vd.getSafeSymbol()+")="+vdstate.getSafeSymbol()+"->"+vd.getSafeSymbol()+";");
}
- cr.outputline("delete "+vdstate.getSafeSymbol()+";");
+ cr.outputline("free"+name+"_state("+vdstate.getSafeSymbol()+");");
}
private void generate_tokentable() {
Iterator tokens = TokenLiteralExpr.tokens.keySet().iterator();
cr.outputline("");
- cr.outputline("// Token values");
+ cr.outputline("/* Token values*/");
cr.outputline("");
while (tokens.hasNext()) {
Object token = tokens.next();
- cr.outputline("// " + token.toString() + " = " + TokenLiteralExpr.tokens.get(token).toString());
+ cr.outputline("/* " + token.toString() + " = " + TokenLiteralExpr.tokens.get(token).toString()+"*/");
}
cr.outputline("");
private void generate_stateobject() {
CodeWriter crhead = new StandardCodeWriter(outputhead);
- crhead.outputline("class "+name+"_state {");
- crhead.outputline("public:");
+ crhead.outputline("struct "+name+"_state {");
Iterator globals=state.stGlobals.descriptors();
while (globals.hasNext()) {
VarDescriptor vd=(VarDescriptor) globals.next();
crhead.outputline(vd.getType().getGenerateType().getSafeSymbol()+" "+vd.getSafeSymbol()+";");
}
- crhead.outputline("void computesizes(int *,int **);");
- crhead.outputline("void recomputesizes();");
+ crhead.outputline("};");
+ crhead.outputline("void "+name+"_statecomputesizes(struct "+name+"_state * ,int *,int **);");
+ crhead.outputline("void "+name+"_staterecomputesizes(struct "+name+"_state *);");
}
private void generate_computesizes() {
public SymbolTable getSymbolTable() { return st; }
};
- cr.outputline("void "+name+"_state::computesizes(int *sizearray,int **numele) {");
+ cr.outputline("void "+name+"_statecomputesizes(struct "+name+"_state * thisvar,int *sizearray,int **numele) {");
cr.outputline("int maybe=0;");
for(int i=0;i<max;i++) {
TypeDescriptor td=tdarray[i];
CodeWriter cr = new StandardCodeWriter(outputaux) {
public SymbolTable getSymbolTable() { return st; }
};
- cr.outputline("void "+name+"_state::recomputesizes() {");
+ cr.outputline("void "+name+"_staterecomputesizes(struct "+name+"_state * thisvar) {");
cr.outputline("int maybe=0;");
for(int i=0;i<max;i++) {
TypeDescriptor td=tdarray[i];
crhead.outputline("#ifndef "+name+"_h");
crhead.outputline("#define "+name+"_h");
crhead.outputline("#include \"SimpleHash.h\"");
- crhead.outputline("extern \"C\" {");
crhead.outputline("#include \"instrument.h\"");
- crhead.outputline("}");
crhead.outputline("#include <stdio.h>");
crhead.outputline("#include <stdlib.h>");
- crhead.outputline("class "+name+" {");
- crhead.outputline("public:");
- crhead.outputline(name+"();");
- crhead.outputline("~"+name+"();");
+ crhead.outputline("struct "+name+" * allocate"+name+"();");
+ crhead.outputline("void free"+name+"(struct "+name+" *);");
+ crhead.outputline("struct "+name+" {");
craux.outputline("#include \""+headername+"\"");
craux.outputline("#include \"size.h\"");
if (Compiler.TIME) {
}
}
}
- craux.outputline(name+"::"+name+"() {");
- craux.outputline("// creating hashtables ");
+ craux.outputline("struct "+ name+"* "+name+"() {");
+ craux.outputline("/* creating hashtables */");
/* build sets */
Iterator sets = state.stSets.descriptors();
+ craux.outputline("struct "+name+"* thisvar=(struct "+name+"*) malloc(sizeof(struct "+name+"));");
/* first pass create all the hash tables */
while (sets.hasNext()) {
SetDescriptor set = (SetDescriptor) sets.next();
- crhead.outputline("SimpleHash* " + set.getSafeSymbol() + "_hash;");
- craux.outputline(set.getSafeSymbol() + "_hash = new SimpleHash();");
+ crhead.outputline("struct SimpleHash* " + set.getJustSafeSymbol() + "_hash;");
+ craux.outputline(set.getSafeSymbol() + "_hash = noargallocateSimpleHash();");
}
/* second pass build relationships between hashtables */
while (subsets.hasNext()) {
SetDescriptor subset = (SetDescriptor) subsets.next();
- craux.outputline(subset.getSafeSymbol() + "_hash->addParent(" + set.getSafeSymbol() + "_hash);");
+ craux.outputline("SimpleHashaddParent("+subset.getSafeSymbol() +"_hash ,"+ set.getSafeSymbol() + "_hash);");
}
}
RelationDescriptor relation = (RelationDescriptor) relations.next();
if (relation.testUsage(RelationDescriptor.IMAGE)) {
- crhead.outputline("SimpleHash* " + relation.getSafeSymbol() + "_hash;");
- craux.outputline(relation.getSafeSymbol() + "_hash = new SimpleHash();");
+ crhead.outputline("struct SimpleHash* " + relation.getJustSafeSymbol() + "_hash;");
+ craux.outputline(relation.getSafeSymbol() + "_hash = noargallocateSimpleHash();");
}
if (relation.testUsage(RelationDescriptor.INVIMAGE)) {
- crhead.outputline("SimpleHash* " + relation.getSafeSymbol() + "_hashinv;");
- craux.outputline(relation.getSafeSymbol() + "_hashinv = new SimpleHash();");
+ crhead.outputline("struct SimpleHash* " + relation.getJustSafeSymbol() + "_hashinv;");
+ craux.outputline(relation.getSafeSymbol() + "_hashinv = noargallocateSimpleHash();");
}
}
craux.outputline("}");
crhead.outputline("};");
- craux.outputline(name+"::~"+name+"() {");
- craux.outputline("// deleting hashtables");
+ craux.outputline("void free"+name+"(struct "+ name +"* thisvar) {");
+ craux.outputline("/* deleting hashtables */");
/* build destructor */
sets = state.stSets.descriptors();
/* first pass create all the hash tables */
while (sets.hasNext()) {
SetDescriptor set = (SetDescriptor) sets.next();
- craux.outputline("delete "+set.getSafeSymbol() + "_hash;");
+ craux.outputline("freeSimpleHash("+set.getSafeSymbol() + "_hash);");
}
/* destroy relations */
RelationDescriptor relation = (RelationDescriptor) relations.next();
if (relation.testUsage(RelationDescriptor.IMAGE)) {
- craux.outputline("delete "+relation.getSafeSymbol() + "_hash;");
+ craux.outputline("freeSimpleHash("+relation.getSafeSymbol() + "_hash);");
}
if (relation.testUsage(RelationDescriptor.INVIMAGE)) {
- craux.outputline("delete " + relation.getSafeSymbol() + "_hashinv;");
+ craux.outputline("freeSimpleHash(" + relation.getSafeSymbol() + "_hashinv);");
}
}
+ craux.outputline("free(thisvar);");
craux.outputline("}");
}
craux.outputline("int abstractcount;");
}
- crhead.outputline("void doanalysis();");
- craux.outputline("void "+name +"_state::doanalysis()");
+ crhead.outputline("void doanalysis(struct "+name+"_state *);");
+ craux.outputline("void doanalysis(struct "+name+"_state * thisvar)");
craux.startblock();
if (Compiler.TIME) {
craux.outputline("struct timeval _begin_time,_end_time;");
craux.outputline("gettimeofday(&_begin_time,NULL);");
}
-
if (Compiler.GENERATEINSTRUMENT) {
craux.outputline("updatecount=0;");
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.outputline("initializestack(&highmark);");
- craux.outputline("typeobject *typeobject1=gettypeobject();");
- craux.outputline("typeobject1->computesizes(this);");
- craux.outputline("recomputesizes();");
- craux.outputline(name+ " * "+oldmodel.getSafeSymbol()+"=0;");
- craux.outputline("WorkList * "+worklist.getSafeSymbol()+" = new WorkList();");
- craux.outputline("RepairHash * "+repairtable.getSafeSymbol()+"=0;");
+ craux.outputline("computesizes(thisvar);");
+ craux.outputline(name+"_staterecomputesizes(thisvar);");
craux.outputline("while (1)");
craux.startblock();
- craux.outputline(name+ " * "+newmodel.getSafeSymbol()+"=new "+name+"();");
- craux.outputline(worklist.getSafeSymbol()+"->reset();");
+ craux.outputline("struct "+name+ " * "+newmodel.getSafeSymbol()+"=allocate"+name+"();");
+ craux.outputline("WorkListreset("+worklist.getSafeSymbol()+");");
if (Compiler.GENERATEINSTRUMENT)
craux.outputline("rebuildcount++;");
}
public SymbolTable getSymbolTable() { return st; }
};
- cr.outputline("// printing sets!");
+ cr.outputline("/* printing sets!*/");
cr.outputline("printf(\"\\n\\nPRINTING SETS AND RELATIONS\\n\");");
Iterator setiterator = state.stSets.descriptors();
String setname = sd.getSafeSymbol();
cr.startblock();
- cr.outputline("// printing set " + setname);
- cr.outputline("printf(\"\\nPrinting set " + sd.getSymbol() + " - %d elements \\n\", " + setname + "_hash->count());");
- cr.outputline("SimpleIterator __setiterator;");
- cr.outputline("" + setname + "_hash->iterator(__setiterator);");
- cr.outputline("while (__setiterator.hasNext())");
+ 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.outputline("while (hasNext(&__setiterator))");
cr.startblock();
- cr.outputline("int __setval = (int) __setiterator.next();");
+ cr.outputline("int __setval = (int) next(&__setiterator);");
TypeDescriptor td = sd.getType();
if (td instanceof StructureTypeDescriptor) {
InvariantValue ivalue=new InvariantValue();
cr.setInvariantValue(ivalue);
- cr.outputline("// build " +escape(rule.toString()));
+ cr.outputline("/* build " +escape(rule.toString())+"*/");
cr.startblock();
cr.outputline("int maybe=0;");
}
}
+ int openparencount=0;
for(Iterator invit=invariants.iterator();invit.hasNext();) {
Expr invexpr=(Expr)invit.next();
VarDescriptor tmpvd=VarDescriptor.makeNew("tmpvar");
cr.outputline("int "+maybevd.getSafeSymbol()+"=maybe;");
cr.outputline("maybe=0;");
ivalue.assignPair(invexpr,tmpvd,maybevd);
+ openparencount++;
+ cr.startblock();
}
-
quantifiers = rule.quantifiers();
while (quantifiers.hasNext()) {
Quantifier quantifier = (Quantifier) quantifiers.next();
}
/* pretty print! */
- cr.output("//");
+ cr.output("/*");
rule.getGuardExpr().prettyPrint(cr);
- cr.outputline("");
+ cr.outputline("*/");
/* now we have to generate the guard test */
VarDescriptor guardval = VarDescriptor.makeNew();
cr.endblock();
}
cr.endblock();
+ while((openparencount--)>0)
+ cr.endblock();
cr.outputline("");
cr.outputline("");
}
for(Iterator initialworklist=ruleset.iterator();initialworklist.hasNext();) {
/** Construct initial worklist set */
Rule rule=(Rule)initialworklist.next();
- cr2.outputline(worklist.getSafeSymbol()+"->add("+rule.getNum()+",-1,0,0);");
+ cr2.outputline("WorkListadd("+worklist.getSafeSymbol()+","+rule.getNum()+",-1,0,0);");
}
- cr2.outputline("while ("+worklist.getSafeSymbol()+"->hasMoreElements())");
+ cr2.outputline("while (WorkListhasMoreElements("+worklist.getSafeSymbol()+"))");
cr2.startblock();
VarDescriptor idvar=VarDescriptor.makeNew("id");
- cr2.outputline("int "+idvar.getSafeSymbol()+"="+worklist.getSafeSymbol()+"->getid();");
+ cr2.outputline("int "+idvar.getSafeSymbol()+"=WorkListgetid("+worklist.getSafeSymbol()+");");
String elseladder = "if";
VarDescriptor typevar=VarDescriptor.makeNew("type");
VarDescriptor leftvar=VarDescriptor.makeNew("left");
VarDescriptor rightvar=VarDescriptor.makeNew("right");
- cr.outputline("int "+typevar.getSafeSymbol()+"="+worklist.getSafeSymbol()+"->gettype();");
- cr.outputline("int "+leftvar.getSafeSymbol()+"="+worklist.getSafeSymbol()+"->getlvalue();");
- cr.outputline("int "+rightvar.getSafeSymbol()+"="+worklist.getSafeSymbol()+"->getrvalue();");
- cr.outputline("// build " +escape(rule.toString()));
+ 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.outputline("/* build " +escape(rule.toString())+"*/");
for (int j=0;j<rule.numQuantifiers();j++) {
}
/* pretty print! */
- cr.output("//");
+ cr.output("/*");
rule.getGuardExpr().prettyPrint(cr);
- cr.outputline("");
+ cr.outputline("*/");
/* now we have to generate the guard test */
cr2.outputline("exit(1);");
cr2.endblock();
// end block created for worklist
- cr2.outputline(worklist.getSafeSymbol()+"->pop();");
+ cr2.outputline("WorkListpop("+worklist.getSafeSymbol()+");");
cr2.endblock();
}
}
CodeWriter cr = new StandardCodeWriter(outputaux);
cr.pushSymbolTable(constraint.getSymbolTable());
- cr.outputline("// checking " + escape(constraint.toString()));
+ cr.outputline("/* checking " + escape(constraint.toString())+"*/");
cr.startblock();
ListIterator quantifiers = constraint.quantifiers();
if (Compiler.REPAIR) {
/* Do repairs */
/* Build new repair table */
+
cr.outputline("if ("+repairtable.getSafeSymbol()+")");
- cr.outputline("delete "+repairtable.getSafeSymbol()+";");
- cr.outputline(repairtable.getSafeSymbol()+"=new RepairHash();");
+ cr.outputline("freeRepairHash("+repairtable.getSafeSymbol()+");");
+ cr.outputline(repairtable.getSafeSymbol()+"=noargallocateRepairHash();");
if (Compiler.GENERATEDEBUGHOOKS)
cr.outputline("debughook();");
cr.outputline("}");
cr.outputline("if ("+oldmodel.getSafeSymbol()+")");
- cr.outputline("delete "+oldmodel.getSafeSymbol()+";");
+ cr.outputline("free"+name+"("+oldmodel.getSafeSymbol()+");");
cr.outputline(oldmodel.getSafeSymbol()+"="+newmodel.getSafeSymbol()+";");
cr.outputline("goto rebuild;"); /* Rebuild model and all */
}
CodeWriter cr = new StandardCodeWriter(outputaux);
cr.startblock();
cr.outputline("if ("+repairtable.getSafeSymbol()+")");
- cr.outputline("delete "+repairtable.getSafeSymbol()+";");
+ cr.outputline("freeRepairHash("+repairtable.getSafeSymbol()+");");
cr.outputline("if ("+oldmodel.getSafeSymbol()+")");
- cr.outputline("delete "+oldmodel.getSafeSymbol()+";");
- cr.outputline("delete "+newmodel.getSafeSymbol()+";");
- cr.outputline("delete "+worklist.getSafeSymbol()+";");
+ cr.outputline("free"+name+"("+oldmodel.getSafeSymbol()+");");
+ cr.outputline("free"+name+"("+newmodel.getSafeSymbol()+");");
+ cr.outputline("freeWorkList("+worklist.getSafeSymbol()+");");
cr.outputline("resettypemap();");
cr.outputline("break;");
cr.endblock();
((RelationExpr)expr.getLeftExpr()).getExpr().generate(cr,leftside);
expr.getRightExpr().generate(cr,newvalue);
cr.outputline(rd.getRange().getType().getGenerateType().getSafeSymbol()+" "+rightside.getSafeSymbol()+";");
- cr.outputline(rd.getSafeSymbol()+"_hash->get("+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+");");
+ cr.outputline("SimpleHashget("+rd.getSafeSymbol()+"_hash,"+leftside.getSafeSymbol()+", &"+rightside.getSafeSymbol()+");");
} else {
((RelationExpr)expr.getLeftExpr()).getExpr().generate(cr,rightside);
expr.getRightExpr().generate(cr,newvalue);
cr.outputline(rd.getDomain().getType().getGenerateType().getSafeSymbol()+" "+leftside.getSafeSymbol()+";");
- cr.outputline(rd.getSafeSymbol()+"_hashinv->get("+rightside.getSafeSymbol()+","+leftside.getSafeSymbol()+");");
+ cr.outputline("SimpleHashget("+rd.getSafeSymbol()+"_hashinv,"+rightside.getSafeSymbol()+", &"+leftside.getSafeSymbol()+");");
}
opcode=Opcode.translateOpcode(negated,opcode);
}
/* Do abstract repairs */
if (usageimage) {
- cr.outputline(rd.getSafeSymbol()+"_hash->remove("+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+");");
+ cr.outputline("SimpleHashremove("+rd.getSafeSymbol()+"_hash, "+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+");");
}
if (usageinvimage) {
- cr.outputline(rd.getSafeSymbol()+"_hashinv->remove("+rightside.getSafeSymbol()+","+leftside.getSafeSymbol()+");");
+ cr.outputline("SimpleHashremove("+rd.getSafeSymbol()+"_hashinv, "+rightside.getSafeSymbol()+","+leftside.getSafeSymbol()+");");
}
if (needremoveloop) {
if (!inverted) {
- cr.outputline("if ("+rd.getSafeSymbol()+"_hash->contains("+leftside.getSafeSymbol()+")) {");
+ cr.outputline("if (SimpleHashcontainskey("+rd.getSafeSymbol()+"_hash, "+leftside.getSafeSymbol()+")) {");
} else {
- cr.outputline("if ("+rd.getSafeSymbol()+"_hashinv->contains("+rightside.getSafeSymbol()+")) {");
+ cr.outputline("if (SimpleHashcontainskey("+rd.getSafeSymbol()+"_hashinv, "+rightside.getSafeSymbol()+")) {");
}
for(int i=0;i<state.vRules.size();i++) {
Rule r=(Rule)state.vRules.get(i);
if (un.getRule()==r) {
/* Update for rule r */
String name=(String)updatenames.get(un);
- cr.outputline(repairtable.getSafeSymbol()+"->addrelation("+rd.getNum()+","+r.getNum()+","+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+",(int) &"+name+");");
+ cr.outputline("RepairHashaddrelation("+repairtable.getSafeSymbol()+","+rd.getNum()+","+r.getNum()+","+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+",(int) &"+name+");");
}
}
}
if (usageimage) {
if (!inverted) {
- cr.outputline(rd.getSafeSymbol()+"_hash->add("+leftside.getSafeSymbol()+","+newvalue.getSafeSymbol()+");");
+ cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hash,"+leftside.getSafeSymbol()+","+newvalue.getSafeSymbol()+");");
} else {
- cr.outputline(rd.getSafeSymbol()+"_hash->add("+newvalue.getSafeSymbol()+","+rightside.getSafeSymbol()+");");
+ cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hash, "+newvalue.getSafeSymbol()+","+rightside.getSafeSymbol()+");");
}
}
if (usageinvimage) {
if (!inverted) {
- cr.outputline(rd.getSafeSymbol()+"_hashinv->add("+newvalue.getSafeSymbol()+","+leftside.getSafeSymbol()+");");
+ cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hashinv, "+newvalue.getSafeSymbol()+","+leftside.getSafeSymbol()+");");
} else {
- cr.outputline(rd.getSafeSymbol()+"_hashinv->add("+rightside.getSafeSymbol()+","+newvalue.getSafeSymbol()+");");
+ cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hashinv,"+rightside.getSafeSymbol()+","+newvalue.getSafeSymbol()+");");
}
}
/* Do concrete repairs */
if (un.getRule()==r) {
/* Update for rule r */
String name=(String)updatenames.get(un);
- cr.outputline(repairtable.getSafeSymbol()+"->addrelation("+rd.getNum()+","+r.getNum()+","+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+",(int) &"+name+","+newvalue.getSafeSymbol()+");");
+ cr.outputline("RepairHashaddrelation2("+repairtable.getSafeSymbol()+","+rd.getNum()+","+r.getNum()+","+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+",(int) &"+name+","+newvalue.getSafeSymbol()+");");
}
}
}
if (un.getRule()==r) {
/* Update for rule r */
String name=(String)updatenames.get(un);
- cr.outputline(repairtable.getSafeSymbol()+"->addrelation("+rd.getNum()+","+r.getNum()+","+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+",(int) &"+name+");");
+ cr.outputline("RepairHashaddrelation("+repairtable.getSafeSymbol()+","+rd.getNum()+","+r.getNum()+","+leftside.getSafeSymbol()+","+rightside.getSafeSymbol()+",(int) &"+name+");");
}
}
}
UpdateNode un=munadd.getUpdate(0);
String name=(String)updatenames.get(un);
if (!inverted) {
- cr.outputline(name+"(this,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+leftside.getSafeSymbol()+","+newvalue.getSafeSymbol()+");");
+ cr.outputline(name+"(thisvar,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+leftside.getSafeSymbol()+","+newvalue.getSafeSymbol()+");");
} else {
- cr.outputline(name+"(this,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+newvalue.getSafeSymbol()+","+rightside.getSafeSymbol()+");");
+ cr.outputline(name+"(thisvar,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+newvalue.getSafeSymbol()+","+rightside.getSafeSymbol()+");");
}
}
if (needremoveloop) {
if (ep.inverted()) {
((ImageSetExpr)((SizeofExpr)expr.left).setexpr).generate_leftside(cr,rightvar);
cr.outputline("int "+leftvar.getSafeSymbol()+";");
- cr.outputline(d.getSafeSymbol()+"_hashinv->get((int)"+rightvar.getSafeSymbol()+","+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.outputline(d.getSafeSymbol()+"_hash->get((int)"+leftvar.getSafeSymbol()+","+rightvar.getSafeSymbol()+");");
+ cr.outputline("SimpleHashget("+d.getSafeSymbol()+"_hash ,(int)"+leftvar.getSafeSymbol()+", &"+rightvar.getSafeSymbol()+");");
}
} else {
- cr.outputline("int "+leftvar.getSafeSymbol()+"="+d.getSafeSymbol()+"_hash->firstkey();");
+ cr.outputline("int "+leftvar.getSafeSymbol()+"= SimpleHashfirstkey("+d.getSafeSymbol()+"_hash);");
}
/* Generate abstract remove instruction */
if (d instanceof RelationDescriptor) {
boolean usageimage=rd.testUsage(RelationDescriptor.IMAGE);
boolean usageinvimage=rd.testUsage(RelationDescriptor.INVIMAGE);
if (usageimage)
- cr.outputline(rd.getSafeSymbol() + "_hash->remove((int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");");
+ cr.outputline("SimpleHashremove("+rd.getSafeSymbol()+"_hash, (int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");");
if (usageinvimage)
- cr.outputline(rd.getSafeSymbol() + "_hashinv->remove((int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
+ cr.outputline("SimpleHashremove("+rd.getSafeSymbol()+"_hashinv ,(int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
} else {
- cr.outputline(d.getSafeSymbol() + "_hash->remove((int)" + leftvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
+ cr.outputline("SimpleHashremove("+d.getSafeSymbol()+"_hash, (int)" + leftvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
}
/* Generate concrete remove instruction */
for(int i=0;i<state.vRules.size();i++) {
/* Update for rule rule r */
String name=(String)updatenames.get(un);
if (d instanceof RelationDescriptor) {
- cr.outputline(repairtable.getSafeSymbol()+"->addrelation("+d.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+","+rightvar.getSafeSymbol()+",(int) &"+name+");");
+ cr.outputline("RepairHashaddrelation("+repairtable.getSafeSymbol()+","+d.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+","+rightvar.getSafeSymbol()+",(int) &"+name+");");
} else {
- cr.outputline(repairtable.getSafeSymbol()+"->addset("+d.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+",(int) &"+name+");");
+ cr.outputline("RepairHashaddset("+repairtable.getSafeSymbol()+","+d.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+",(int) &"+name+");");
}
}
}
SetDescriptor sd=termination.sources.relgetSourceSet(rd,!ep.inverted());
VarDescriptor iterator=VarDescriptor.makeNew("iterator");
cr.outputline(sd.getType().getGenerateType().getSafeSymbol() +" "+newobject.getSafeSymbol()+";");
- cr.outputline("SimpleIterator "+iterator.getSafeSymbol()+";");
- cr.outputline("for("+sd.getSafeSymbol()+"_hash->iterator("+ iterator.getSafeSymbol() +");"+iterator.getSafeSymbol()+".hasNext();)");
+ cr.outputline("struct SimpleIterator "+iterator.getSafeSymbol()+";");
+ cr.outputline("for(SimpleHashiterator(& "+sd.getSafeSymbol()+"_hash ,"+ iterator.getSafeSymbol() +");"+iterator.getSafeSymbol()+".hasNext();)");
cr.startblock();
if (ep.inverted()) {
- cr.outputline("if (!"+rd.getSafeSymbol()+"_hashinv->contains("+iterator.getSafeSymbol()+".key(),"+otherside.getSafeSymbol()+"))");
+ cr.outputline("if (!SimpleHashcontainskeydata("+rd.getSafeSymbol()+"_hashinv,"+iterator.getSafeSymbol()+".key(),"+otherside.getSafeSymbol()+"))");
} else {
- cr.outputline("if (!"+rd.getSafeSymbol()+"_hash->contains("+otherside.getSafeSymbol()+","+iterator.getSafeSymbol()+".key()))");
+ cr.outputline("if (!SimpleHashcontainskeydata("+rd.getSafeSymbol()+"_hash, "+otherside.getSafeSymbol()+","+iterator.getSafeSymbol()+".key()))");
}
- cr.outputline(newobject.getSafeSymbol()+"="+iterator.getSafeSymbol()+".key();");
- cr.outputline(iterator.getSafeSymbol()+".next();");
+ cr.outputline(newobject.getSafeSymbol()+"=key("+iterator.getSafeSymbol()+");");
+ cr.outputline("next("+iterator.getSafeSymbol()+");");
cr.endblock();
} else if (termination.sources.relallocSource(rd,!ep.inverted())) {
/* Allocation Source*/
boolean usageimage=rd.testUsage(RelationDescriptor.IMAGE);
boolean usageinvimage=rd.testUsage(RelationDescriptor.INVIMAGE);
if (usageimage)
- cr.outputline(rd.getSafeSymbol()+"_hash->add("+newobject.getSafeSymbol()+","+otherside.getSafeSymbol()+");");
+ cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hash, "+newobject.getSafeSymbol()+","+otherside.getSafeSymbol()+");");
if (usageinvimage)
- cr.outputline(rd.getSafeSymbol()+"_hashinv->add("+otherside.getSafeSymbol()+","+newobject.getSafeSymbol()+");");
+ cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hashinv, "+otherside.getSafeSymbol()+","+newobject.getSafeSymbol()+");");
UpdateNode un=munadd.getUpdate(0);
String name=(String)updatenames.get(un);
- cr.outputline(name+"(this,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+newobject.getSafeSymbol()+","+otherside.getSafeSymbol()+");");
+ cr.outputline(name+"(thisvar,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+newobject.getSafeSymbol()+","+otherside.getSafeSymbol()+");");
} else {
boolean usageimage=rd.testUsage(RelationDescriptor.IMAGE);
boolean usageinvimage=rd.testUsage(RelationDescriptor.INVIMAGE);
if (usageimage)
- cr.outputline(rd.getSafeSymbol()+"_hash->add("+otherside.getSafeSymbol()+","+newobject.getSafeSymbol()+");");
+ cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hash, "+otherside.getSafeSymbol()+","+newobject.getSafeSymbol()+");");
if (usageinvimage)
- cr.outputline(rd.getSafeSymbol()+"_hashinv->add("+newobject.getSafeSymbol()+","+otherside.getSafeSymbol()+");");
+ cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hashinv, "+newobject.getSafeSymbol()+","+otherside.getSafeSymbol()+");");
UpdateNode un=munadd.getUpdate(0);
String name=(String)updatenames.get(un);
- cr.outputline(name+"(this,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+otherside.getSafeSymbol()+","+newobject.getSafeSymbol()+");");
+ cr.outputline(name+"(thisvar, "+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+otherside.getSafeSymbol()+","+newobject.getSafeSymbol()+");");
}
} else {
SetDescriptor sd=(SetDescriptor)d;
VarDescriptor iterator=VarDescriptor.makeNew("iterator");
cr.outputline(sourcesd.getType().getGenerateType().getSafeSymbol() +" "+newobject.getSafeSymbol()+";");
cr.outputline("SimpleIterator "+iterator.getSafeSymbol()+";");
- cr.outputline("for("+sourcesd.getSafeSymbol()+"_hash->iterator("+iterator.getSafeSymbol()+");"+iterator.getSafeSymbol()+".hasNext();)");
+ cr.outputline("for(SimpleHashiterator("+sourcesd.getSafeSymbol()+"_hash, "+iterator.getSafeSymbol()+");"+iterator.getSafeSymbol()+".hasNext();)");
cr.startblock();
- cr.outputline("if (!"+sd.getSafeSymbol()+"_hash->contains("+iterator.getSafeSymbol()+".key()))");
- cr.outputline(newobject.getSafeSymbol()+"="+iterator.getSafeSymbol()+".key();");
- cr.outputline(iterator.getSafeSymbol()+".next();");
+ 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*/
termination.sources.generateSourceAlloc(cr,newobject,sd);
} else throw new Error("No source for adding to Set");
- cr.outputline(sd.getSafeSymbol()+"_hash->add("+newobject.getSafeSymbol()+","+newobject.getSafeSymbol()+");");
+ cr.outputline("SimpleHashadd("+sd.getSafeSymbol()+"_hash, "+newobject.getSafeSymbol()+","+newobject.getSafeSymbol()+");");
UpdateNode un=munadd.getUpdate(0);
String name=(String)updatenames.get(un);
- cr.outputline(name+"(this,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+newobject.getSafeSymbol()+");");
+ cr.outputline(name+"(thisvar,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+newobject.getSafeSymbol()+");");
}
cr.endblock();
}
boolean usageinvimage=rd.testUsage(RelationDescriptor.INVIMAGE);
if (inverse) {
if (usageimage)
- cr.outputline(rd.getSafeSymbol() + "_hash->remove((int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
+ cr.outputline("SimpleHashremove("+rd.getSafeSymbol()+"_hash, (int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
if (usageinvimage)
- cr.outputline(rd.getSafeSymbol() + "_hashinv->remove((int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");");
+ cr.outputline("SimpleHashremove("+rd.getSafeSymbol()+"_hashinv, (int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");");
} else {
if (usageimage)
- cr.outputline(rd.getSafeSymbol() + "_hash->remove((int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");");
+ cr.outputline("SimpleHashremove("+rd.getSafeSymbol()+"_hash ,(int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");");
if (usageinvimage)
- cr.outputline(rd.getSafeSymbol() + "_hashinv->remove((int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
+ cr.outputline("SimpleHashremove("+rd.getSafeSymbol()+"_hashinv, (int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
}
for(int i=0;i<state.vRules.size();i++) {
Rule r=(Rule)state.vRules.get(i);
/* Update for rule rule r */
String name=(String)updatenames.get(un);
if (inverse) {
- cr.outputline(repairtable.getSafeSymbol()+"->addrelation("+rd.getNum()+","+r.getNum()+","+rightvar.getSafeSymbol()+","+leftvar.getSafeSymbol()+",(int) &"+name+");");
+ cr.outputline("RepairHashaddrelation("+repairtable.getSafeSymbol()+","+rd.getNum()+","+r.getNum()+","+rightvar.getSafeSymbol()+","+leftvar.getSafeSymbol()+",(int) &"+name+");");
} else {
- cr.outputline(repairtable.getSafeSymbol()+"->addrelation("+rd.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+","+rightvar.getSafeSymbol()+",(int) &"+name+");");
+ cr.outputline("RepairHashaddrelation("+repairtable.getSafeSymbol()+","+rd.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+","+rightvar.getSafeSymbol()+",(int) &"+name+");");
}
}
}
}
} else {
SetDescriptor sd=ip.setexpr.sd;
- cr.outputline(sd.getSafeSymbol() + "_hash->remove((int)" + leftvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
+ cr.outputline("SimpleHashremove("+sd.getSafeSymbol()+"_hash, (int)" + leftvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
for(int i=0;i<state.vRules.size();i++) {
Rule r=(Rule)state.vRules.get(i);
if (un.getRule()==r) {
/* Update for rule rule r */
String name=(String)updatenames.get(un);
- cr.outputline(repairtable.getSafeSymbol()+"->addset("+sd.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+",(int) &"+name+");");
+ cr.outputline("RepairHashaddset("+repairtable.getSafeSymbol()+","+sd.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+",(int) &"+name+");");
}
}
}
boolean usageinvimage=rd.testUsage(RelationDescriptor.INVIMAGE);
if (inverse) {
if (usageimage)
- cr.outputline(rd.getSafeSymbol() + "_hash->add((int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
+ cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hash, (int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
if (usageinvimage)
- cr.outputline(rd.getSafeSymbol() + "_hashinv->add((int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");");
+ cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hashinv, (int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");");
} else {
if (usageimage)
- cr.outputline(rd.getSafeSymbol() + "_hash->add((int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");");
+ cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hash, (int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");");
if (usageinvimage)
- cr.outputline(rd.getSafeSymbol() + "_hashinv->add((int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
+ cr.outputline("SimpleHashadd("+rd.getSafeSymbol()+"_hashinv, (int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
}
UpdateNode un=mun.getUpdate(0);
String name=(String)updatenames.get(un);
if (inverse) {
- cr.outputline(name+"(this,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+rightvar.getSafeSymbol()+","+leftvar.getSafeSymbol()+");");
+ cr.outputline(name+"(thisvar,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+rightvar.getSafeSymbol()+","+leftvar.getSafeSymbol()+");");
} else {
- cr.outputline(name+"(this,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+leftvar.getSafeSymbol()+","+rightvar.getSafeSymbol()+");");
+ cr.outputline(name+"(thisvar,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+leftvar.getSafeSymbol()+","+rightvar.getSafeSymbol()+");");
}
} else {
SetDescriptor sd=ip.setexpr.sd;
- cr.outputline(sd.getSafeSymbol() + "_hash->add((int)" + leftvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
+ cr.outputline("SimpleHashadd("+sd.getSafeSymbol()+"_hash, (int)" + leftvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
UpdateNode un=mun.getUpdate(0);
/* Update for rule rule r */
String name=(String)updatenames.get(un);
- cr.outputline(name+"(this,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+leftvar.getSafeSymbol()+");");
+ cr.outputline(name+"(thisvar,"+newmodel.getSafeSymbol()+","+repairtable.getSafeSymbol()+","+leftvar.getSafeSymbol()+");");
}
}
}
if (!(usageinvimage||usageimage)) /* not used at all*/
return;
- cr.outputline("// RELATION DISPATCH ");
+ cr.outputline("/* RELATION DISPATCH */");
if (Compiler.REPAIR) {
cr.outputline("if ("+oldmodel.getSafeSymbol()+"&&");
if (usageimage)
- cr.outputline("!"+oldmodel.getSafeSymbol() +"->"+rd.getJustSafeSymbol()+"_hash->contains("+leftvar+","+rightvar+"))");
+ cr.outputline("!SimpleHashcontainskeydata("+oldmodel.getSafeSymbol()+"->"+rd.getJustSafeSymbol() + "_hash, "+leftvar+","+rightvar+"))");
else
- cr.outputline("!"+oldmodel.getSafeSymbol() +"->"+rd.getJustSafeSymbol()+"_hashinv->contains("+rightvar+","+leftvar+"))");
+ cr.outputline("!SimpleHashcontainskeydata("+oldmodel.getSafeSymbol() +"->"+rd.getJustSafeSymbol()+"_hashinv, "+rightvar+","+leftvar+"))");
cr.startblock(); {
/* Adding new item */
/* Perform safety checks */
cr.outputline("if ("+repairtable.getSafeSymbol()+"&&");
- cr.outputline(repairtable.getSafeSymbol()+"->containsrelation("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+"))");
+ cr.outputline("RepairHashcontainsrelation("+repairtable.getSafeSymbol()+","+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+"))");
cr.startblock(); {
/* Have update to call into */
VarDescriptor mdfyptr=VarDescriptor.makeNew("modifyptr");
VarDescriptor ismdfyptr=VarDescriptor.makeNew("ismodifyptr");
- cr.outputline("int "+ismdfyptr.getSafeSymbol()+"="+repairtable.getSafeSymbol()+"->ismodify("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
+ cr.outputline("int "+ismdfyptr.getSafeSymbol()+"=RepairHashismodify("+repairtable.getSafeSymbol()+","+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
VarDescriptor funptr=VarDescriptor.makeNew("updateptr");
VarDescriptor tmpptr=VarDescriptor.makeNew("tempupdateptr");
- String methodcall="("+funptr.getSafeSymbol()+") (this,"+oldmodel.getSafeSymbol()+","+repairtable.getSafeSymbol();
+ String methodcall="("+funptr.getSafeSymbol()+") (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.outputline("(void *) "+repairtable.getSafeSymbol()+"->getrelation("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
+ cr.outputline("(void *) RepairHashgetrelation("+repairtable.getSafeSymbol()+","+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
cr.outputline("if ("+ismdfyptr.getSafeSymbol()+")");
{
cr.startblock();
- cr.outputline("int "+mdfyptr.getSafeSymbol()+"="+repairtable.getSafeSymbol()+"->getrelation2("+rd.getNum()+","+currentrule.getNum()+","+leftvar+","+rightvar+");");
- cr.outputline("void (*"+funptr.getSafeSymbol()+") ("+name+"_state *,"+name+"*,RepairHash *"+parttype+",int,int,int)="+"(void (*) ("+name+"_state *,"+name+"*,RepairHash *"+parttype+",int,int,int)) "+tmpptr.getSafeSymbol()+";");
+ 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.endblock();
}
cr.outputline("else ");
{
cr.startblock();
- cr.outputline("void (*"+funptr.getSafeSymbol()+") ("+name+"_state *,"+name+"*,RepairHash *"+parttype+")="+"(void (*) ("+name+"_state *,"+name+"*,RepairHash *"+parttype+")) "+tmpptr.getSafeSymbol()+";");
+ 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.endblock();
}
- cr.outputline("delete "+newmodel.getSafeSymbol()+";");
+ cr.outputline("free"+name+"("+newmodel.getSafeSymbol()+");");
cr.outputline("goto rebuild;");
}
cr.endblock();
UpdateNode un=find_compensation(currentrule);
String name=(String)updatenames.get(un);
usedupdates.add(un); /* Mark as used */
- String methodcall=name+"(this,"+oldmodel.getSafeSymbol()+","+repairtable.getSafeSymbol();
+ String methodcall=name+"(thisvar,"+oldmodel.getSafeSymbol()+","+repairtable.getSafeSymbol();
for(int i=0;i<currentrule.numQuantifiers();i++) {
Quantifier q=currentrule.getQuantifier(i);
if (q instanceof SetQuantifier) {
}
methodcall+=");";
cr.outputline(methodcall);
- cr.outputline("delete "+newmodel.getSafeSymbol()+";");
+ cr.outputline("free"+name+"("+newmodel.getSafeSymbol()+");");
cr.outputline("goto rebuild;");
}
}
}
String addeditem = (VarDescriptor.makeNew("addeditem")).getSafeSymbol();
+ cr.startblock();
cr.outputline("int " + addeditem + "=0;");
String ifstring="if (!maybe";
if (rd.testUsage(RelationDescriptor.IMAGE)) {
cr.outputline(ifstring);
- cr.outputline(addeditem + " = " + rd.getSafeSymbol() + "_hash->add((int)" + leftvar + ", (int)" + rightvar+ ");");
+ cr.outputline(addeditem + " = SimpleHashadd("+rd.getSafeSymbol()+"_hash, (int)" + leftvar + ", (int)" + rightvar+ ");");
}
if (rd.testUsage(RelationDescriptor.INVIMAGE)) {
cr.outputline(ifstring);
- cr.outputline(addeditem + " = " + rd.getSafeSymbol() + "_hashinv->add((int)" + rightvar + ", (int)" + leftvar + ");");
+ cr.outputline(addeditem + " = SimpleHashadd("+rd.getSafeSymbol()+"_hashinv, (int)" + rightvar + ", (int)" + leftvar + ");");
}
}
dispatchrules.removeAll(toremove);
if (dispatchrules.size() == 0) {
- cr.outputline("// nothing to dispatch");
+ cr.outputline("/* nothing to dispatch */");
+ cr.endblock();
return;
}
Rule rule = (Rule) dispatchrules.elementAt(i);
if (rule.getGuardExpr().getRequiredDescriptors().contains(rd)) {
/* Guard depends on this relation, so we recomput everything */
- cr.outputline(worklist.getSafeSymbol()+"->add("+rule.getNum()+",-1,0,0);");
+ cr.outputline("WorkListadd("+worklist.getSafeSymbol()+","+rule.getNum()+",-1,0,0);");
} else {
for (int j=0;j<rule.numQuantifiers();j++) {
Quantifier q=rule.getQuantifier(j);
if (q.getRequiredDescriptors().contains(rd)) {
/* Generate add */
- cr.outputline(worklist.getSafeSymbol()+"->add("+rule.getNum()+","+j+","+leftvar+","+rightvar+");");
+ cr.outputline("WorkListadd("+worklist.getSafeSymbol()+","+rule.getNum()+","+j+","+leftvar+","+rightvar+");");
}
}
}
}
-
+ cr.endblock();
cr.endblock();
}
public void generate_dispatch(CodeWriter cr, SetDescriptor sd, String setvar) {
- cr.outputline("// SET DISPATCH ");
+ cr.outputline("/* SET DISPATCH */");
if (Compiler.REPAIR) {
cr.outputline("if ("+oldmodel.getSafeSymbol()+"&&");
- cr.outputline("!"+oldmodel.getSafeSymbol() +"->"+sd.getJustSafeSymbol()+"_hash->contains("+setvar+"))");
+ cr.outputline("!SimpleHashcontainskey("+oldmodel.getSafeSymbol() +"->"+sd.getJustSafeSymbol()+"_hash, "+setvar+"))");
cr.startblock(); {
/* Adding new item */
/* See if there is an outstanding update in the repairtable */
cr.outputline("if ("+repairtable.getSafeSymbol()+"&&");
- cr.outputline(repairtable.getSafeSymbol()+"->containsset("+sd.getNum()+","+currentrule.getNum()+","+setvar+"))");
+ cr.outputline("RepairHashcontainsset("+repairtable.getSafeSymbol()+","+sd.getNum()+","+currentrule.getNum()+","+setvar+"))");
cr.startblock(); {
/* Have update to call into */
VarDescriptor funptr=VarDescriptor.makeNew("updateptr");
else
parttype=parttype+", int";
}
- cr.outputline("void (*"+funptr.getSafeSymbol()+") ("+name+"_state *,"+name+"*,RepairHash *"+parttype+")=");
- cr.outputline("(void (*) ("+name+"_state *,"+name+"*,RepairHash *"+parttype+")) "+repairtable.getSafeSymbol()+"->getset("+sd.getNum()+","+currentrule.getNum()+","+setvar+");");
- String methodcall="("+funptr.getSafeSymbol()+") (this,"+oldmodel.getSafeSymbol()+","+
+ cr.outputline("void (*"+funptr.getSafeSymbol()+") (struct "+name+"_state *,struct "+name+"*,struct RepairHash *"+parttype+")=");
+ 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();
for(int i=0;i<currentrule.numQuantifiers();i++) {
Quantifier q=currentrule.getQuantifier(i);
}
methodcall+=");";
cr.outputline(methodcall);
- cr.outputline("delete "+newmodel.getSafeSymbol()+";");
+ cr.outputline("free"+name+"("+newmodel.getSafeSymbol()+");");
cr.outputline("goto rebuild;");
}
cr.endblock();
String name=(String)updatenames.get(un);
usedupdates.add(un); /* Mark as used */
- String methodcall=name+"(this,"+oldmodel.getSafeSymbol()+","+
+ String methodcall=name+"(thisvar,"+oldmodel.getSafeSymbol()+","+
repairtable.getSafeSymbol();
for(int j=0;j<currentrule.numQuantifiers();j++) {
Quantifier q=currentrule.getQuantifier(j);
if (currentrule!=itrule) {
SetDescriptor sdrule=((SetInclusion)itrule.getInclusion()).getSet();
cr.outputline("if ("+oldmodel.getSafeSymbol()+"&&");
- cr.outputline("!"+oldmodel.getSafeSymbol() +"->"+sdrule.getJustSafeSymbol()+"_hash->contains("+setvar+"))");
+ cr.outputline("!SimpleHashcontainskey("+ oldmodel.getSafeSymbol() +"->"+sdrule.getJustSafeSymbol() +"_hash,"+setvar+"))");
cr.startblock();
}
cr.outputline(methodcall);
- cr.outputline("delete "+newmodel.getSafeSymbol()+";");
+ cr.outputline("free"+name+"("+newmodel.getSafeSymbol()+");");
cr.outputline("goto rebuild;");
cr.endblock();
}
}
}
+ cr.startblock();
String addeditem = (VarDescriptor.makeNew("addeditem")).getSafeSymbol();
cr.outputline("int " + addeditem + " = 0;");
if (sd.getType() instanceof StructureTypeDescriptor) {
cr.outputline("if (!maybe&&"+setvar+")");
} else
cr.outputline("if (!maybe)");
- cr.outputline(addeditem + " = " + sd.getSafeSymbol() + "_hash->add((int)" + setvar + ", (int)" + setvar + ");");
+ cr.outputline(addeditem + " = SimpleHashadd("+sd.getSafeSymbol()+"_hash, (int)" + setvar + ", (int)" + setvar + ");");
cr.startblock();
Vector dispatchrules = getrulelist(sd);
dispatchrules.removeAll(toremove);
if (dispatchrules.size() == 0) {
- cr.outputline("// nothing to dispatch");
+ cr.outputline("/* nothing to dispatch */");
+ cr.endblock();
cr.endblock();
return;
}
Rule rule = (Rule) dispatchrules.elementAt(i);
if (SetDescriptor.expand(rule.getGuardExpr().getRequiredDescriptors()).contains(sd)) {
/* Guard depends on this relation, so we recompute everything */
- cr.outputline(worklist.getSafeSymbol()+"->add("+rule.getNum()+",-1,0,0);");
+ cr.outputline("WorkListadd("+worklist.getSafeSymbol()+","+rule.getNum()+",-1,0,0);");
} else {
for (int j=0;j<rule.numQuantifiers();j++) {
Quantifier q=rule.getQuantifier(j);
if (SetDescriptor.expand(q.getRequiredDescriptors()).contains(sd)) {
/* Generate add */
- cr.outputline(worklist.getSafeSymbol()+"->add("+rule.getNum()+","+j+","+setvar+",0);");
+ cr.outputline("WorkListadd("+worklist.getSafeSymbol()+","+rule.getNum()+","+j+","+setvar+",0);");
}
}
}
}
cr.endblock();
cr.endblock();
+ cr.endblock();
}
}
}
public void generate_inclusion(CodeWriter writer, VarDescriptor dest, VarDescriptor element) {
- writer.outputline("int " + dest.getSafeSymbol() + " = " + sd.getSafeSymbol() + "_hash->contains(" + element.getSafeSymbol() + ");");
- }
+ writer.outputline("int " + dest.getSafeSymbol() + " = SimpleHashcontainskey(" +sd.getSafeSymbol()+ "_hash, "+element.getSafeSymbol() + ");");
+ }
public void generate_size(CodeWriter writer, VarDescriptor dest) {
- writer.outputline("int " + dest.getSafeSymbol() + " = " + sd.getSafeSymbol() + "_hash->count();");
+ writer.outputline("int " + dest.getSafeSymbol() + " = SimpleHashcountset("+sd.getSafeSymbol()+"_hash);");
}
public void prettyPrint(PrettyPrinter pp) {
}
}
-
-
if (dostore) {
/* if (!Compiler.REPAIR) {
writer.outputline("int " + addeditem + " = 1;");
- writer.outputline(addeditem + " = " + set.getSafeSymbol() + "_hash->add((int)" + vd.getSafeSymbol()
+ writer.outputline(addeditem + " = SimpleHashadd("+set.getSafeSymbol()+"_hash, (int)" + vd.getSafeSymbol()
+ ", (int)" + vd.getSafeSymbol() + ");");
} else {*/
Repair.generate_dispatch(writer, set, vd.getSafeSymbol());
}
public void generate_open(CodeWriter writer) {
- writer.outputline("SimpleIterator "+var.getSafeSymbol()+"_iterator;");
- writer.outputline("for (" + set.getSafeSymbol() + "_hash->iterator("+var.getSafeSymbol()+"_iterator); " + var.getSafeSymbol() + "_iterator.hasNext(); )");
+ writer.outputline("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() + ") " + var.getSafeSymbol() + "_iterator.next();");
+ writer.outputline(var.getType().getGenerateType() + " " + 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("SimpleIterator "+var.getSafeSymbol()+"_iterator;");
- writer.outputline(set.getSafeSymbol() + "_hash->iterator("+var.getSafeSymbol()+"_iterator);");
+ writer.outputline("struct SimpleIterator "+var.getSafeSymbol()+"_iterator;");
+ writer.outputline("SimpleHashiterator("+set.getSafeSymbol()+"_hash, &"+var.getSafeSymbol()+"_iterator);");
writer.outputline("int "+tmp.getSafeSymbol()+"=0;");
writer.outputline("if ("+type+"=="+number+")");
writer.outputline(tmp.getSafeSymbol()+"=1;");
- writer.outputline("while("+tmp.getSafeSymbol()+"||(("+type+"!="+number+")&&"+var.getSafeSymbol() + "_iterator.hasNext()))");
+ writer.outputline("while("+tmp.getSafeSymbol()+"||(("+type+"!="+number+")&&hasNext(&"+var.getSafeSymbol()+"_iterator)))");
writer.startblock();
writer.outputline(var.getType().getGenerateType() + " " + var.getSafeSymbol() + ";");
writer.outputline("if ("+type+"=="+number+")");
writer.outputline(var.getSafeSymbol() + " = (" + var.getType().getGenerateType() + ") " + left + ";");
writer.endblock();
writer.outputline("else");
- writer.outputline(var.getSafeSymbol() + " = (" + var.getType().getGenerateType() + ") " + var.getSafeSymbol() + "_iterator.next();");
+ writer.outputline(var.getSafeSymbol() + " = (" + var.getType().getGenerateType() + ") next(&"+var.getSafeSymbol()+"_iterator);");
}
-
- public int generate_worklistload(CodeWriter writer, int offset) {
+
+ public int generate_worklistload(CodeWriter writer, int offset) {
String varname = var.getSafeSymbol();
- writer.outputline("int " + varname + " = wi->word" + offset + ";");
- return offset + 1;
+ writer.outputline("int " + varname + " = wi->word" + offset + ";");
+ return offset + 1;
}
- public int generate_workliststore(CodeWriter writer, int offset) {
+ public int generate_workliststore(CodeWriter writer, int offset) {
String varname = var.getSafeSymbol();
writer.outputline("wi->word" + offset + " = " + varname + ";");
- return offset + 1;
+ return offset + 1;
}
String destname = dest.getSafeSymbol();
cr.outputline("int " + destname + ";");
- // ok... destination is declared... we gotta expand this rule inplace... and instead of the inclusion we
+ // ok... destination is declared... we gotta expand this rule inplace... and instead of the inclusion we
// set the destination in the guard ... otherwise maybe!
-
+
VarDescriptor domain = vd;
cr.pushSymbolTable(rule.getSymbolTable());
SetQuantifier sq = ((SetQuantifier) rule.quantifiers().next());
VarDescriptor rulebinding = sq.getVar();
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 + ";");
-
+
/* pretty print! */
- cr.outputline("// about to inbed relational function");
- cr.output("// ");
+ cr.outputline("/* about to inbed relational function*/");
+ cr.output("/* ");
rule.getGuardExpr().prettyPrint(cr);
- cr.outputline("");
-
+ cr.outputline("*/");
+
/* now we have to generate the guard test */
VarDescriptor guardval = VarDescriptor.makeNew();
rule.getGuardExpr().generate(cr, guardval);
-
+
cr.outputline("if (" + guardval.getSafeSymbol() + ")");
cr.startblock(); {
-
+
cr.outputline(destname + " = 1;");
-
+
} cr.endblock();
cr.outputline("else");
cr.startblock(); {
public TypeDescriptor typecheck(SemanticAnalyzer sa) {
throw new IRException();
}
-
+
}
this.state=state;
this.rg=rg;
try {
- cr=new StandardCodeWriter(new java.io.PrintWriter(new FileOutputStream("size.cc"),true));
+ cr=new StandardCodeWriter(new java.io.PrintWriter(new FileOutputStream("size.c"),true));
crhead=new StandardCodeWriter(new java.io.PrintWriter(new FileOutputStream("size.h"),true));
} catch (Exception e) {
e.printStackTrace();
}
str+="};";
cr.outputline(str);
-
- cr.outputline("int typeobject::size(int type) {");
+
+ cr.outputline("int size(int type) {");
cr.outputline("return arsize[type];");
cr.outputline("}");
- cr.outputline("int typeobject::sizeBytes(int type) {");
+ cr.outputline("int sizeBytes(int type) {");
cr.outputline("return arsizeBytes[type];");
cr.outputline("}");
- cr.outputline("int typeobject::numElements(int type, int fieldindex) {");
+ cr.outputline("int numElements(int type, int fieldindex) {");
cr.outputline("return arnumelements[type][fieldindex];");
cr.outputline("}");
- cr.outputline("typeobject::typeobject() {}");
}
private void generatecomputesize() {
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("void computesizes(struct "+rg.name+"_state * obj) {");
+ cr.outputline("int i;");
+ cr.outputline(rg.name+"_statecomputesizes(obj,arsize,arnumelements);");
+ cr.outputline("for(i=0;i<"+max+";i++) {");
cr.outputline("int bits=arsize[i];");
cr.outputline("int bytes=bits>>3;");
cr.outputline("if (bits%8) bytes++;");
private void generateheader() {
crhead.outputline("#include \""+rg.headername + "\"");
- crhead.outputline("class typeobject {");
- crhead.outputline("public:");
- crhead.outputline("typeobject();");
crhead.outputline("int getfield(int type, int fieldindex);");
crhead.outputline("int isArray(int type, int fieldindex);");
crhead.outputline("int isPtr(int type, int fieldindex);");
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 *);");
- crhead.outputline("};");
+ crhead.outputline("void computesizes(struct "+rg.name+"_state *);");
}
-
+
private void generategetfield() {
for(Iterator it=state.stTypes.descriptors();it.hasNext();) {
TypeDescriptor ttd=(TypeDescriptor)it.next();
}
str+="};";
cr.outputline(str);
-
- cr.outputline("int typeobject::getfield(int type, int fieldindex) {");
+
+ cr.outputline("int getfield(int type, int fieldindex) {");
cr.outputline("return argetfield[type][fieldindex];");
cr.outputline("}");
}
}
str+="};";
cr.outputline(str);
-
- cr.outputline("int typeobject::getnumfields(int type) {");
+
+ cr.outputline("int getnumfields(int type) {");
cr.outputline("return argetnumfield[type];");
cr.outputline("}");
}
}
str+="};";
cr.outputline(str);
-
- cr.outputline("int typeobject::isArray(int type, int fieldindex) {");
+
+ cr.outputline("int isArray(int type, int fieldindex) {");
cr.outputline("return arisArray[type][fieldindex];");
cr.outputline("}");
}
}
str+="};";
cr.outputline(str);
-
- cr.outputline("int typeobject::isPtr(int type, int fieldindex) {");
+
+ cr.outputline("int isPtr(int type, int fieldindex) {");
cr.outputline("return arisPtr[type][fieldindex];");
cr.outputline("}");
}
}
str+="};";
cr.outputline(str);
- cr.outputline("bool typeobject::issubtype(int subtype, int type) {");
+ cr.outputline("bool issubtype(int subtype, int type) {");
cr.outputline("return arissubtype[subtype][type];");
cr.outputline("}");
}
writer.outputline("int "+dest.getSafeSymbol()+"=0;");
VarDescriptor itvd=VarDescriptor.makeNew("iterator");
- writer.outputline("SimpleIterator "+itvd.getSafeSymbol()+";");
- writer.outputline(sd.getSafeSymbol()+"_hash->iterator("+itvd.getSafeSymbol()+");");
- writer.outputline("while ("+itvd.getSafeSymbol()+".hasNext()) {");
+ writer.outputline("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()+"="+itvd.getSafeSymbol()+".next();");
+ writer.outputline("int "+keyvd.getSafeSymbol()+"=next(&"+itvd.getSafeSymbol()+");");
VarDescriptor tmpvar=VarDescriptor.makeNew("tmp");
writer.outputline("int "+tmpvar.getSafeSymbol()+";");
- writer.outputline(rd.getSafeSymbol()+ "_hash->get("+keyvd.getSafeSymbol()+","+tmpvar.getSafeSymbol()+");");
+ writer.outputline("SimpleHashget("+rd.getSafeSymbol()+"_hash, "+keyvd.getSafeSymbol()+", &"+tmpvar.getSafeSymbol()+");");
writer.outputline(dest.getSafeSymbol()+"+="+tmpvar.getSafeSymbol()+";");
writer.outputline("}");
}
if ((left == null) || (right == null) || (relation == null)) {
throw new NullPointerException();
}
-
+
this.left = left;
this.right = right;
this.relation = relation;
VarDescriptor rd = VarDescriptor.makeNew();
right.generate(writer, rd);
- writer.outputline("int " + dest.getSafeSymbol() + " = " +
- relation.getSafeSymbol() + "_hash->contains(" +
+ writer.outputline("int " + dest.getSafeSymbol() + " = SimpleHashcontainskeydata("
+ +relation.getSafeSymbol() +"_hash, "+
ld.getSafeSymbol() + ", " +
rd.getSafeSymbol() + ");");
}
public TypeDescriptor typecheck(SemanticAnalyzer sa) {
TypeDescriptor ld = left.typecheck(sa);
TypeDescriptor rd = right.typecheck(sa);
-
+
if (ld == null || rd == null) {
return null;
}
st+="---------------------\n";
return st;
}
-
+
public void addBindings(Vector v) {
for (int i=0;i<v.size();i++) {
addBinding((Binding)v.get(i));
Descriptor d=u1.getDescriptor();
Expr subexpr=null;
Expr intindex=null;
-
+
if (u2.isField()) {
subexpr=((DotExpr)u2.getLeftExpr()).getExpr();
intindex=((DotExpr)u2.getLeftExpr()).getIndex();
continue; /* Abstract updates are already accounted for by graph */
if (u1.getDescriptor()!=u2.getDescriptor())
continue; /* No interference - different descriptors */
-
+
if ((u1.getOpcode()==Opcode.GT||u1.getOpcode()==Opcode.GE)&&
(u2.getOpcode()==Opcode.GT||u2.getOpcode()==Opcode.GE))
continue; /* Can be satisfied simultaneously */
toremove.add(u2);
continue;
}
-
+
/* Compatible operations < & <= */
if (((u1.getOpcode()==Opcode.LT)||(u1.getOpcode()==Opcode.LE))&&
((u2.getOpcode()==Opcode.LT)||(u2.getOpcode()==Opcode.LE)))
public Binding getBinding(int i) {
return (Binding)bindings.get(i);
}
-
+
public Binding getBinding(VarDescriptor vd) {
if (binding.containsKey(vd))
return (Binding)binding.get(vd);
boolean usageimage=rd.testUsage(RelationDescriptor.IMAGE);
boolean usageinvimage=rd.testUsage(RelationDescriptor.INVIMAGE);
if (usageimage)
- cr.outputline(rg.stmodel+"->"+rd.getJustSafeSymbol() + "_hash->remove((int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");");
+ cr.outputline("SimpleHashremove("+rg.stmodel+"->"+rd.getJustSafeSymbol()+"_hash, (int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");");
if (usageinvimage)
- cr.outputline(rg.stmodel+"->"+rd.getJustSafeSymbol() + "_hashinv->remove((int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
-
+ cr.outputline("SimpleHashremove("+rg.stmodel+"->"+rd.getJustSafeSymbol()+"_hashinv, (int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
+
for(int i=0;i<state.vRules.size();i++) {
Rule r=(Rule)state.vRules.get(i);
if (r.getInclusion().getTargetDescriptors().contains(rd)) {
if (un.getRule()==r) {
/* Update for rule rule r */
String name=(String)rg.updatenames.get(un);
- cr.outputline(rg.strepairtable+"->addrelation("+rd.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+","+rightvar.getSafeSymbol()+",(int) &"+name+");");
+ cr.outputline("RepairHashaddrelation("+rg.strepairtable+","+rd.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+","+rightvar.getSafeSymbol()+",(int) &"+name+");");
}
}
}
}
} else {
SetDescriptor sd=(SetDescriptor) d;
- cr.outputline(rg.stmodel+"->"+sd.getJustSafeSymbol() + "_hash->remove((int)" + leftvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
+ cr.outputline("SimpleHashremove("+rg.stmodel+"->"+sd.getJustSafeSymbol()+"_hash, (int)" + leftvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
for(int i=0;i<state.vRules.size();i++) {
Rule r=(Rule)state.vRules.get(i);
if (un.getRule()==r) {
/* Update for rule rule r */
String name=(String)rg.updatenames.get(un);
- cr.outputline(rg.strepairtable+"->addset("+sd.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+",(int) &"+name+");");
+ cr.outputline("RepairHashaddset("+rg.strepairtable+","+sd.getNum()+","+r.getNum()+","+leftvar.getSafeSymbol()+",(int) &"+name+");");
}
}
}
boolean usageimage=rd.testUsage(RelationDescriptor.IMAGE);
boolean usageinvimage=rd.testUsage(RelationDescriptor.INVIMAGE);
if (usageimage)
- cr.outputline(rg.stmodel+"->"+rd.getJustSafeSymbol() + "_hash->add((int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");");
+ cr.outputline("SimpleHashadd("+rg.stmodel+"->"+rd.getJustSafeSymbol()+"_hash, (int)" + leftvar.getSafeSymbol() + ", (int)" + rightvar.getSafeSymbol() + ");");
if (usageinvimage)
- cr.outputline(rg.stmodel+"->"+rd.getJustSafeSymbol() + "_hashinv->add((int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
+ cr.outputline("SimpleHashadd("+rg.stmodel+"->"+rd.getJustSafeSymbol()+"_hashinv, (int)" + rightvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
UpdateNode un=mun.getUpdate(0);
String name=(String)rg.updatenames.get(un);
cr.outputline(name+"(this,"+rg.stmodel+","+rg.strepairtable+","+leftvar.getSafeSymbol()+","+rightvar.getSafeSymbol()+");");
} else {
SetDescriptor sd=(SetDescriptor)d;
- cr.outputline(rg.stmodel+"->"+sd.getJustSafeSymbol() + "_hash->add((int)" + leftvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
+ cr.outputline("SimpleHashadd("+rg.stmodel+"->"+sd.getJustSafeSymbol()+"_hash, (int)" + leftvar.getSafeSymbol() + ", (int)" + leftvar.getSafeSymbol() + ");");
UpdateNode un=mun.getUpdate(0);
/* Update for rule rule r */
ArrayAnalysis.AccessPath ap=u.getAccessPath();
VarDescriptor init=VarDescriptor.makeNew("init");
if (ap.isSet()) {
- cr.outputline("int "+init.getSafeSymbol()+"="+ap.getSet().getSafeSymbol()+"_hash->firstkey();");
+ cr.outputline("int "+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()+"="+b.getSet().getSafeSymbol()+"_hash->firstkey();");
+ cr.outputline(vd.getType().getGenerateType().getSafeSymbol()+" "+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());
if (writer.getInvariantValue()!=null&&
writer.getInvariantValue().isInvariant(this)) {
- writer.outputline("maybe="+writer.getInvariantValue().getMaybe(this).getSafeSymbol()+";");
writer.outputline(vd.getType().getGenerateType().getSafeSymbol()+
" "+dest.getSafeSymbol()+"="+writer.getInvariantValue().getValue(this).getSafeSymbol()+";");
+ writer.outputline("maybe="+writer.getInvariantValue().getMaybe(this).getSafeSymbol()+";");
return;
}
writer.outputline(vd.getType().getGenerateType().getSafeSymbol() + " " + dest.getSafeSymbol() +
- " = (" + vd.getType().getGenerateType().getSafeSymbol() + ") " + vd.getSafeSymbol() + "; //varexpr");
+ " = (" + 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()+")");
public static Vector getrulelist(Descriptor d) {
Vector dispatchrules = new Vector();
- Vector rules = State.currentState.vRules;
-
+ Vector rules = State.currentState.vRules;
+
for (int i = 0; i < rules.size(); i++) {
Rule rule = (Rule) rules.elementAt(i);
Set requiredsymbols = rule.getRequiredDescriptors();
-
+
// #TBD#: in general this is wrong because these descriptors may contain descriptors
// bound in "in?" expressions which need to be dealt with in a topologically sorted
// fashion...
return dispatchrules;
}
-
+
public static void generate_dispatch(CodeWriter cr, RelationDescriptor rd, String leftvar, String rightvar) {
- cr.outputline("// RELATION DISPATCH ");
+ cr.outputline("/* RELATION DISPATCH */");
Vector dispatchrules = getrulelist(rd);
-
+
if (dispatchrules.size() == 0) {
- cr.outputline("// nothing to dispatch");
+ cr.outputline("/* nothing to dispatch*/");
return;
}
-
+
for(int i = 0; i < dispatchrules.size(); i++) {
Rule rule = (Rule) dispatchrules.elementAt(i);
cr.outputline("need to dispatch for " + rule.getLabel());
public static void generate_dispatch(CodeWriter cr, SetDescriptor sd, String setvar) {
-
- cr.outputline("// SET DISPATCH ");
-
+
+ cr.outputline("/* SET DISPATCH */");
+
Vector dispatchrules = getrulelist(sd);
if (dispatchrules.size() == 0) {
- cr.outputline("// nothing to dispatch");
+ cr.outputline("/* nothing to dispatch*/");
return;
}
for(int i = 0; i < dispatchrules.size(); i++) {
Rule rule = (Rule) dispatchrules.elementAt(i);
-
+
ListIterator quantifiers = rule.quantifiers();
Vector otherq = new Vector(); // quantifiers that we need to iterate over to add workitems
- cr.outputline("// " + rule.getLabel());
+ cr.outputline("/* " + rule.getLabel()+"*/");
cr.startblock();
-
+
// #ATTN#: this may/does not handle multiple instances of the same quantifier being bound
// solution is probabyl to iterate over all bindings
size += 8;
} else { // ForQuantifier
size += 4;
- }
+ }
- otherq.addElement(quantifier);
+ otherq.addElement(quantifier);
}
assert boundname != null;
// bind bound variable
cr.outputline("int " + boundname + " = " + setvar + ";");
-
+
// add the rest of the quantifiers and continue to calculate size
while (quantifiers.hasNext()) {
Quantifier quantifier = (Quantifier) quantifiers.next();
size += 4;
}
}
-
+
ListIterator otheriterator = otherq.listIterator();
while (otheriterator.hasNext()) {
- Quantifier quantifier = (Quantifier) otheriterator.next();
+ Quantifier quantifier = (Quantifier) otheriterator.next();
quantifier.generate_open(cr);
// implicitly opens bracket
- }
-
- cr.outputline("// dispatching to " + rule.getLabel());
+ }
+
+ cr.outputline("/* dispatching to " + rule.getLabel()+"*/");
// #TODO#: add code to do worklist addition
cr.outputline("WORKITEM *wi = (WORKITEM *) malloc(" + size + ");");
while (quantifiers.hasNext()) {
Quantifier quantifier = (Quantifier) quantifiers.next();
offset = quantifier.generate_workliststore(cr, offset);
- }
-
+ }
+
// now store in worklist!
- cr.outputline("WORKLIST->add((int) wi);");
-
+ cr.outputline("WORKLIST->add((int) wi);");
+
// close all those brackets
while (otheriterator.hasPrevious()) {
otheriterator.previous(); // throw away
cr.endblock();
- }
+ }
// end rule
cr.endblock();
- }
+ }
}
}
State state;
java.io.PrintWriter output = null;
-
+
public WorklistGenerator(State state) {
this.state = state;
}
public void generate(java.io.OutputStream output) {
- this.output = new java.io.PrintWriter(output, true);
-
+ this.output = new java.io.PrintWriter(output, true);
+
generate_tokentable();
generate_hashtables();
generate_worklist();
private void generate_tokentable() {
- CodeWriter cr = new StandardCodeWriter(output);
- Iterator tokens = TokenLiteralExpr.tokens.keySet().iterator();
+ CodeWriter cr = new StandardCodeWriter(output);
+ Iterator tokens = TokenLiteralExpr.tokens.keySet().iterator();
cr.outputline("");
- cr.outputline("// Token values");
+ cr.outputline("/* Token values*/");
cr.outputline("");
while (tokens.hasNext()) {
Object token = tokens.next();
- cr.outputline("// " + token.toString() + " = " + TokenLiteralExpr.tokens.get(token).toString());
+ cr.outputline("/* " + token.toString() + " = " + TokenLiteralExpr.tokens.get(token).toString()+"*/");
}
cr.outputline("");
private void generate_hashtables() {
CodeWriter cr = new StandardCodeWriter(output);
- cr.outputline("int __Success = 1;\n");
- cr.outputline("// creating hashtables ");
-
+ cr.outputline("int __Success = 1;\n");
+ cr.outputline("/* creating hashtables */");
+
/* build all the hashtables */
Hashtable hashtables = new Hashtable();
/* build sets */
Iterator sets = state.stSets.descriptors();
-
+
/* first pass create all the hash tables */
while (sets.hasNext()) {
SetDescriptor set = (SetDescriptor) sets.next();
cr.outputline("SimpleHash* " + set.getSafeSymbol() + "_hash = new SimpleHash();");
- }
-
+ }
+
/* second pass build relationships between hashtables */
sets = state.stSets.descriptors();
-
+
while (sets.hasNext()) {
SetDescriptor set = (SetDescriptor) sets.next();
Iterator subsets = set.subsets();
-
+
while (subsets.hasNext()) {
- SetDescriptor subset = (SetDescriptor) subsets.next();
+ SetDescriptor subset = (SetDescriptor) subsets.next();
cr.outputline(subset.getSafeSymbol() + "_hash->addParent(" + set.getSafeSymbol() + "_hash);");
}
- }
+ }
/* build relations */
Iterator relations = state.stRelations.descriptors();
-
+
/* first pass create all the hash tables */
while (relations.hasNext()) {
RelationDescriptor relation = (RelationDescriptor) relations.next();
-
+
if (relation.testUsage(RelationDescriptor.IMAGE)) {
cr.outputline("SimpleHash* " + relation.getSafeSymbol() + "_hash = new SimpleHash();");
}
if (relation.testUsage(RelationDescriptor.INVIMAGE)) {
cr.outputline("SimpleHash* " + relation.getSafeSymbol() + "_hashinv = new SimpleHash();");
- }
+ }
}
cr.outputline("");
cr.outputline("WORKLIST = new SimpleList();");
}
-
+
private void generate_teardown() {
- CodeWriter cr = new StandardCodeWriter(output);
+ CodeWriter cr = new StandardCodeWriter(output);
cr.outputline("WORKLIST->reset();");
cr.outputline("while (WORKLIST->hasMoreElements())");
cr.startblock();
cr.outputline("free ((WORKITEM *) WORKLIST->nextElement());");
- cr.endblock();
+ cr.endblock();
cr.outputline("delete WORKLIST;");
}
private void generate_rules() {
-
+
/* first we must sort the rules */
Iterator allrules = state.vRules.iterator();
worklistrules.add(rule);
}
}
-
+
Iterator iterator_er = emptyrules.iterator();
while (iterator_er.hasNext()) {
- Rule rule = (Rule) iterator_er.next();
+ Rule rule = (Rule) iterator_er.next();
{
- final SymbolTable st = rule.getSymbolTable();
+ final SymbolTable st = rule.getSymbolTable();
CodeWriter cr = new StandardCodeWriter(output) {
public SymbolTable getSymbolTable() { return st; }
};
-
- cr.outputline("// build " + rule.getLabel());
+
+ cr.outputline("/* build " + rule.getLabel()+"*/");
cr.startblock();
ListIterator quantifiers = rule.quantifiers();
while (quantifiers.hasNext()) {
- Quantifier quantifier = (Quantifier) quantifiers.next();
+ Quantifier quantifier = (Quantifier) quantifiers.next();
quantifier.generate_open(cr);
- }
-
+ }
+
/* pretty print! */
- cr.output("//");
+ cr.output("/*");
rule.getGuardExpr().prettyPrint(cr);
- cr.outputline("");
+ cr.outputline("*/");
/* now we have to generate the guard test */
-
+
VarDescriptor guardval = VarDescriptor.makeNew();
rule.getGuardExpr().generate(cr, guardval);
-
+
cr.outputline("if (" + guardval.getSafeSymbol() + ")");
cr.startblock();
}
}
- CodeWriter cr2 = new StandardCodeWriter(output);
+ CodeWriter cr2 = new StandardCodeWriter(output);
cr2.outputline("WORKLIST->reset();");
cr2.outputline("while (WORKLIST->hasMoreElements())");
cr2.startblock();
cr2.outputline("WORKITEM *wi = (WORKITEM *) WORKLIST->nextElement();");
-
+
String elseladder = "if";
Iterator iterator_rules = worklistrules.iterator();
while (iterator_rules.hasNext()) {
-
- Rule rule = (Rule) iterator_rules.next();
+
+ Rule rule = (Rule) iterator_rules.next();
int dispatchid = rule.getNum();
{
- final SymbolTable st = rule.getSymbolTable();
+ final SymbolTable st = rule.getSymbolTable();
CodeWriter cr = new StandardCodeWriter(output) {
public SymbolTable getSymbolTable() { return st; }
};
cr.outputline(elseladder + " (wi->id == " + dispatchid + ")");
cr.startblock();
- cr.outputline("// build " + rule.getLabel());
+ cr.outputline("/* build " + rule.getLabel()+"*/");
ListIterator quantifiers = rule.quantifiers();
int count = 0;
while (quantifiers.hasNext()) {
Quantifier quantifier = (Quantifier) quantifiers.next();
- count = quantifier.generate_worklistload(cr, count );
+ count = quantifier.generate_worklistload(cr, count );
}
-
+
/* pretty print! */
- cr.output("//");
+ cr.output("/*");
rule.getGuardExpr().prettyPrint(cr);
- cr.outputline("");
+ cr.outputline("*/");
/* now we have to generate the guard test */
-
+
VarDescriptor guardval = VarDescriptor.makeNew();
rule.getGuardExpr().generate(cr, guardval);
-
+
cr.outputline("if (" + guardval.getSafeSymbol() + ")");
cr.startblock();
cr.endblock();
// close startblocks generated by DotExpr memory checks
- //DotExpr.generate_memory_endblocks(cr);
+ //DotExpr.generate_memory_endblocks(cr);
cr.endblock(); // end else-if WORKLIST ladder
private void generate_implicit_checks() {
/* do post checks */
-
+
CodeWriter cr = new StandardCodeWriter(output);
-
+
// #TBD#: these should be implicit checks added to the set of constraints
//output.println("check multiplicity");
}
for (int i = 0; i < constraints.size(); i++) {
- Constraint constraint = (Constraint) constraints.elementAt(i);
+ Constraint constraint = (Constraint) constraints.elementAt(i);
{
final SymbolTable st = constraint.getSymbolTable();
-
+
CodeWriter cr = new StandardCodeWriter(output) {
public SymbolTable getSymbolTable() { return st; }
};
-
- cr.outputline("// checking " + constraint.getLabel());
+
+ cr.outputline("/* checking " + constraint.getLabel()+"*/");
cr.startblock();
ListIterator quantifiers = constraint.quantifiers();
while (quantifiers.hasNext()) {
- Quantifier quantifier = (Quantifier) quantifiers.next();
+ Quantifier quantifier = (Quantifier) quantifiers.next();
quantifier.generate_open(cr);
- }
+ }
cr.outputline("int maybe = 0;");
-
+
/* now we have to generate the guard test */
-
+
VarDescriptor constraintboolean = VarDescriptor.makeNew("constraintboolean");
constraint.getLogicStatement().generate(cr, constraintboolean);
-
+
cr.outputline("if (maybe)");
cr.startblock();
cr.outputline("__Success = 0;");
cr.outputline("");
cr.outputline("");
}
-
+
}
- output.println("// if (__Success) { printf(\"all tests passed\"); }");
- }
+ output.println("/* if (__Success) { printf(\"all tests passed\"); }*/");
+ }
}
-
-
-
IR/ElementOfExpr.class IR/Rule.class IR/Inclusion.class \
IR/CodeWriter.class IR/SymbolTableStack.class \
IR/StandardCodeWriter.class IR/SumExpr.class \
-IR/WorkList.class \
+IR/WorkList.class IR/PrintWrapper.class \
IR/RepairGenerator.class IR/AbstractInterferes.class \
IR/PrettyPrinter.class IR/AbstractRepair.class IR/Quantifiers.class \
IR/Binding.class IR/ConcreteInterferes.class IR/Conjunction.class \
-struct foo_state {int l;};
+#include "specs/x86/cache_aux.h"
+class typeobject {
+public:
+typeobject();
int getfield(int type, int fieldindex);
int isArray(int type, int fieldindex);
int isPtr(int type, int fieldindex);
int sizeBytes(int type);
int getnumfields(int type);
bool issubtype(int subtype, int type);
-void computesizes(struct foo_state *);
+void computesizes(foo_state *);
+};