Search in sources :

Example 21 with Register

use of com.dat3m.dartagnan.program.Register 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 22 with Register

use of com.dat3m.dartagnan.program.Register 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 23 with Register

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

the class SvcompProcedures method __VERIFIER_nondet_bool.

private static void __VERIFIER_nondet_bool(VisitorBoogie visitor, Call_cmdContext ctx) {
    String registerName = ctx.call_params().Ident(0).getText();
    Register register = visitor.programBuilder.getRegister(visitor.threadCount, visitor.currentScope.getID() + ":" + registerName);
    if (register != null) {
        visitor.programBuilder.addChild(visitor.threadCount, EventFactory.newLocal(register, new BNonDet(register.getPrecision()))).setCLine(visitor.currentLine).setSourceCodeFile(visitor.sourceCodeFile);
    }
}
Also used : Register(com.dat3m.dartagnan.program.Register)

Example 24 with Register

use of com.dat3m.dartagnan.program.Register 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 25 with Register

use of com.dat3m.dartagnan.program.Register 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)

Aggregations

Register (com.dat3m.dartagnan.program.Register)154 MemoryObject (com.dat3m.dartagnan.program.memory.MemoryObject)29 Event (com.dat3m.dartagnan.program.event.core.Event)25 IExpr (com.dat3m.dartagnan.expression.IExpr)16 RegWriter (com.dat3m.dartagnan.program.event.core.utils.RegWriter)15 ProgramBuilder (com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder)13 AliasAnalysis (com.dat3m.dartagnan.program.analysis.AliasAnalysis)12 Label (com.dat3m.dartagnan.program.event.core.Label)11 ParsingException (com.dat3m.dartagnan.exception.ParsingException)10 BigInteger (java.math.BigInteger)8 IConst (com.dat3m.dartagnan.expression.IConst)7 IExprBin (com.dat3m.dartagnan.expression.IExprBin)6 IValue (com.dat3m.dartagnan.expression.IValue)6 IOpBin (com.dat3m.dartagnan.expression.op.IOpBin)6 Program (com.dat3m.dartagnan.program.Program)6 Dependency (com.dat3m.dartagnan.program.analysis.Dependency)6 ExprInterface (com.dat3m.dartagnan.expression.ExprInterface)5 Thread (com.dat3m.dartagnan.program.Thread)5 java.util (java.util)5 Atom (com.dat3m.dartagnan.expression.Atom)4