Search in sources :

Example 56 with Model

use of com.microsoft.z3.Model in project xtext-core by eclipse.

the class Bug299395Test method testSerialization.

@Test
public void testSerialization() {
    Model model = Bug299395Factory.eINSTANCE.createModel();
    String serialized = getSerializer().serialize(model);
    assertEquals("", serialized);
}
Also used : Model(org.eclipse.xtext.parsetree.reconstr.bug299395.Model) SubModel(org.eclipse.xtext.parsetree.reconstr.bug299395.SubModel) Test(org.junit.Test)

Example 57 with Model

use of com.microsoft.z3.Model in project xtext-core by eclipse.

the class Bug299395Test method testSerialization_04.

@Test
public void testSerialization_04() {
    Model model = Bug299395Factory.eINSTANCE.createModel();
    model.getKeys().add("Key1");
    model.getValues().add("Value1");
    model.getKeys().add("Key2");
    model.getValues().add("Value2");
    String serialized = getSerializer().serialize(model);
    assertEquals("[ \"Key1\" \"Value1\" \"Key2\" \"Value2\" ]", serialized);
}
Also used : Model(org.eclipse.xtext.parsetree.reconstr.bug299395.Model) SubModel(org.eclipse.xtext.parsetree.reconstr.bug299395.SubModel) Test(org.junit.Test)

Example 58 with Model

use of com.microsoft.z3.Model in project xtext-core by eclipse.

the class Bug299395Test method testSerialization_08.

@Test
public void testSerialization_08() {
    Model model = Bug299395Factory.eINSTANCE.createModel();
    SubModel subModel = Bug299395Factory.eINSTANCE.createSubModel();
    model.setSubModel(subModel);
    subModel.getStrings().add("s1");
    subModel.getStrings().add("s2");
    String serialized = getSerializer().serialize(model);
    assertEquals("subModel 1 2 \"s1\" 1 2 \"s2\"", serialized);
}
Also used : Model(org.eclipse.xtext.parsetree.reconstr.bug299395.Model) SubModel(org.eclipse.xtext.parsetree.reconstr.bug299395.SubModel) SubModel(org.eclipse.xtext.parsetree.reconstr.bug299395.SubModel) Test(org.junit.Test)

Example 59 with Model

use of com.microsoft.z3.Model 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;
}
Also used : Arrays(java.util.Arrays) com.microsoft.z3(com.microsoft.z3) Event(dartagnan.program.Event) FileWriter(java.io.FileWriter) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) Init(dartagnan.program.Init) Register(dartagnan.program.Register) Load(dartagnan.program.Load) MemEvent(dartagnan.program.MemEvent) Program(dartagnan.program.Program) Store(dartagnan.program.Store) Location(dartagnan.program.Location) Load(dartagnan.program.Load) FileWriter(java.io.FileWriter) Store(dartagnan.program.Store) Init(dartagnan.program.Init) MemEvent(dartagnan.program.MemEvent) Event(dartagnan.program.Event) MemEvent(dartagnan.program.MemEvent) File(java.io.File)

Example 60 with Model

use of com.microsoft.z3.Model in project Dat3M by hernanponcedeleon.

the class Encodings method AssertFromModel.

public static Assert AssertFromModel(Program p, Model model, Context ctx) {
    Assert ass = new Assert();
    Set<Location> locs = p.getEvents().stream().filter(e -> e instanceof MemEvent).map(e -> e.getLoc()).collect(Collectors.toSet());
    for (Location loc : locs) {
        ass.addPair(loc, Integer.valueOf(model.getConstInterp(ctx.mkIntConst(loc.getName() + "_final")).toString()));
    }
    Set<Event> executedEvents = p.getEvents().stream().filter(e -> model.getConstInterp(e.executes(ctx)).isTrue()).collect(Collectors.toSet());
    Set<Register> regs = executedEvents.stream().filter(e -> e instanceof Local | e instanceof Load).map(e -> e.getReg()).collect(Collectors.toSet());
    for (Register reg : regs) {
        Set<Integer> ssaRegIndexes = new HashSet<Integer>();
        for (Event e : executedEvents) {
            if (!(e instanceof Load | e instanceof Local)) {
                continue;
            }
            if (e.getReg() != reg) {
                continue;
            }
            ssaRegIndexes.add(e.getSsaRegIndex());
        }
        Integer lastRegIndex = Collections.max(ssaRegIndexes);
        String regVarName = String.format("T%s_%s_%s", reg.getMainThread(), reg.getName(), lastRegIndex);
        ass.addPair(reg, Integer.valueOf(model.getConstInterp(ctx.mkIntConst(regVarName)).toString()));
    }
    return ass;
}
Also used : IntStream(java.util.stream.IntStream) com.microsoft.z3(com.microsoft.z3) Event(dartagnan.program.Event) Set(java.util.Set) Assert(dartagnan.expression.Assert) Utils(dartagnan.utils.Utils) Collectors(java.util.stream.Collectors) Init(dartagnan.program.Init) HashSet(java.util.HashSet) Register(dartagnan.program.Register) Local(dartagnan.program.Local) Load(dartagnan.program.Load) MemEvent(dartagnan.program.MemEvent) Program(dartagnan.program.Program) Collections(java.util.Collections) Store(dartagnan.program.Store) Location(dartagnan.program.Location) Load(dartagnan.program.Load) Local(dartagnan.program.Local) Assert(dartagnan.expression.Assert) Register(dartagnan.program.Register) MemEvent(dartagnan.program.MemEvent) Event(dartagnan.program.Event) MemEvent(dartagnan.program.MemEvent) Location(dartagnan.program.Location) HashSet(java.util.HashSet)

Aggregations

Test (org.junit.Test)45 Model (org.eclipse.xtext.valueconverter.bug250313.Model)30 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)16 BoolExpr (com.microsoft.z3.BoolExpr)11 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)11 Model (org.eclipse.xtext.parsetree.reconstr.bug299395.Model)9 SubModel (org.eclipse.xtext.parsetree.reconstr.bug299395.SubModel)9 Model (com.microsoft.z3.Model)7 Init (dartagnan.program.Init)7 Program (dartagnan.program.Program)7 Set (java.util.Set)7 Collectors (java.util.stream.Collectors)7 com.microsoft.z3 (com.microsoft.z3)6 Event (dartagnan.program.Event)6 Load (dartagnan.program.Load)6 Location (dartagnan.program.Location)6 MemEvent (dartagnan.program.MemEvent)6 Register (dartagnan.program.Register)6 Store (dartagnan.program.Store)6 EPackage (org.eclipse.emf.ecore.EPackage)6