Search in sources :

Example 11 with Label

use of com.dat3m.dartagnan.program.event.core.Label in project Dat3M by hernanponcedeleon.

the class VisitorLitmusPPC method visitBranchCond.

@Override
public Object visitBranchCond(LitmusPPCParser.BranchCondContext ctx) {
    Label label = programBuilder.getOrCreateLabel(ctx.Label().getText());
    Event lastEvent = programBuilder.getLastEvent(mainThread);
    if (!(lastEvent instanceof Cmp)) {
        throw new ParsingException("Invalid syntax near " + ctx.getText());
    }
    Cmp cmp = (Cmp) lastEvent;
    Atom expr = new Atom(cmp.getLeft(), ctx.cond().op, cmp.getRight());
    return programBuilder.addChild(mainThread, EventFactory.newJump(expr, label));
}
Also used : Cmp(com.dat3m.dartagnan.program.event.core.Cmp) ParsingException(com.dat3m.dartagnan.exception.ParsingException) Label(com.dat3m.dartagnan.program.event.core.Label) Event(com.dat3m.dartagnan.program.event.core.Event) Atom(com.dat3m.dartagnan.expression.Atom)

Example 12 with Label

use of com.dat3m.dartagnan.program.event.core.Label in project Dat3M by hernanponcedeleon.

the class VisitorLitmusAArch64 method visitBranch.

@Override
public Object visitBranch(LitmusAArch64Parser.BranchContext ctx) {
    Label label = programBuilder.getOrCreateLabel(ctx.label().getText());
    if (ctx.branchCondition() == null) {
        return programBuilder.addChild(mainThread, EventFactory.newGoto(label));
    }
    Event lastEvent = programBuilder.getLastEvent(mainThread);
    if (!(lastEvent instanceof Cmp)) {
        throw new ParsingException("Invalid syntax near " + ctx.getText());
    }
    Cmp cmp = (Cmp) lastEvent;
    Atom expr = new Atom(cmp.getLeft(), ctx.branchCondition().op, cmp.getRight());
    return programBuilder.addChild(mainThread, EventFactory.newJump(expr, label));
}
Also used : Cmp(com.dat3m.dartagnan.program.event.core.Cmp) ParsingException(com.dat3m.dartagnan.exception.ParsingException) Label(com.dat3m.dartagnan.program.event.core.Label) Event(com.dat3m.dartagnan.program.event.core.Event) Atom(com.dat3m.dartagnan.expression.Atom)

Example 13 with Label

use of com.dat3m.dartagnan.program.event.core.Label in project Dat3M by hernanponcedeleon.

the class ExceptionsTest method JumpWithNullExpr.

@Test(expected = NullPointerException.class)
public void JumpWithNullExpr() throws Exception {
    ProgramBuilder pb = new ProgramBuilder();
    pb.initThread(0);
    Label end = pb.getOrCreateLabel("END");
    // The expr cannot be null
    pb.addChild(0, new CondJump(null, end));
}
Also used : ProgramBuilder(com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder) Label(com.dat3m.dartagnan.program.event.core.Label) CondJump(com.dat3m.dartagnan.program.event.core.CondJump) Test(org.junit.Test)

Example 14 with Label

use of com.dat3m.dartagnan.program.event.core.Label in project Dat3M by hernanponcedeleon.

the class PropertyEncoder method encodeLiveness.

public BooleanFormula encodeLiveness(SolverContext ctx) {
    // Further, we assume that the spinloops are indeed correct, i.e., side-effect free
    class SpinLoop {

        public List<Load> loads = new ArrayList<>();

        public Event bound;
    }
    logger.info("Encoding liveness");
    Map<Thread, List<SpinLoop>> spinloopsMap = new HashMap<>();
    // Find spinloops of all threads
    for (Thread t : program.getThreads()) {
        List<Event> spinStarts = t.getEvents().stream().filter(e -> e instanceof Label && e.is(Tag.SPINLOOP)).collect(Collectors.toList());
        List<SpinLoop> spinLoops = new ArrayList<>();
        spinloopsMap.put(t, spinLoops);
        for (Event start : spinStarts) {
            SpinLoop loop = new SpinLoop();
            Event cur = start.getSuccessor();
            while (!cur.is(Tag.SPINLOOP)) {
                if (cur.is(Tag.READ)) {
                    loop.loads.add((Load) cur);
                }
                cur = cur.getSuccessor();
            }
            loop.bound = cur;
            spinLoops.add(loop);
        }
    }
    BooleanFormulaManager bmgr = ctx.getFormulaManager().getBooleanFormulaManager();
    RelRf rf = (RelRf) memoryModel.getRelationRepository().getRelation(RelationNameRepository.RF);
    RelCo co = (RelCo) memoryModel.getRelationRepository().getRelation(RelationNameRepository.CO);
    // Compute "stuckness": A thread is stuck if it reaches a spinloop bound event
    // while reading from a co-maximal write.
    Map<Thread, BooleanFormula> isStuckMap = new HashMap<>();
    for (Thread t : program.getThreads()) {
        List<SpinLoop> loops = spinloopsMap.get(t);
        if (loops.isEmpty()) {
            continue;
        }
        BooleanFormula isStuck = bmgr.makeFalse();
        for (SpinLoop pair : loops) {
            BooleanFormula allCoMaximalLoad = bmgr.makeTrue();
            for (Load load : pair.loads) {
                BooleanFormula coMaximalLoad = bmgr.makeFalse();
                for (Tuple rfEdge : rf.getMaxTupleSet().getBySecond(load)) {
                    coMaximalLoad = bmgr.or(coMaximalLoad, bmgr.and(rf.getSMTVar(rfEdge, ctx), co.getLastCoVar(rfEdge.getFirst(), ctx)));
                }
                allCoMaximalLoad = bmgr.and(allCoMaximalLoad, coMaximalLoad);
            }
            isStuck = bmgr.or(isStuck, bmgr.and(pair.bound.exec(), allCoMaximalLoad));
        }
        isStuckMap.put(t, isStuck);
    }
    // LivenessViolation <=> allStuckOrDone /\ atLeastOneStuck
    BooleanFormula allStuckOrDone = bmgr.makeTrue();
    BooleanFormula atLeastOneStuck = bmgr.makeFalse();
    for (Thread t : program.getThreads()) {
        BooleanFormula isStuck = isStuckMap.getOrDefault(t, bmgr.makeFalse());
        BooleanFormula isDone = t.getCache().getEvents(FilterBasic.get(Tag.BOUND)).stream().map(e -> bmgr.not(e.exec())).reduce(bmgr.makeTrue(), bmgr::and);
        atLeastOneStuck = bmgr.or(atLeastOneStuck, isStuck);
        allStuckOrDone = bmgr.and(allStuckOrDone, bmgr.or(isStuck, isDone));
    }
    // We use the SMT variable to extract from the model if the property was violated
    BooleanFormula enc = bmgr.equivalence(LIVENESS.getSMTVariable(ctx), bmgr.and(allStuckOrDone, atLeastOneStuck));
    return bmgr.and(LIVENESS.getSMTVariable(ctx), enc);
}
Also used : Options(org.sosy_lab.common.configuration.Options) Property(com.dat3m.dartagnan.configuration.Property) Utils.intVar(com.dat3m.dartagnan.wmm.utils.Utils.intVar) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Utils.edge(com.dat3m.dartagnan.wmm.utils.Utils.edge) HashMap(java.util.HashMap) Thread(com.dat3m.dartagnan.program.Thread) ArrayList(java.util.ArrayList) Wmm(com.dat3m.dartagnan.wmm.Wmm) Map(java.util.Map) SolverContext(org.sosy_lab.java_smt.api.SolverContext) Program(com.dat3m.dartagnan.program.Program) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple) BigInteger(java.math.BigInteger) RelRf(com.dat3m.dartagnan.wmm.relation.base.memory.RelRf) FilterBasic(com.dat3m.dartagnan.program.filter.FilterBasic) EnumSet(java.util.EnumSet) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException) Utils.generalEqual(com.dat3m.dartagnan.expression.utils.Utils.generalEqual) AliasAnalysis(com.dat3m.dartagnan.program.analysis.AliasAnalysis) RelCo(com.dat3m.dartagnan.wmm.relation.base.memory.RelCo) Configuration(org.sosy_lab.common.configuration.Configuration) Collectors(java.util.stream.Collectors) Label(com.dat3m.dartagnan.program.event.core.Label) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) IntegerFormulaManager(org.sosy_lab.java_smt.api.IntegerFormulaManager) Tag(com.dat3m.dartagnan.program.event.Tag) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) Context(com.dat3m.dartagnan.verification.Context) RelationNameRepository(com.dat3m.dartagnan.wmm.relation.RelationNameRepository) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Event(com.dat3m.dartagnan.program.event.core.Event) Preconditions(com.google.common.base.Preconditions) Load(com.dat3m.dartagnan.program.event.core.Load) LogManager(org.apache.logging.log4j.LogManager) FilterMinus(com.dat3m.dartagnan.program.filter.FilterMinus) Load(com.dat3m.dartagnan.program.event.core.Load) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) HashMap(java.util.HashMap) Label(com.dat3m.dartagnan.program.event.core.Label) ArrayList(java.util.ArrayList) Thread(com.dat3m.dartagnan.program.Thread) RelCo(com.dat3m.dartagnan.wmm.relation.base.memory.RelCo) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) Event(com.dat3m.dartagnan.program.event.core.Event) ArrayList(java.util.ArrayList) List(java.util.List) RelRf(com.dat3m.dartagnan.wmm.relation.base.memory.RelRf) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple)

Example 15 with Label

use of com.dat3m.dartagnan.program.event.core.Label in project Dat3M by hernanponcedeleon.

the class VisitorLitmusC method visitIfExpression.

@Override
public Object visitIfExpression(LitmusCParser.IfExpressionContext ctx) {
    ExprInterface expr = (ExprInterface) ctx.re().accept(this);
    ifId++;
    Label elseL = programBuilder.getOrCreateLabel("else_" + ifId);
    Label endL = programBuilder.getOrCreateLabel("end_" + ifId);
    IfAsJump ifEvent = EventFactory.newIfJumpUnless(expr, elseL, endL);
    programBuilder.addChild(currentThread, ifEvent);
    for (LitmusCParser.ExpressionContext expressionContext : ctx.expression()) expressionContext.accept(this);
    CondJump jumpToEnd = EventFactory.newGoto(endL);
    jumpToEnd.addFilters(Tag.IFI);
    programBuilder.addChild(currentThread, jumpToEnd);
    programBuilder.addChild(currentThread, elseL);
    if (ctx.elseExpression() != null) {
        ctx.elseExpression().accept(this);
    }
    programBuilder.addChild(currentThread, endL);
    return null;
}
Also used : LitmusCParser(com.dat3m.dartagnan.parsers.LitmusCParser) Label(com.dat3m.dartagnan.program.event.core.Label) IfAsJump(com.dat3m.dartagnan.program.event.core.IfAsJump) CondJump(com.dat3m.dartagnan.program.event.core.CondJump)

Aggregations

Label (com.dat3m.dartagnan.program.event.core.Label)33 Event (com.dat3m.dartagnan.program.event.core.Event)15 Register (com.dat3m.dartagnan.program.Register)11 CondJump (com.dat3m.dartagnan.program.event.core.CondJump)9 Atom (com.dat3m.dartagnan.expression.Atom)7 MemoryObject (com.dat3m.dartagnan.program.memory.MemoryObject)7 ProgramBuilder (com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder)6 Test (org.junit.Test)6 LoopUnrolling (com.dat3m.dartagnan.program.processing.LoopUnrolling)5 ParsingException (com.dat3m.dartagnan.exception.ParsingException)4 Program (com.dat3m.dartagnan.program.Program)4 Thread (com.dat3m.dartagnan.program.Thread)4 Preconditions (com.google.common.base.Preconditions)4 HashMap (java.util.HashMap)4 LogManager (org.apache.logging.log4j.LogManager)4 Logger (org.apache.logging.log4j.Logger)4 Tag (com.dat3m.dartagnan.program.event.Tag)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3