Search in sources :

Example 11 with Program

use of com.dat3m.dartagnan.program.Program in project Dat3M by hernanponcedeleon.

the class WitnessGraph method encode.

public BooleanFormula encode(Program program, SolverContext ctx) {
    BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
    IntegerFormulaManager imgr = ctx.getFormulaManager().getIntegerFormulaManager();
    BooleanFormula enc = bmgr.makeTrue();
    List<Event> previous = new ArrayList<>();
    for (Edge edge : edges.stream().filter(Edge::hasCline).collect(Collectors.toList())) {
        List<Event> events = program.getCache().getEvents(FilterBasic.get(MEMORY)).stream().filter(e -> e.getCLine() == edge.getCline()).collect(Collectors.toList());
        if (!previous.isEmpty() && !events.isEmpty()) {
            enc = bmgr.and(enc, bmgr.or(Lists.cartesianProduct(previous, events).stream().map(p -> edge("hb", p.get(0), p.get(1), ctx)).toArray(BooleanFormula[]::new)));
        }
        if (!events.isEmpty()) {
            previous = events;
        }
        if (edge.hasAttributed(EVENTID.toString()) && edge.hasAttributed(LOADEDVALUE.toString())) {
            int id = Integer.parseInt(edge.getAttributed(EVENTID.toString()));
            if (program.getCache().getEvents(FilterBasic.get(READ)).stream().anyMatch(e -> e.getUId() == id)) {
                Load load = (Load) program.getCache().getEvents(FilterBasic.get(READ)).stream().filter(e -> e.getUId() == id).findFirst().get();
                BigInteger value = new BigInteger(edge.getAttributed(LOADEDVALUE.toString()));
                enc = bmgr.and(enc, generalEqual(load.getResultRegisterExpr(), imgr.makeNumber(value), ctx));
            }
        }
        if (edge.hasAttributed(EVENTID.toString()) && edge.hasAttributed(STOREDVALUE.toString())) {
            int id = Integer.parseInt(edge.getAttributed(EVENTID.toString()));
            if (program.getCache().getEvents(FilterBasic.get(WRITE)).stream().anyMatch(e -> e.getUId() == id)) {
                Store store = (Store) program.getCache().getEvents(FilterBasic.get(WRITE)).stream().filter(e -> e.getUId() == id).findFirst().get();
                BigInteger value = new BigInteger(edge.getAttributed(STOREDVALUE.toString()));
                enc = bmgr.and(enc, generalEqual(store.getMemValueExpr(), imgr.makeNumber(value), ctx));
            }
        }
    }
    return enc;
}
Also used : java.util(java.util) Store(com.dat3m.dartagnan.program.event.core.Store) PROGRAMFILE(com.dat3m.dartagnan.witness.GraphAttributes.PROGRAMFILE) FileWriter(java.io.FileWriter) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) EdgeAttributes(com.dat3m.dartagnan.witness.EdgeAttributes) Utils.edge(com.dat3m.dartagnan.wmm.utils.Utils.edge) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) IntegerFormulaManager(org.sosy_lab.java_smt.api.IntegerFormulaManager) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) Tag(com.dat3m.dartagnan.program.event.Tag) Lists(com.google.common.collect.Lists) Files(com.google.common.io.Files) SolverContext(org.sosy_lab.java_smt.api.SolverContext) Program(com.dat3m.dartagnan.program.Program) Event(com.dat3m.dartagnan.program.event.core.Event) BigInteger(java.math.BigInteger) Load(com.dat3m.dartagnan.program.event.core.Load) FilterBasic(com.dat3m.dartagnan.program.filter.FilterBasic) Utils.generalEqual(com.dat3m.dartagnan.expression.utils.Utils.generalEqual) Load(com.dat3m.dartagnan.program.event.core.Load) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) Event(com.dat3m.dartagnan.program.event.core.Event) BigInteger(java.math.BigInteger) Store(com.dat3m.dartagnan.program.event.core.Store) IntegerFormulaManager(org.sosy_lab.java_smt.api.IntegerFormulaManager) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula)

Example 12 with Program

use of com.dat3m.dartagnan.program.Program in project Dat3M by hernanponcedeleon.

the class AnalysisTest method analyze.

private AliasAnalysis analyze(ProgramBuilder builder, Alias method) throws InvalidConfigurationException {
    Program program = builder.build();
    LoopUnrolling.newInstance().run(program);
    Compilation.newInstance().run(program);
    return AliasAnalysis.fromConfig(program, Configuration.builder().setOption(ALIAS_METHOD, method.asStringOption()).build());
}
Also used : Program(com.dat3m.dartagnan.program.Program)

Example 13 with Program

use of com.dat3m.dartagnan.program.Program in project Dat3M by hernanponcedeleon.

the class ArrayValidTest method test.

@Test
public void test() {
    try (SolverContext ctx = TestHelper.createContext();
        ProverEnvironment prover1 = ctx.newProverEnvironment(ProverOptions.GENERATE_MODELS);
        ProverEnvironment prover2 = ctx.newProverEnvironment(ProverOptions.GENERATE_MODELS)) {
        Program program = new ProgramParser().parse(new File(path));
        VerificationTask task = VerificationTask.builder().withSolverTimeout(60).withTarget(Arch.LKMM).build(program, wmm, EnumSet.of(Property.getDefault()));
        assertEquals(TwoSolvers.run(ctx, prover1, prover2, task), FAIL);
    } catch (Exception e) {
        fail("Missing resource file");
    }
}
Also used : SolverContext(org.sosy_lab.java_smt.api.SolverContext) Program(com.dat3m.dartagnan.program.Program) VerificationTask(com.dat3m.dartagnan.verification.VerificationTask) ProgramParser(com.dat3m.dartagnan.parsers.program.ProgramParser) ProverEnvironment(org.sosy_lab.java_smt.api.ProverEnvironment) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Example 14 with Program

use of com.dat3m.dartagnan.program.Program in project Dat3M by hernanponcedeleon.

the class LoopTest method test.

@Test
public void test() throws Exception {
    Program p = new ProgramParser().parse(new File(path));
    LoopUnrolling.newInstance().run(p);
}
Also used : Program(com.dat3m.dartagnan.program.Program) ProgramParser(com.dat3m.dartagnan.parsers.program.ProgramParser) File(java.io.File) Test(org.junit.Test)

Example 15 with Program

use of com.dat3m.dartagnan.program.Program in project Dat3M by hernanponcedeleon.

the class ExceptionsTest method initializedBeforeCompileException.

@Test(expected = IllegalArgumentException.class)
public void initializedBeforeCompileException() throws Exception {
    ProgramBuilder pb = new ProgramBuilder(SourceLanguage.LITMUS);
    pb.initThread(0);
    Program p = pb.build();
    Wmm cat = new ParserCat().parse(new File(ResourceHelper.CAT_RESOURCE_PATH + "cat/tso.cat"));
    Configuration config = Configuration.defaultConfiguration();
    VerificationTask task = VerificationTask.builder().withConfig(config).build(p, cat, EnumSet.of(Property.getDefault()));
    // The program must be compiled before being able to construct an Encoder for it
    ProgramEncoder.fromConfig(task.getProgram(), Context.create(), config);
}
Also used : Program(com.dat3m.dartagnan.program.Program) VerificationTask(com.dat3m.dartagnan.verification.VerificationTask) Configuration(org.sosy_lab.common.configuration.Configuration) ProgramBuilder(com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder) Wmm(com.dat3m.dartagnan.wmm.Wmm) ParserCat(com.dat3m.dartagnan.parsers.cat.ParserCat) File(java.io.File) Test(org.junit.Test)

Aggregations

Program (com.dat3m.dartagnan.program.Program)41 Test (org.junit.Test)22 File (java.io.File)21 ProgramParser (com.dat3m.dartagnan.parsers.program.ProgramParser)20 ProgramBuilder (com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder)10 Printer (com.dat3m.dartagnan.utils.printer.Printer)8 VerificationTask (com.dat3m.dartagnan.verification.VerificationTask)6 Configuration (org.sosy_lab.common.configuration.Configuration)6 ParserErrorListener (com.dat3m.dartagnan.exception.ParserErrorListener)5 Compilation (com.dat3m.dartagnan.program.processing.compilation.Compilation)5 Collectors (java.util.stream.Collectors)5 SolverContext (org.sosy_lab.java_smt.api.SolverContext)5 ParserCat (com.dat3m.dartagnan.parsers.cat.ParserCat)4 Tag (com.dat3m.dartagnan.program.event.Tag)4 Event (com.dat3m.dartagnan.program.event.core.Event)4 Result (com.dat3m.dartagnan.utils.Result)4 Wmm (com.dat3m.dartagnan.wmm.Wmm)4 InvalidConfigurationException (org.sosy_lab.common.configuration.InvalidConfigurationException)4 ProverEnvironment (org.sosy_lab.java_smt.api.ProverEnvironment)4 FilterBasic (com.dat3m.dartagnan.program.filter.FilterBasic)3