use of dartagnan.program.Init in project Dat3M by hernanponcedeleon.
the class Utils method drawGraph.
public static void drawGraph(Program p, Context ctx, Model model, String filename, String[] relations) throws IOException {
File newTextFile = new File(filename);
FileWriter fw = new FileWriter(newTextFile);
GraphViz gv = new GraphViz();
gv.addln(gv.start_graph());
gv.addln(" subgraph cluster_Source { rank=sink; fontsize=20; label = \"Program Compiled to Source Architecture\"; color=red; shape=box;");
int tid = 0;
for (dartagnan.program.Thread t : p.getThreads()) {
tid++;
if (!(t instanceof Init)) {
gv.addln(" subgraph cluster_Thread_Source" + t.getTId() + " { rank=sink; fontsize=15; label = \"Thread " + tid + "\"; color=magenta; shape=box;");
}
for (Event e : p.getEvents()) {
String label = "";
if (!(e instanceof MemEvent)) {
continue;
}
if ((e instanceof Store || e instanceof Init) && model.getConstInterp(e.executes(ctx)).isTrue()) {
label = "W_" + e.getLoc() + "_" + model.getConstInterp(((MemEvent) e).ssaLoc).toString() + "\\n";
}
if (e instanceof Load && model.getConstInterp(e.executes(ctx)).isTrue()) {
label = "R_" + e.getLoc() + "_" + model.getConstInterp(((MemEvent) e).ssaLoc).toString() + "\\n";
}
for (Event eHL : p.getEvents().stream().filter(x -> x instanceof MemEvent).collect(Collectors.toSet())) {
if (!(e instanceof Init) && e.getHLId() != null && e.getHLId() == eHL.hashCode()) {
label = label + eHL.toString().replaceAll("\\s", "");
}
}
if ((e instanceof Store || e instanceof Load) && e.getMainThread() == t.getTId() && model.getConstInterp(e.executes(ctx)).isTrue()) {
gv.addln(" " + e.repr() + " [label=\"" + label + "\", shape=\"box\", color=\"blue\", group=s" + e.getMainThread() + "];");
}
if (e instanceof Init && e.getMainThread() == t.getTId() && model.getConstInterp(e.executes(ctx)).isTrue()) {
gv.addln(" " + e.repr() + " [label=\"" + label + "\", shape=\"box\", color=\"blue\", root=true];");
}
}
if (!(t instanceof Init)) {
gv.addln(" }");
}
}
for (Event e1 : p.getEvents()) {
for (Event e2 : p.getEvents()) {
if (!(e1 instanceof MemEvent && e2 instanceof MemEvent)) {
continue;
}
if (!(model.getConstInterp(e1.executes(ctx)).isTrue() && model.getConstInterp(e2.executes(ctx)).isTrue())) {
continue;
}
if (model.getConstInterp(edge("rf", e1, e2, ctx)).isTrue() && model.getConstInterp(e1.executes(ctx)).isTrue() && model.getConstInterp(e2.executes(ctx)).isTrue()) {
gv.addln(" " + e1.repr() + " -> " + e2.repr() + " [label=\"rf\", color=\"red\", fontcolor=\"red\", weight=1];");
}
if (model.getConstInterp(edge("fr", e1, e2, ctx)).isTrue() && model.getConstInterp(e1.executes(ctx)).isTrue() && model.getConstInterp(e2.executes(ctx)).isTrue()) {
gv.addln(" " + e1.repr() + " -> " + e2.repr() + " [label=\"fr\", color=\"#ffa040\", fontcolor=\"#ffa040\", weight=1];");
}
if (e1.getLoc() == e2.getLoc() && (e1 instanceof Store || e1 instanceof Init) && (e2 instanceof Store || e2 instanceof Init) && Integer.parseInt(model.getConstInterp(intVar("co", e1, ctx)).toString()) == Integer.parseInt(model.getConstInterp(intVar("co", e2, ctx)).toString()) - 1 && model.getConstInterp(e1.executes(ctx)).isTrue() && model.getConstInterp(e2.executes(ctx)).isTrue()) {
gv.addln(" " + e1.repr() + " -> " + e2.repr() + " [label=\"co\", color=\"brown\", fontcolor=\"brown\", weight=1];");
}
if (model.getConstInterp(edge("sync", e1, e2, ctx)).isTrue() && model.getConstInterp(e1.executes(ctx)).isTrue() && model.getConstInterp(e2.executes(ctx)).isTrue()) {
gv.addln(" " + e1.repr() + " -> " + e2.repr() + " [label=\"sync\", color=\"black\", fontcolor=\"black\", weight=1];");
}
if (model.getConstInterp(edge("lwsync", e1, e2, ctx)).isTrue() && model.getConstInterp(e1.executes(ctx)).isTrue() && model.getConstInterp(e2.executes(ctx)).isTrue()) {
gv.addln(" " + e1.repr() + " -> " + e2.repr() + " [label=\"lwsync\", color=\"black\", fontcolor=\"black\", weight=1];");
}
if (model.getConstInterp(edge("mfence", e1, e2, ctx)).isTrue() && model.getConstInterp(e1.executes(ctx)).isTrue() && model.getConstInterp(e2.executes(ctx)).isTrue()) {
gv.addln(" " + e1.repr() + " -> " + e2.repr() + " [label=\"mfence\", color=\"black\", fontcolor=\"black\", weight=1];");
}
}
}
gv.addln(" }");
gv.addln(gv.end_graph());
fw.write(gv.getDotSource());
fw.close();
return;
}
use of dartagnan.program.Init in project Dat3M by hernanponcedeleon.
the class Encodings method encodeCommonExecutions.
public static BoolExpr encodeCommonExecutions(Program p1, Program p2, Context ctx) throws Z3Exception {
BoolExpr enc = ctx.mkTrue();
Set<Event> lEventsP1 = p1.getEvents().stream().filter(e -> e instanceof MemEvent | e instanceof Local).collect(Collectors.toSet());
Set<Event> lEventsP2 = p2.getEvents().stream().filter(e -> e instanceof MemEvent | e instanceof Local).collect(Collectors.toSet());
Set<Event> rEventsP1 = p1.getEvents().stream().filter(e -> e instanceof Load).collect(Collectors.toSet());
Set<Event> wEventsP1 = p1.getEvents().stream().filter(e -> e instanceof Store || e instanceof Init).collect(Collectors.toSet());
Set<Event> rEventsP2 = p2.getEvents().stream().filter(e -> e instanceof Load).collect(Collectors.toSet());
Set<Event> wEventsP2 = p2.getEvents().stream().filter(e -> e instanceof Store || e instanceof Init).collect(Collectors.toSet());
for (Event e1 : lEventsP1) {
for (Event e2 : lEventsP2) {
if (e1.getHLId().equals(e2.getHLId()) && e1.getUnfCopy().equals(e2.getUnfCopy())) {
enc = ctx.mkAnd(enc, ctx.mkEq(e1.executes(ctx), e2.executes(ctx)));
}
}
}
for (Event r1 : rEventsP1) {
for (Event r2 : rEventsP2) {
if (r1.getHLId().equals(r2.getHLId()) && r1.getUnfCopy().equals(r2.getUnfCopy())) {
for (Event w1 : wEventsP1) {
for (Event w2 : wEventsP2) {
if (r1.getLoc() != w1.getLoc()) {
continue;
}
if (r2.getLoc() != w2.getLoc()) {
continue;
}
if (w1.getHLId().equals(w2.getHLId()) && w1.getUnfCopy().equals(w2.getUnfCopy())) {
enc = ctx.mkAnd(enc, ctx.mkEq(edge("rf", w1, r1, ctx), edge("rf", w2, r2, ctx)));
}
}
}
}
}
}
for (Event w1P1 : wEventsP1) {
for (Event w1P2 : wEventsP2) {
if (w1P1.getHLId().equals(w1P2.getHLId()) && w1P1.getUnfCopy().equals(w1P2.getUnfCopy())) {
for (Event w2P1 : wEventsP1) {
for (Event w2P2 : wEventsP2) {
if (w1P1.getLoc() != w2P1.getLoc()) {
continue;
}
if (w1P1.getLoc() != w2P2.getLoc()) {
continue;
}
if (w1P1 == w2P1 | w1P2 == w2P2) {
continue;
}
if (w2P1.getHLId().equals(w2P2.getHLId()) && w2P1.getUnfCopy().equals(w2P2.getUnfCopy())) {
enc = ctx.mkAnd(enc, ctx.mkEq(edge("co", w1P1, w2P1, ctx), edge("co", w1P2, w2P2, ctx)));
}
}
}
}
}
}
return enc;
}
use of dartagnan.program.Init in project Dat3M by hernanponcedeleon.
the class Encodings method getInitialHigh.
public static BoolExpr getInitialHigh(Program p, Model model, Context ctx, boolean var1, boolean val1) {
Set<Event> highInits = p.getEvents().stream().filter(e -> e instanceof Init).filter(e -> e.getLoc() instanceof HighLocation).collect(Collectors.toSet());
BoolExpr reachedState = ctx.mkTrue();
for (Event e : highInits) {
IntExpr var = var1 ? initValue(e, ctx) : initValue2(e, ctx);
IntExpr val = val1 ? initValue(e, ctx) : initValue2(e, ctx);
if (e.getLoc().getIValue() == null) {
reachedState = ctx.mkAnd(reachedState, ctx.mkEq(var, model.getConstInterp(val)));
}
}
return reachedState;
}
Aggregations