Search in sources :

Example 6 with Label

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

the class SvcompProcedures method __VERIFIER_assert.

private static void __VERIFIER_assert(VisitorBoogie visitor, Call_cmdContext ctx) {
    IExpr expr = (IExpr) ctx.call_params().exprs().accept(visitor);
    Register ass = visitor.programBuilder.getOrCreateRegister(visitor.threadCount, "assert_" + visitor.assertionIndex, expr.getPrecision());
    visitor.assertionIndex++;
    if (expr instanceof IConst && ((IConst) expr).getValue().equals(BigInteger.ONE)) {
        return;
    }
    Local event = EventFactory.newLocal(ass, expr);
    event.addFilters(Tag.ASSERTION);
    visitor.programBuilder.addChild(visitor.threadCount, event);
    Label end = visitor.programBuilder.getOrCreateLabel("END_OF_T" + visitor.threadCount);
    visitor.programBuilder.addChild(visitor.threadCount, EventFactory.newJump(new Atom(ass, NEQ, expr), end));
}
Also used : Register(com.dat3m.dartagnan.program.Register) Label(com.dat3m.dartagnan.program.event.core.Label) Local(com.dat3m.dartagnan.program.event.core.Local)

Example 7 with Label

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

the class SvcompProcedures method __VERIFIER_atomic.

public static void __VERIFIER_atomic(VisitorBoogie visitor, boolean begin) {
    Register register = visitor.programBuilder.getOrCreateRegister(visitor.threadCount, null, ARCH_PRECISION);
    MemoryObject lockAddress = visitor.programBuilder.getOrNewObject("__VERIFIER_atomic");
    Label label = visitor.programBuilder.getOrCreateLabel("END_OF_T" + visitor.threadCount);
    LinkedList<Event> events = new LinkedList<>();
    events.add(EventFactory.newLoad(register, lockAddress, null));
    events.add(EventFactory.newJump(new Atom(register, NEQ, begin ? IValue.ZERO : IValue.ONE), label));
    events.add(EventFactory.newStore(lockAddress, begin ? IValue.ONE : IValue.ZERO, null));
    for (Event e : events) {
        e.addFilters(Tag.C11.LOCK, Tag.RMW);
        visitor.programBuilder.addChild(visitor.threadCount, e);
    }
}
Also used : Register(com.dat3m.dartagnan.program.Register) MemoryObject(com.dat3m.dartagnan.program.memory.MemoryObject) Label(com.dat3m.dartagnan.program.event.core.Label) Event(com.dat3m.dartagnan.program.event.core.Event) LinkedList(java.util.LinkedList)

Example 8 with Label

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

the class VisitorBoogie method visitAssert_cmd.

@Override
public Object visitAssert_cmd(Assert_cmdContext ctx) {
    // In boogie transformation, assertions result in "assert false".
    // The control flow checks the corresponding expression, thus
    // we cannot just add the expression to the AbstractAssertion.
    // We need to create an event carrying the value of the expression
    // and see if this event can be executed.
    IExpr expr = (IExpr) ctx.proposition().expr().accept(this);
    Register ass = programBuilder.getOrCreateRegister(threadCount, "assert_" + assertionIndex, expr.getPrecision());
    assertionIndex++;
    programBuilder.addChild(threadCount, EventFactory.newLocal(ass, expr)).setCLine(currentLine).setSourceCodeFile(sourceCodeFile).addFilters(Tag.ASSERTION);
    Label end = programBuilder.getOrCreateLabel("END_OF_T" + threadCount);
    programBuilder.addChild(threadCount, EventFactory.newJump(new Atom(ass, COpBin.NEQ, IValue.ONE), end));
    return null;
}
Also used : Register(com.dat3m.dartagnan.program.Register) Label(com.dat3m.dartagnan.program.event.core.Label)

Example 9 with Label

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

the class VisitorBoogie method visitProc_decl.

private void visitProc_decl(Proc_declContext ctx, boolean create, List<ExprInterface> callingValues) {
    currentLine = -1;
    if (ctx.proc_sign().proc_sign_out() != null) {
        for (Attr_typed_idents_whereContext atiwC : ctx.proc_sign().proc_sign_out().attr_typed_idents_wheres().attr_typed_idents_where()) {
            for (ParseTree ident : atiwC.typed_idents_where().typed_idents().idents().Ident()) {
                currentReturnName = ident.getText();
            }
        }
    }
    if (create) {
        threadCount++;
        String name = ctx.proc_sign().Ident().getText();
        programBuilder.initThread(name, threadCount);
        if (threadCount != 1) {
            // Used to allow execution of threads after they have been created (pthread_create)
            MemoryObject object = programBuilder.getOrNewObject(String.format("%s(%s)_active", pool.getPtrFromInt(threadCount), pool.getCreatorFromPtr(pool.getPtrFromInt(threadCount))));
            Register reg = programBuilder.getOrCreateRegister(threadCount, null, ARCH_PRECISION);
            programBuilder.addChild(threadCount, EventFactory.Pthread.newStart(reg, object));
        }
    }
    currentScope = new Scope(nextScopeID, currentScope);
    nextScopeID++;
    Impl_bodyContext body = ctx.impl_body();
    if (body == null) {
        throw new ParsingException(ctx.proc_sign().Ident().getText() + " cannot be handled");
    }
    if (ctx.proc_sign().proc_sign_in() != null) {
        int index = 0;
        for (Attr_typed_idents_whereContext atiwC : ctx.proc_sign().proc_sign_in().attr_typed_idents_wheres().attr_typed_idents_where()) {
            for (ParseTree ident : atiwC.typed_idents_where().typed_idents().idents().Ident()) {
                // To deal with references passed to created threads
                if (index < callingValues.size()) {
                    String type = atiwC.typed_idents_where().typed_idents().type().getText();
                    int precision = type.contains("bv") ? Integer.parseInt(type.split("bv")[1]) : ARCH_PRECISION;
                    Register register = programBuilder.getOrCreateRegister(threadCount, currentScope.getID() + ":" + ident.getText(), precision);
                    ExprInterface value = callingValues.get(index);
                    programBuilder.addChild(threadCount, EventFactory.newLocal(register, value)).setCLine(currentLine).setSourceCodeFile(sourceCodeFile);
                    index++;
                }
            }
        }
    }
    for (Local_varsContext localVarContext : body.local_vars()) {
        visitLocal_vars(localVarContext, threadCount);
    }
    visitChildren(body.stmt_list());
    Label label = programBuilder.getOrCreateLabel("END_OF_" + currentScope.getID());
    programBuilder.addChild(threadCount, label);
    currentScope = currentScope.getParent();
    if (create) {
        if (threadCount != 1) {
            // Used to mark the end of the execution of a thread (used by pthread_join)
            MemoryObject object = programBuilder.getOrNewObject(String.format("%s(%s)_active", pool.getPtrFromInt(threadCount), pool.getCreatorFromPtr(pool.getPtrFromInt(threadCount))));
            programBuilder.addChild(threadCount, EventFactory.Pthread.newEnd(object));
        }
    }
}
Also used : Scope(com.dat3m.dartagnan.parsers.program.boogie.Scope) Register(com.dat3m.dartagnan.program.Register) ParsingException(com.dat3m.dartagnan.exception.ParsingException) MemoryObject(com.dat3m.dartagnan.program.memory.MemoryObject) Label(com.dat3m.dartagnan.program.event.core.Label) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 10 with Label

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

the class VisitorBase method visitLock.

@Override
public List<Event> visitLock(Lock e) {
    Register resultRegister = e.getResultRegister();
    String mo = e.getMo();
    List<Event> events = eventSequence(newLoad(resultRegister, e.getAddress(), mo), newJump(new Atom(resultRegister, NEQ, IValue.ZERO), (Label) e.getThread().getExit()), newStore(e.getAddress(), IValue.ONE, mo));
    for (Event child : events) {
        child.addFilters(C11.LOCK, RMW);
    }
    return events;
}
Also used : Register(com.dat3m.dartagnan.program.Register) Label(com.dat3m.dartagnan.program.event.core.Label) Event(com.dat3m.dartagnan.program.event.core.Event) Atom(com.dat3m.dartagnan.expression.Atom)

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