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;
}
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());
}
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");
}
}
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);
}
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);
}
Aggregations