Search in sources :

Example 26 with ProgramBuilder

use of com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder in project Dat3M by hernanponcedeleon.

the class AnalysisTest method program4.

private void program4(Alias method, Result... expect) throws InvalidConfigurationException {
    ProgramBuilder b = new ProgramBuilder(SourceLanguage.LITMUS);
    MemoryObject x = b.getOrNewObject("x");
    MemoryObject y = b.getOrNewObject("y");
    MemoryObject z = b.getOrNewObject("z");
    b.initThread(0);
    Register r0 = b.getOrCreateRegister(0, "r0", ARCH_PRECISION);
    b.addChild(0, newLocal(r0, mult(x, 0)));
    b.addChild(0, newLocal(r0, y));
    Store e0 = newStore(r0);
    b.addChild(0, e0);
    Store e1 = newStore(x);
    b.addChild(0, e1);
    Store e2 = newStore(y);
    b.addChild(0, e2);
    Store e3 = newStore(z);
    b.addChild(0, e3);
    AliasAnalysis a = analyze(b, method);
    // precisely no
    assertAlias(expect[0], a, e0, e1);
    // precisely must
    assertAlias(expect[1], a, e0, e2);
    assertAlias(expect[2], a, e1, e2);
    assertAlias(expect[3], a, e0, e3);
    assertAlias(expect[4], a, e1, e3);
    assertAlias(expect[5], a, e2, e3);
}
Also used : Register(com.dat3m.dartagnan.program.Register) ProgramBuilder(com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder) MemoryObject(com.dat3m.dartagnan.program.memory.MemoryObject) AliasAnalysis(com.dat3m.dartagnan.program.analysis.AliasAnalysis)

Example 27 with ProgramBuilder

use of com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder in project Dat3M by hernanponcedeleon.

the class AnalysisTest method dependencyMustOverride.

@Test
public void dependencyMustOverride() throws InvalidConfigurationException {
    ProgramBuilder b = new ProgramBuilder(SourceLanguage.LITMUS);
    b.initThread(0);
    Register r0 = b.getOrCreateRegister(0, "r0", ARCH_PRECISION);
    Register r1 = b.getOrCreateRegister(0, "r1", ARCH_PRECISION);
    Register r2 = b.getOrCreateRegister(0, "r2", ARCH_PRECISION);
    Label alt = b.getOrCreateLabel("alt");
    b.addChild(0, newJump(new BNonDet(ARCH_PRECISION), alt));
    Local e0 = newLocal(r0, value(1));
    b.addChild(0, e0);
    Local e1 = newLocal(r1, r0);
    b.addChild(0, e1);
    Label join = b.getOrCreateLabel("join");
    b.addChild(0, newGoto(join));
    b.addChild(0, alt);
    Local e2 = newLocal(r1, value(2));
    b.addChild(0, e2);
    b.addChild(0, join);
    Local e3 = newLocal(r2, r0);
    b.addChild(0, e3);
    Local e4 = newLocal(r2, r1);
    b.addChild(0, e4);
    Local e5 = newLocal(r0, r2);
    b.addChild(0, e5);
    Program program = b.build();
    LoopUnrolling.newInstance().run(program);
    Compilation.newInstance().run(program);
    Configuration config = Configuration.defaultConfiguration();
    Context context = Context.create();
    context.register(BranchEquivalence.class, BranchEquivalence.fromConfig(program, config));
    context.register(ExecutionAnalysis.class, ExecutionAnalysis.fromConfig(program, context, config));
    Dependency dep = Dependency.fromConfig(program, context, config);
    assertTrue(dep.of(e1, r0).initialized);
    assertList(dep.of(e1, r0).may, e0);
    assertList(dep.of(e1, r0).must, e0);
    assertFalse(dep.of(e3, r0).initialized);
    assertList(dep.of(e3, r0).may, e0);
    assertList(dep.of(e3, r0).must, e0);
    assertTrue(dep.of(e4, r1).initialized);
    assertList(dep.of(e4, r1).may, e1, e2);
    assertList(dep.of(e4, r1).must, e1, e2);
    assertTrue(dep.of(e5, r2).initialized);
    assertList(dep.of(e5, r2).may, e4);
    assertList(dep.of(e5, r2).must, e4);
}
Also used : Context(com.dat3m.dartagnan.verification.Context) Program(com.dat3m.dartagnan.program.Program) Configuration(org.sosy_lab.common.configuration.Configuration) Register(com.dat3m.dartagnan.program.Register) ProgramBuilder(com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder) Dependency(com.dat3m.dartagnan.program.analysis.Dependency) Test(org.junit.Test)

Example 28 with ProgramBuilder

use of com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder in project Dat3M by hernanponcedeleon.

the class AnalysisTest method program0.

private void program0(Alias method, Result... expect) throws InvalidConfigurationException {
    ProgramBuilder b = new ProgramBuilder(SourceLanguage.LITMUS);
    MemoryObject x = b.newObject("x", 2);
    MemoryObject y = b.getOrNewObject("y");
    b.initThread(0);
    Register r0 = b.getOrCreateRegister(0, "r0", ARCH_PRECISION);
    // this is undefined behavior in C11
    // the expression does not match a sum, but x occurs in it
    b.addChild(0, newLocal(r0, mult(x, 1)));
    Store e0 = newStore(r0);
    b.addChild(0, e0);
    Store e1 = newStore(plus(r0, 1));
    b.addChild(0, e1);
    Store e2 = newStore(x);
    b.addChild(0, e2);
    Store e3 = newStore(y);
    b.addChild(0, e3);
    AliasAnalysis a = analyze(b, method);
    // precisely no
    assertAlias(expect[0], a, e0, e1);
    assertAlias(expect[1], a, e0, e2);
    assertAlias(expect[2], a, e1, e2);
    assertAlias(expect[3], a, e0, e3);
    assertAlias(expect[4], a, e1, e3);
    assertAlias(expect[5], a, e2, e3);
}
Also used : Register(com.dat3m.dartagnan.program.Register) ProgramBuilder(com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder) MemoryObject(com.dat3m.dartagnan.program.memory.MemoryObject) AliasAnalysis(com.dat3m.dartagnan.program.analysis.AliasAnalysis)

Example 29 with ProgramBuilder

use of com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder in project Dat3M by hernanponcedeleon.

the class AnalysisTest method program3.

private void program3(Alias method, Result... expect) throws InvalidConfigurationException {
    ProgramBuilder b = new ProgramBuilder(SourceLanguage.LITMUS);
    MemoryObject x = b.newObject("x", 3);
    x.setInitialValue(0, x);
    b.initThread(0);
    Register r0 = b.getOrCreateRegister(0, "r0", ARCH_PRECISION);
    Load e0 = newLoad(r0, x);
    b.addChild(0, e0);
    Store e1 = newStore(x, plus(r0, 1));
    b.addChild(0, e1);
    Store e2 = newStore(plus(x, 2));
    b.addChild(0, e2);
    Store e3 = newStore(r0);
    b.addChild(0, e3);
    AliasAnalysis a = analyze(b, method);
    assertAlias(expect[0], a, e0, e1);
    assertAlias(expect[1], a, e0, e2);
    assertAlias(expect[2], a, e1, e2);
    assertAlias(expect[3], a, e0, e3);
    assertAlias(expect[4], a, e1, e3);
    // precisely no
    assertAlias(expect[5], a, e2, e3);
}
Also used : Register(com.dat3m.dartagnan.program.Register) ProgramBuilder(com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder) MemoryObject(com.dat3m.dartagnan.program.memory.MemoryObject) AliasAnalysis(com.dat3m.dartagnan.program.analysis.AliasAnalysis)

Example 30 with ProgramBuilder

use of com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder in project Dat3M by hernanponcedeleon.

the class ExceptionsTest method unrollBeforeReorderException.

@Test(expected = IllegalArgumentException.class)
public void unrollBeforeReorderException() throws Exception {
    ProgramBuilder pb = new ProgramBuilder(SourceLanguage.LITMUS);
    pb.initThread(0);
    Program p = pb.build();
    LoopUnrolling.newInstance().run(p);
    // Reordering cannot be called after unrolling
    BranchReordering.newInstance().run(p);
}
Also used : Program(com.dat3m.dartagnan.program.Program) ProgramBuilder(com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder) Test(org.junit.Test)

Aggregations

ProgramBuilder (com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder)32 MemoryObject (com.dat3m.dartagnan.program.memory.MemoryObject)16 Test (org.junit.Test)14 Register (com.dat3m.dartagnan.program.Register)13 AliasAnalysis (com.dat3m.dartagnan.program.analysis.AliasAnalysis)12 Program (com.dat3m.dartagnan.program.Program)10 Label (com.dat3m.dartagnan.program.event.core.Label)6 ParserErrorListener (com.dat3m.dartagnan.exception.ParserErrorListener)5 LoopUnrolling (com.dat3m.dartagnan.program.processing.LoopUnrolling)5 CondJump (com.dat3m.dartagnan.program.event.core.CondJump)2 RMWReadCond (com.dat3m.dartagnan.program.event.lang.linux.cond.RMWReadCond)2 Configuration (org.sosy_lab.common.configuration.Configuration)2 BoogieLexer (com.dat3m.dartagnan.parsers.BoogieLexer)1 BoogieParser (com.dat3m.dartagnan.parsers.BoogieParser)1 LitmusAArch64Lexer (com.dat3m.dartagnan.parsers.LitmusAArch64Lexer)1 LitmusAArch64Parser (com.dat3m.dartagnan.parsers.LitmusAArch64Parser)1 LitmusCLexer (com.dat3m.dartagnan.parsers.LitmusCLexer)1 LitmusCParser (com.dat3m.dartagnan.parsers.LitmusCParser)1 LitmusLISALexer (com.dat3m.dartagnan.parsers.LitmusLISALexer)1 LitmusLISAParser (com.dat3m.dartagnan.parsers.LitmusLISAParser)1