Commit bcc898c3 authored by Alfons Laarman's avatar Alfons Laarman
Browse files

Turn off copy vector

parent 2a5d3a27
...@@ -193,6 +193,10 @@ public class Compile { ...@@ -193,6 +193,10 @@ public class Compile {
"make next-state a total function\n"); "make next-state a total function\n");
parser.addOption(total); parser.addOption(total);
final BooleanOption no_cpy = new BooleanOption('A',
"do not initialize copy _A_rrays\n");
parser.addOption(no_cpy);
final BooleanOption useNever = new BooleanOption('N', final BooleanOption useNever = new BooleanOption('N',
"Force use of never claim (slow; it is preferable to supply the LTL formula to LTSmin).\n"); "Force use of never claim (slow; it is preferable to supply the LTL formula to LTSmin).\n");
parser.addOption(useNever); parser.addOption(useNever);
...@@ -274,7 +278,8 @@ public class Compile { ...@@ -274,7 +278,8 @@ public class Compile {
Options opts = new Options(verbose.isSet(), no_guards.isSet(), Options opts = new Options(verbose.isSet(), no_guards.isSet(),
must_write.isSet(), !no_cnf.isSet(), must_write.isSet(), !no_cnf.isSet(),
java.isSet(), no_atomic.isSet(), total.isSet()); java.isSet(), no_atomic.isSet(),
total.isSet(), no_cpy.isSet());
final Specification spec = final Specification spec =
Compile.compile(file, !optimalizations.isSet("3"), opts); Compile.compile(file, !optimalizations.isSet("3"), opts);
......
...@@ -101,7 +101,7 @@ public class LTSminDMWalker { ...@@ -101,7 +101,7 @@ public class LTSminDMWalker {
} }
private static RWMatrix DUMMY_MATRIX = new RWMatrix(null, null, null); private static RWMatrix DUMMY_MATRIX = new RWMatrix(null, null, null);
private static Options DUMMY_OPTIONS = new Options(false, false, false, false, false, false, false); private static Options DUMMY_OPTIONS = new Options(false, false, false, false, false, false, false, false);
private static Params sParams = new Params(null, null, DUMMY_MATRIX, private static Params sParams = new Params(null, null, DUMMY_MATRIX,
0, DUMMY_OPTIONS); 0, DUMMY_OPTIONS);
public static void walkOneGuard(LTSminModel model, DepMatrix dm, public static void walkOneGuard(LTSminModel model, DepMatrix dm,
......
...@@ -412,13 +412,14 @@ public class LTSminPrinter { ...@@ -412,13 +412,14 @@ public class LTSminPrinter {
if (model.hasAtomicCycles) { if (model.hasAtomicCycles) {
w.appendLine("extern inline int spins_reach (void* model, transition_info_t *transition_info, state_t *in, void (*callback)(void* arg, transition_info_t *transition_info, state_t *out, int *cpy), void *arg, int pid, int *cpy);"); w.appendLine("extern inline int spins_reach (void* model, transition_info_t *transition_info, state_t *in, void (*callback)(void* arg, transition_info_t *transition_info, state_t *out, int *cpy), void *arg, int pid, int *cpy);");
} }
w.appendLine("extern inline int spins_simple_reach (void* model, transition_info_t *transition_info, state_t *in, void (*callback)(void* arg, transition_info_t *transition_info, state_t *out, int *cpy), void *arg, int pid, int *cpy);"); w.appendLine("extern inline int spins_simple_reach (void *model, transition_info_t *transition_info, state_t *in, void (*callback)(void* arg, transition_info_t *transition_info, state_t *out, int *cpy), void *arg, int pid, int *cpy);");
w.appendLine("extern int spins_get_successor_all (void* model, state_t *in, void (*callback)(void* arg, transition_info_t *transition_info, state_t *out, int *cpy), void *arg);"); w.appendLine("extern int spins_get_successor_all (void *model, state_t *in, void (*callback)(void* arg, transition_info_t *transition_info, state_t *out, int *cpy), void *arg);");
w.appendLine("extern int spins_get_successor (void* model, int t, state_t *in, void (*callback)(void* arg, transition_info_t *transition_info, state_t *out, int *cpy), void *arg);"); w.appendLine("extern int spins_get_successor (void *model, int t, state_t *in, void (*callback)(void* arg, transition_info_t *transition_info, state_t *out, int *cpy), void *arg);");
w.appendLine("extern int spins_get_actions (void* model, int t, state_t *in, void (*callback)(void* arg, transition_info_t *transition_info, state_t *out, int *cpy), void *arg);"); w.appendLine("extern int spins_get_actions (void *model, int t, state_t *in, void (*callback)(void* arg, transition_info_t *transition_info, state_t *out, int *cpy), void *arg);");
w.appendLine("extern void spins_atomic_cb (void* arg, transition_info_t *transition_info, state_t *out, int atomic, int *cpy);"); w.appendLine("extern void spins_atomic_cb (void *arg, transition_info_t *transition_info, state_t *out, int atomic, int *cpy);");
w.appendLine("extern void spins_simple_atomic_cb (void* arg, transition_info_t *transition_info, state_t *out, int atomic, int *cpy);"); w.appendLine("extern void spins_simple_atomic_cb (void *arg, transition_info_t *transition_info, state_t *out, int atomic, int *cpy);");
w.appendLine("extern int *spins_get_guards (state_t *in);"); w.appendLine("extern int *spins_get_guards (state_t *in);");
w.appendLine("extern int spins_get_label (void *model, int g, state_t *in);");
w.appendLine(""); w.appendLine("");
} }
...@@ -472,20 +473,10 @@ public class LTSminPrinter { ...@@ -472,20 +473,10 @@ public class LTSminPrinter {
w.appendLine(""); w.appendLine("");
} }
private static void generateACallback(StringWriter w, LTSminModel model,
LTSminTransition t) {
printEdgeLabels(w, model, t);
w.appendLine("transition_info.group = "+ t.getGroup() +";");
w.appendLine("callback(arg,&transition_info,"+ OUT_VAR +",cpy);");
w.appendLine("++states_emitted;");
}
private static void printEdgeLabels(StringWriter w, LTSminModel model, private static void printEdgeLabels(StringWriter w, LTSminModel model,
LTSminTransition t) { LTSminTransition t) {
int index = model.getEdgeIndex(STATEMENT_EDGE_LABEL_NAME);
w.appendLine("transition_labels["+ index +"] = "+ t.getGroup() +";"); // index
if (t.isProgress()) { if (t.isProgress()) {
index = model.getEdgeIndex(ACTION_EDGE_LABEL_NAME); int index = model.getEdgeIndex(ACTION_EDGE_LABEL_NAME);
int value = model.getTypeValueIndex(ACTION_TYPE_NAME, PROGRESS_ACTION_NAME); int value = model.getTypeValueIndex(ACTION_TYPE_NAME, PROGRESS_ACTION_NAME);
w.appendLine("transition_labels["+ index +"] = "+ value +";"); // index w.appendLine("transition_labels["+ index +"] = "+ value +";"); // index
} }
...@@ -524,7 +515,10 @@ public class LTSminPrinter { ...@@ -524,7 +515,10 @@ public class LTSminPrinter {
if (guards == 0) w.append("true"); w.append(") {").appendPostfix(); if (guards == 0) w.append("true"); w.append(") {").appendPostfix();
w.indent(); w.indent();
w.appendLine("memcpy(", OUT_VAR,", ", IN_VAR , ", sizeof(", C_STATE,"));"); w.appendLine("memcpy(", OUT_VAR,", ", IN_VAR , ", sizeof(", C_STATE,"));");
w.appendLine("int cpy[" + model.sv.size() + "]; memcpy(cpy, cpy_src, sizeof(int[" + model.sv.size() + "]));"); if (!w.options.no_cpy)
w.appendLine("int cpy[" + model.sv.size() + "]; memcpy(cpy, cpy_src, sizeof(int[" + model.sv.size() + "]));");
else
w.appendLine("int *cpy = NULL;");
w.appendPostfix(); w.appendPostfix();
List<Action> actions = t.getActions(); List<Action> actions = t.getActions();
...@@ -595,18 +589,8 @@ public class LTSminPrinter { ...@@ -595,18 +589,8 @@ public class LTSminPrinter {
w.appendLine("int spins_get_successor_all( void* model, state_t *in, void (*callback)(void* arg, transition_info_t *transition_info, state_t *out, int *cpy), void *arg) {"); w.appendLine("int spins_get_successor_all( void* model, state_t *in, void (*callback)(void* arg, transition_info_t *transition_info, state_t *out, int *cpy), void *arg) {");
w.indent(); w.indent();
String edge_array = "";
for (int i = 0; i < model.getEdges().size(); i++)
edge_array += "0, ";
w.appendLine("int transition_labels["+ model.getEdges().size() +"] = {"+ edge_array +"};");
w.appendLine("transition_info_t transition_info = { transition_labels, -1 };");
w.appendLine("int states_emitted = 0;"); w.appendLine("int states_emitted = 0;");
w.appendLine("int *__guards = spins_get_guards(in);"); w.appendLine("int *__guards = spins_get_guards(in);");
w.appendLine("state_t tmp;");
w.appendLine("state_t *"+ OUT_VAR +" = &tmp;");
for (Variable local : model.getLocals()) {
w.appendLine("int "+ local.getName() +";");
}
generateAssertions(w, model); generateAssertions(w, model);
w.appendLine(); w.appendLine();
List<LTSminTransition> transitions = model.getTransitions(); List<LTSminTransition> transitions = model.getTransitions();
...@@ -647,10 +631,17 @@ public class LTSminPrinter { ...@@ -647,10 +631,17 @@ public class LTSminPrinter {
} }
} }
} else { } else {
LTSminGuardBase last = t.getGuards().get(t.getGuards().size() - 1); // LTSminGuardBase last = t.getGuards().get(t.getGuards().size() - 1);
for (LTSminGuardBase g : t.getGuards()) { // for (LTSminGuardBase g : t.getGuards()) {
guards += generateGuard(w, model, g, in(model)); // guards += generateGuard(w, model, g, in(model));
if (g != last) { // if (g != last) {
// w.append(" &&").appendPostfix().appendPrefix();
// }
// }
List<Integer> gs = model.getGuardInfo().getTransMatrix().get(t.getIndex());
for (int g : gs) {
w.append("spins_get_label(NULL, "+ g +", "+ IN_VAR +")");
if (++guards != gs.size()) {
w.append(" &&").appendPostfix().appendPrefix(); w.append(" &&").appendPostfix().appendPrefix();
} }
} }
...@@ -658,21 +649,17 @@ public class LTSminPrinter { ...@@ -658,21 +649,17 @@ public class LTSminPrinter {
if (guards == 0) w.append("true"); if (guards == 0) w.append("true");
w.outdent(); w.outdent();
w.append(") {").appendPostfix(); w.append(") {").appendPostfix();
w.indent(); w.indent();
//generateActions(w, t, model); //generateActions(w, t, model);
w.appendLine("states_emitted += spins_get_actions (model, "+ t.getGroup() +", in, callback, arg);"); w.appendLine("states_emitted += spins_get_actions (model, "+ t.getGroup() +", in, callback, arg);");
if (many && (hasAssert(t.getActions()) || t.isProgress())) {
int index = model.getEdgeIndex(ACTION_EDGE_LABEL_NAME);
w.appendLine("transition_labels["+ index +"] = "+ 0 +";");
}
w.outdent(); w.outdent();
w.appendLine("}"); w.appendLine("}");
} }
private static void generateActions(StringWriter w, LTSminTransition t, private static void generateActions(StringWriter w, LTSminTransition t,
LTSminModel model) { LTSminModel model) {
w.appendLine("memcpy(", OUT_VAR,", ", IN_VAR , ", sizeof(", C_STATE,"));");
List<Action> actions = t.getActions(); List<Action> actions = t.getActions();
if (w.options.total) if (w.options.total)
w.appendLine("while (1) {").indent(); w.appendLine("while (1) {").indent();
...@@ -687,17 +674,17 @@ public class LTSminPrinter { ...@@ -687,17 +674,17 @@ public class LTSminPrinter {
w.appendLine("break;").outdent(); w.appendLine("break;").outdent();
w.appendLine("}"); w.appendLine("}");
} }
printEdgeLabels (w, model, t);
if (t.isAtomic()) { if (t.isAtomic()) {
printEdgeLabels (w, model, t);
w.appendLine("transition_info.group = "+ t.getGroup() +";"); w.appendLine("transition_info.group = "+ t.getGroup() +";");
if (t.getEnd().liesOnCycle()) { if (t.getEnd().liesOnCycle()) {
w.appendLine("int count = spins_reach (model, &transition_info, "+ OUT_VAR +", callback, arg, "+ t.getEndId() +", cpy);"); w.appendLine("int count = spins_reach (model, &transition_info, "+ OUT_VAR +", callback, arg, "+ t.getEndId() +", cpy);");
} else { } else {
w.appendLine("int count = spins_simple_reach (model, &transition_info, "+ OUT_VAR +", callback, arg, "+ t.getEndId() +", cpy);"); w.appendLine("int count = spins_simple_reach (model, &transition_info, "+ OUT_VAR +", callback, arg, "+ t.getEndId() +", cpy);");
} }
w.appendLine("states_emitted += count;"); // non-deterministic atomic sequences emit multiple states w.appendLine("return count;");
} else { } else {
generateACallback(w, model, t); w.appendLine("break;");
} }
} }
...@@ -718,19 +705,7 @@ public class LTSminPrinter { ...@@ -718,19 +705,7 @@ public class LTSminPrinter {
private static void generateGetNext(StringWriter w, LTSminModel model) { private static void generateGetNext(StringWriter w, LTSminModel model) {
w.appendLine("int spins_get_successor (void* model, int t, state_t *in, void (*callback)(void* arg, transition_info_t *transition_info, state_t *out, int *cpy), void *arg) {"); w.appendLine("int spins_get_successor (void* model, int t, state_t *in, void (*callback)(void* arg, transition_info_t *transition_info, state_t *out, int *cpy), void *arg) {");
w.indent(); w.indent();
String edge_array = "";
for (int i = 0; i < model.getEdges().size(); i++)
edge_array += "0, ";
w.appendLine("int transition_labels["+ model.getEdges().size() +"] = {"+ edge_array +"};");
w.appendLine("transition_info_t transition_info = { transition_labels, t };");
w.appendLine("int states_emitted = 0;"); w.appendLine("int states_emitted = 0;");
w.appendLine("int minus_one = -1;");
w.appendLine("int *atomic = &minus_one;");
w.appendLine(C_STATE," local_state;");
w.appendLine(C_STATE,"* ",OUT_VAR," = &local_state;");
for (Variable local : model.getLocals()) {
w.appendLine("int "+ local.getName() +";");
}
generateAssertions(w, model); generateAssertions(w, model);
w.appendLine(); w.appendLine();
w.appendLine("switch(t) {"); w.appendLine("switch(t) {");
...@@ -759,18 +734,25 @@ public class LTSminPrinter { ...@@ -759,18 +734,25 @@ public class LTSminPrinter {
for (int i = 0; i < model.getEdges().size(); i++) for (int i = 0; i < model.getEdges().size(); i++)
edge_array += "0, "; edge_array += "0, ";
w.appendLine("int transition_labels["+ model.getEdges().size() +"] = {"+ edge_array +"};"); w.appendLine("int transition_labels["+ model.getEdges().size() +"] = {"+ edge_array +"};");
int index = model.getEdgeIndex(STATEMENT_EDGE_LABEL_NAME);
w.appendLine("transition_labels["+ index +"] = t;"); // index
w.appendLine("transition_info_t transition_info = { transition_labels, t };"); w.appendLine("transition_info_t transition_info = { transition_labels, t };");
w.appendLine("int states_emitted = 0;"); w.appendLine("transition_info.group = t;");
w.appendLine("int minus_one = -1;"); w.appendLine("int minus_one = -1;");
w.appendLine("int *atomic = &minus_one;"); w.appendLine("int *atomic = &minus_one;");
w.appendLine(C_STATE," local_state;"); w.appendLine(C_STATE," local_state;");
w.appendLine(C_STATE,"* ",OUT_VAR," = &local_state;"); w.appendLine(C_STATE,"* ",OUT_VAR," = &local_state;");
w.appendLine("memcpy(", OUT_VAR,", ", IN_VAR , ", sizeof(", C_STATE,"));");
w.appendPrefix(); if (!w.options.no_cpy) {
w.append("int cpy[" + model.sv.size() + "] = { "); w.appendPrefix();
for (int i = 0; i < model.sv.size(); i++) w.append("1,"); w.append("int cpy[" + model.sv.size() + "] = { ");
w.append(" };"); for (int i = 0; i < model.sv.size(); i++) w.append("1,");
w.appendPostfix(); w.append(" };");
w.appendPostfix();
} else {
w.appendLine("int *cpy = NULL;");
}
for (Variable local : model.getLocals()) { for (Variable local : model.getLocals()) {
w.appendLine("int "+ local.getName() +";"); w.appendLine("int "+ local.getName() +";");
...@@ -785,13 +767,17 @@ public class LTSminPrinter { ...@@ -785,13 +767,17 @@ public class LTSminPrinter {
w.indent(); w.indent();
w.appendLine("// "+ t.getName()); w.appendLine("// "+ t.getName());
generateActions (w, t, model); generateActions (w, t, model);
w.appendLine("return states_emitted;");
w.outdent(); w.outdent();
w.appendLine("}"); w.appendLine("}");
++trans; ++trans;
} }
w.appendLine("}"); w.appendLine("}");
w.appendLine("return 0;");
w.appendLine("callback(arg,&transition_info,"+ OUT_VAR +",cpy);");
int aindex = model.getEdgeIndex(ACTION_EDGE_LABEL_NAME);
w.appendLine("transition_labels["+ aindex +"] = "+ 0 +";");
w.appendLine("return 1;");
w.outdent(); w.outdent();
w.appendLine("}"); w.appendLine("}");
w.appendLine(); w.appendLine();
...@@ -871,12 +857,15 @@ public class LTSminPrinter { ...@@ -871,12 +857,15 @@ public class LTSminPrinter {
String struct_t = model.sv.getMember(rpa.getProcess()).getType().getName(); String struct_t = model.sv.getMember(rpa.getProcess()).getType().getName();
w.appendLine("#ifndef NORESETPROCESS"); w.appendLine("#ifndef NORESETPROCESS");
w.appendLine("memcpy(&",OUT_VAR,"->"+ name +", (char*)&(",INITIAL_VAR,".",name,"), sizeof("+ struct_t +"));"); w.appendLine("memcpy(&",OUT_VAR,"->"+ name +", (char*)&(",INITIAL_VAR,".",name,"), sizeof("+ struct_t +"));");
w.appendLine("memset(&((state_t *)cpy)->"+ name +", 0, sizeof("+ struct_t +"));"); if (!w.options.no_cpy)
w.appendLine("memset(&((state_t *)cpy)->"+ name +", 0, sizeof("+ struct_t +"));");
LTSminSubVector sub = model.sv.sub(rpa.getProcess()); LTSminSubVector sub = model.sv.sub(rpa.getProcess());
for (LTSminSlot slot : sub) { if (!w.options.no_cpy) {
w.appendPrefix(); for (LTSminSlot slot : sub) {
w.append("cpy["+ slot.getIndex() +"] = 0;"); w.appendPrefix();
w.appendPostfix(); w.append("cpy["+ slot.getIndex() +"] = 0;");
w.appendPostfix();
}
} }
w.appendLine("#endif"); w.appendLine("#endif");
...@@ -1212,6 +1201,7 @@ public class LTSminPrinter { ...@@ -1212,6 +1201,7 @@ public class LTSminPrinter {
private static void copyAccess(LTSminModel model, StringWriter w, Identifier id) { private static void copyAccess(LTSminModel model, StringWriter w, Identifier id) {
if (id.getVariable().isHidden() || id instanceof LTSminIdentifier) return; if (id.getVariable().isHidden() || id instanceof LTSminIdentifier) return;
if (id.isConstant()) return; if (id.isConstant()) return;
if (w.options.no_cpy) return;
String var = print(id, out(model)); String var = print(id, out(model));
...@@ -1924,7 +1914,7 @@ public class LTSminPrinter { ...@@ -1924,7 +1914,7 @@ public class LTSminPrinter {
w.appendLine("}"); w.appendLine("}");
w.appendLine(""); w.appendLine("");
w.appendLine("int spins_get_label(void* model, int g, ",C_STATE,"* ",IN_VAR,") {"); w.appendLine("int spins_get_label(void *model, int g, ",C_STATE,"* ",IN_VAR,") {");
w.indent(); w.indent();
w.appendLine("(void)model;"); w.appendLine("(void)model;");
w.appendLine("assert(g < ",gm.getNumberOfLabels(),", \"spins_get_label: invalid state label index %d\", g);"); w.appendLine("assert(g < ",gm.getNumberOfLabels(),", \"spins_get_label: invalid state label index %d\", g);");
...@@ -1956,10 +1946,14 @@ public class LTSminPrinter { ...@@ -1956,10 +1946,14 @@ public class LTSminPrinter {
w.appendLine("switch(g) {"); w.appendLine("switch(g) {");
w.indent(); w.indent();
for (int g = 0; g < gm.getNumberOfLabels(); ++g) { for (int g = 0; g < gm.getNumberOfLabels(); ++g) {
if (gm.getLabelName(g).startsWith("guard_")) {
continue;
}
w.appendPrefix(); w.appendPrefix();
w.append("case "+ g +": return \""+ gm.getLabelName(g) +"\";"); w.append("case "+ g +": return \""+ gm.getLabelName(g) +"\";");
w.appendPostfix(); w.appendPostfix();
} }
w.append("default: { static char c[100]; snprintf(c, 100, \"guard_%d\", g); return c; }");
w.outdent(); w.outdent();
w.appendLine("}"); w.appendLine("}");
w.appendLine("return \"\";"); w.appendLine("return \"\";");
......
...@@ -173,7 +173,7 @@ public class LTSminTreeWalker { ...@@ -173,7 +173,7 @@ public class LTSminTreeWalker {
public Options(boolean verbose, boolean no_gm, boolean must_write, public Options(boolean verbose, boolean no_gm, boolean must_write,
boolean cnf, boolean cnf,
boolean unless_java_semantics, boolean no_atomic, boolean unless_java_semantics, boolean no_atomic,
boolean total) { boolean total, boolean no_cpy) {
this.verbose = verbose; this.verbose = verbose;
this.no_gm = no_gm; this.no_gm = no_gm;
this.must_write = must_write; this.must_write = must_write;
...@@ -181,6 +181,7 @@ public class LTSminTreeWalker { ...@@ -181,6 +181,7 @@ public class LTSminTreeWalker {
this.unless_java_semantics = unless_java_semantics; this.unless_java_semantics = unless_java_semantics;
this.no_atomic = no_atomic; this.no_atomic = no_atomic;
this.total = total; this.total = total;
this.no_cpy = no_cpy;
} }
public boolean verbose = false; public boolean verbose = false;
public boolean no_gm = false; public boolean no_gm = false;
...@@ -189,6 +190,7 @@ public class LTSminTreeWalker { ...@@ -189,6 +190,7 @@ public class LTSminTreeWalker {
public boolean unless_java_semantics = false; public boolean unless_java_semantics = false;
public boolean no_atomic = false; public boolean no_atomic = false;
public boolean total = false; public boolean total = false;
public boolean no_cpy = false;
} }
TimeoutExpression timeout = null; TimeoutExpression timeout = null;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment