try {
FileOutputStream gcode = new FileOutputStream(cli.infile + ".cc");
+
+ // do model optimizations
+ (new Optimizer(state)).optimize();
+
NaiveGenerator ng = new NaiveGenerator(state);
ng.generate(gcode);
+ //WorklistGenerator wg = new WorklistGenerator(state);
+ //wg.generate(gcode);
gcode.close();
} catch (Exception e) {
e.printStackTrace();
public void startblock();
public void endblock();
+ public void pushSymbolTable(SymbolTable st);
+ public SymbolTable popSymbolTable();
public SymbolTable getSymbolTable();
}
Vector quantifiers = new Vector();
LogicStatement logicstatement = null;
+ int num;
+
public Constraint() {
+ num = count;
label = new String("c" + count++);
}
+ public int getNum() {
+ return num;
+ }
+
public String getLabel() {
return label;
}
return v;
}
+ public Expr getExpr() {
+ return left;
+ }
+
public void generate(CodeWriter writer, VarDescriptor dest) {
VarDescriptor leftd = VarDescriptor.makeNew("left");
public abstract void prettyPrint(PrettyPrinter pp);
+ public Set getInversedRelations() {
+ throw new IRException("unsupported");
+ }
+
}
this.inverse = inverse;
}
+ public VarDescriptor getVar() {
+ return vd;
+ }
+
+ public RelationDescriptor getRelation() {
+ return rd;
+ }
+
+ public Set getInversedRelations() {
+ HashSet set = new HashSet();
+ if (inverse) {
+ set.add(rd);
+ }
+ return set;
+ }
+
public Set getRequiredDescriptors() {
HashSet v = new HashSet();
v.add(rd);
}
public void prettyPrint(PrettyPrinter pp) {
- throw new IRException("not supported");
+ pp.output(vd.toString());
+ pp.output(".");
+ if (inverse) {
+ pp.output("~");
+ }
+ pp.output(rd.toString());
}
public TypeDescriptor typecheck(SemanticAnalyzer sa) {
expr.generate(writer, var);
setexpr.generate_inclusion(writer, dest, var);
}
+
+ public Set getInversedRelations() {
+
+ throw new IRException("unsupported");
+
+ //Set set = setexpr.getInversedRelations();
+ //set.addAll(expr.getInversedRelations());
+ //return set;
+ }
}
return new HashSet();
}
+ public Set getInversedRelations() {
+ return new HashSet();
+ }
+
}
public static final Operation AND = new Operation("AND");
public static final Operation OR = new Operation("OR");
public static final Operation NOT = new Operation("NOT");
+
+ public Set getInversedRelations() {
+ if (left == null) {
+ throw new IRException();
+ }
+
+ Set set = left.getInversedRelations();
+ if (right != null) {
+ set.addAll(right.getInversedRelations());
+ }
+ return set;
+ }
public static class Operation {
private final String name;
GraphNode rulenode = (GraphNode) rules.next();
Rule rule = (Rule) rulenode.getOwner();
+ if (!state.vRules.contains(rule)) {
+ // this is no longer a top-level rule
+ continue;
+ }
+
{
- final SymbolTable st = rule.getSymbolTable();
- CodeWriter cr = new StandardCodeWriter(output) {
- public SymbolTable getSymbolTable() { return st; }
- };
+ CodeWriter cr = new StandardCodeWriter(output);
+ cr.pushSymbolTable(rule.getSymbolTable());
cr.outputline("// build " + rule.getLabel());
cr.startblock();
{
- final SymbolTable st = constraint.getSymbolTable();
-
- CodeWriter cr = new StandardCodeWriter(output) {
- public SymbolTable getSymbolTable() { return st; }
- };
+ CodeWriter cr = new StandardCodeWriter(output);
+ cr.pushSymbolTable(constraint.getSymbolTable());
cr.outputline("// checking " + constraint.getLabel());
cr.startblock();
cr.outputline("if (maybe)");
cr.startblock();
cr.outputline("__Success = 0;");
- cr.outputline("printf(\"maybe fail " + (i+1) + ". \");");
+ cr.outputline("printf(\"maybe fail " + constraint.getNum() + ". \");");
+ cr.outputline("exit(1);");
cr.endblock();
cr.outputline("else if (!" + constraintboolean.getSafeSymbol() + ")");
cr.startblock();
cr.outputline("__Success = 0;");
- cr.outputline("printf(\"fail " + (i+1) + ". \");");
+ cr.outputline("printf(\"fail " + constraint.getNum() + ". \");");
+ cr.outputline("exit(1);");
cr.endblock();
while (quantifiers.hasPrevious()) {
}
- output.println("if (__Success) { printf(\"all tests passed\"); }");
+ output.println("//if (__Success) { printf(\"all tests passed\"); }");
}
}
assert (right == null && opcode == Opcode.NOT) || (right != null);
}
+ public Set getInversedRelations() {
+ Set set = left.getInversedRelations();
+ if (right != null) {
+ set.addAll(right.getInversedRelations());
+ }
+ return set;
+ }
+
public Set getRequiredDescriptors() {
Set v = left.getRequiredDescriptors();
this.inverse = inverse;
}
+ public Expr getExpr() {
+ return expr;
+ }
+
+ public RelationDescriptor getRelation() {
+ return relation;
+ }
+
+ public Set getInversedRelations() {
+ Set set = expr.getInversedRelations();
+ if (inverse) {
+ set.add(relation);
+ }
+ return set;
+ }
+
public Set getRequiredDescriptors() {
Set v = expr.getRequiredDescriptors();
v.add(relation);
// #TBD#: this flag needs to be set by some static analysis
boolean typesafe = true;
- static boolean worklist = true;
+ static boolean worklist = false;
public RelationInclusion(Expr leftelementexpr, Expr rightelementexpr, RelationDescriptor relation) {
this.leftelementexpr = leftelementexpr;
this.relation = relation;
}
+ public Expr getLeftExpr() {
+ return leftelementexpr;
+ }
+
+ public Expr getRightExpr() {
+ return rightelementexpr;
+ }
+
+ public RelationDescriptor getRelation() {
+ return relation;
+ }
+
public Set getTargetDescriptors() {
HashSet v = new HashSet();
v.add(relation);
return st;
}
+ public Set getQuantifierDescriptors() {
+
+ HashSet topdescriptors = new HashSet();
+
+ for (int i = 0; i < quantifiers.size(); i++) {
+ Quantifier q = (Quantifier) quantifiers.elementAt(i);
+ topdescriptors.addAll(q.getRequiredDescriptors());
+ }
+
+ return SetDescriptor.expand(topdescriptors);
+ }
+
+
public Set getRequiredDescriptors() {
HashSet topdescriptors = new HashSet();
this.sd = null;
}
+ public Set getInversedRelations() {
+ return new HashSet();
+ }
+
public Set getRequiredDescriptors() {
HashSet v = new HashSet();
v.add(sd);
Expr elementexpr;
SetDescriptor set;
- static boolean worklist = true;
+ public String generatedresult = null;
+ public String generatedaddeditem = null;
+
+ static boolean worklist = false;
+ public boolean dostore = true;
public SetInclusion(Expr elementexpr, SetDescriptor set) {
this.elementexpr = elementexpr;
this.set = set;
}
+ public SetDescriptor getSet() {
+ return set;
+ }
+
public Set getTargetDescriptors() {
HashSet v = new HashSet();
v.add(set);
VarDescriptor vd = VarDescriptor.makeNew("element");
elementexpr.generate(writer, vd);
+ // allows access to the value of this set addition later
+ generatedresult = vd.getSafeSymbol();
+
String addeditem = (VarDescriptor.makeNew("addeditem")).getSafeSymbol();
- writer.outputline("int " + addeditem + ";");
+ generatedaddeditem = addeditem; // allows access to the result of the set addition later.
+
+ // we set equal to one so that if dostore == false the guard in teh
+ // metainclusion generation for the subrules and sub quantifiers will go on
+ writer.outputline("int " + addeditem + " = 1;");
+
+ if (dostore) {
- writer.outputline(addeditem + " = " + set.getSafeSymbol() + "_hash->add((int)" + vd.getSafeSymbol()
- + ", (int)" + vd.getSafeSymbol() + ");");
+ writer.outputline(addeditem + " = " + set.getSafeSymbol() + "_hash->add((int)" + vd.getSafeSymbol()
+ + ", (int)" + vd.getSafeSymbol() + ");");
- if (SetInclusion.worklist) {
- writer.outputline("if (" + addeditem + ")");
- writer.startblock(); {
- WorkList.generate_dispatch(writer, set, vd.getSafeSymbol());
+ if (SetInclusion.worklist) {
+ writer.outputline("if (" + addeditem + ")");
+ writer.startblock(); {
+ WorkList.generate_dispatch(writer, set, vd.getSafeSymbol());
+ }
+ writer.endblock();
}
- writer.endblock();
+
}
}
this.setexpr = setexpr;
}
+ public SetExpr getSetExpr() {
+ return setexpr;
+ }
+
public Set getRequiredDescriptors() {
return setexpr.getRequiredDescriptors();
}
return this.td;
}
+ public Set getInversedRelations() {
+ return setexpr.getInversedRelations();
+ }
}
this.varname = varname;
}
+ public Set getInversedRelations() {
+ return new HashSet();
+ }
+
public Set getRequiredDescriptors() {
return new HashSet();
}
+
+ public VarDescriptor getVar() {
+ return vd;
+ }
public void generate(CodeWriter writer, VarDescriptor dest) {
IR/DependencyBuilder.class IR/RelationInclusion.class IR/SetInclusion.class \
IR/TupleOfExpr.class IR/ElementOfExpr.class IR/Rule.class IR/Inclusion.class \
IR/NaiveGenerator.class IR/CodeWriter.class IR/SymbolTableStack.class \
-IR/StandardCodeWriter.class
+IR/StandardCodeWriter.class IR/WorklistGenerator.class IR/WorkList.class \
+IR/Optimizer.class IR/MetaInclusion.class IR/SizeofFunction.class \
+IR/RelationFunctionExpr.class
#MODEL_CLASS = Field.class Literal.class Quantifier.class \
#Set.class TypeElement.class \