Search in sources :

Example 21 with Label

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

the class VisitorBoogie method visitCall_cmd.

@Override
public Object visitCall_cmd(Call_cmdContext ctx) {
    if (ctx.getText().contains("boogie_si_record") && !ctx.getText().contains("smack")) {
        Object local = ctx.call_params().exprs().expr(0).accept(this);
        if (local instanceof Register) {
            String txt = ctx.attr(0).getText();
            String cVar;
            if (ctx.getText().contains("arg:")) {
                cVar = txt.substring(txt.lastIndexOf(":") + 1, txt.lastIndexOf("\""));
            } else {
                cVar = txt.substring(txt.indexOf("\"") + 1, txt.lastIndexOf("\""));
            }
            ((Register) local).setCVar(cVar);
        }
    }
    String name = ctx.call_params().Define() == null ? ctx.call_params().Ident(0).getText() : ctx.call_params().Ident(1).getText();
    if (name.equals("$initialize")) {
        initMode = true;
    }
    if (name.equals("abort")) {
        Label label = programBuilder.getOrCreateLabel("END_OF_T" + threadCount);
        programBuilder.addChild(threadCount, EventFactory.newGoto(label));
        return null;
    }
    if (name.equals("reach_error")) {
        Register ass = programBuilder.getOrCreateRegister(threadCount, "assert_" + assertionIndex, ARCH_PRECISION);
        assertionIndex++;
        programBuilder.addChild(threadCount, EventFactory.newLocal(ass, new BConst(false))).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;
    }
    if (DUMMYPROCEDURES.stream().anyMatch(name::startsWith)) {
        return null;
    }
    if (PTHREADPROCEDURES.stream().anyMatch(name::contains)) {
        handlePthreadsFunctions(this, ctx);
        return null;
    }
    if (SVCOMPPROCEDURES.stream().anyMatch(name::contains)) {
        handleSvcompFunction(this, ctx);
        return null;
    }
    if (ATOMICPROCEDURES.stream().anyMatch(name::startsWith)) {
        handleAtomicFunction(this, ctx);
        return null;
    }
    if (STDPROCEDURES.stream().anyMatch(name::startsWith)) {
        handleStdFunction(this, ctx);
        return null;
    }
    if (name.contains("__VERIFIER_atomic_")) {
        atomicMode = ctx;
        if (GlobalSettings.ATOMIC_AS_LOCK) {
            SvcompProcedures.__VERIFIER_atomic(this, true);
        } else {
            SvcompProcedures.__VERIFIER_atomic_begin(this);
        }
    }
    // There will be no return for them.
    if (ctx.call_params().Define() != null && procedures.get(name).impl_body() != null) {
        Register register = programBuilder.getRegister(threadCount, currentScope.getID() + ":" + ctx.call_params().Ident(0).getText());
        if (register != null) {
            returnRegister.add(register);
        }
    }
    List<ExprInterface> callingValues = new ArrayList<>();
    if (ctx.call_params().exprs() != null) {
        callingValues = ctx.call_params().exprs().expr().stream().map(c -> (ExprInterface) c.accept(this)).collect(Collectors.toList());
    }
    if (!procedures.containsKey(name)) {
        throw new ParsingException("Procedure " + name + " is not defined");
    }
    FunCall call = EventFactory.newFunctionCall(name);
    programBuilder.addChild(threadCount, call).setCLine(currentLine).setSourceCodeFile(sourceCodeFile);
    visitProc_decl(procedures.get(name), false, callingValues);
    if (ctx.equals(atomicMode)) {
        atomicMode = null;
        if (GlobalSettings.ATOMIC_AS_LOCK) {
            SvcompProcedures.__VERIFIER_atomic(this, false);
        } else {
            SvcompProcedures.__VERIFIER_atomic_end(this);
        }
    }
    programBuilder.addChild(threadCount, EventFactory.newFunctionReturn(name)).setCLine(call.getCLine()).setSourceCodeFile(sourceCodeFile);
    if (name.equals("$initialize")) {
        initMode = false;
    }
    return null;
}
Also used : FunCall(com.dat3m.dartagnan.program.event.core.annotations.FunCall) Register(com.dat3m.dartagnan.program.Register) ParsingException(com.dat3m.dartagnan.exception.ParsingException) Label(com.dat3m.dartagnan.program.event.core.Label) MemoryObject(com.dat3m.dartagnan.program.memory.MemoryObject)

Example 22 with Label

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

the class VisitorBoogie method visitReturn_cmd.

@Override
public Object visitReturn_cmd(Return_cmdContext ctx) {
    Label label = programBuilder.getOrCreateLabel("END_OF_" + currentScope.getID());
    programBuilder.addChild(threadCount, EventFactory.newGoto(label));
    return null;
}
Also used : Label(com.dat3m.dartagnan.program.event.core.Label)

Example 23 with Label

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

the class BranchEquivalence method computeBranches.

// ========================== Branching Property =========================
private Branch computeBranches(Event start, Map<Event, Branch> branchMap, Map<Event, Branch> finalBranchMap) {
    if (branchMap.containsKey(start)) {
        // <start> was already visited
        return branchMap.get(start);
    }
    Branch b = new Branch(start);
    branchMap.put(start, b);
    Event succ = start;
    do {
        if (succ instanceof CondJump) {
            CondJump jump = (CondJump) succ;
            if (!alwaysSplitOnJump && jump.isGoto()) {
                // There is only one branch we can proceed on, so we don't need to split the current branch
                succ = jump.getLabel();
            } else {
                // Split into two branches...
                Branch b1 = computeBranches(jump.getSuccessor(), branchMap, finalBranchMap);
                Branch b2 = computeBranches(jump.getLabel(), branchMap, finalBranchMap);
                b1.parents.add(b);
                b.children.add(b1);
                b2.parents.add(b);
                b.children.add(b2);
                return b;
            }
        } else {
            // No branching happened, thus we stay on the current branch
            succ = succ.getSuccessor();
        }
        if (succ == null) {
            finalBranchMap.put(b.events.get(b.events.size() - 1), b);
            return b;
        } else if ((succ instanceof Label && !((Label) succ).getJumpSet().isEmpty()) || branchMap.containsKey(succ)) {
            // We ran into a merge point
            Branch b1 = computeBranches(succ, branchMap, finalBranchMap);
            b1.parents.add(b);
            b.children.add(b1);
            return b;
        } else {
            b.events.add(succ);
        }
    } while (true);
}
Also used : Label(com.dat3m.dartagnan.program.event.core.Label) Event(com.dat3m.dartagnan.program.event.core.Event) CondJump(com.dat3m.dartagnan.program.event.core.CondJump)

Example 24 with Label

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

the class ProgramBuilder method validateLabels.

private void validateLabels(Thread thread) throws MalformedProgramException {
    Map<String, Label> threadLabels = new HashMap<>();
    Set<String> referencedLabels = new HashSet<>();
    Event e = thread.getEntry();
    while (e != null) {
        if (e instanceof CondJump) {
            referencedLabels.add(((CondJump) e).getLabel().getName());
        } else if (e instanceof Label) {
            Label label = labels.remove(((Label) e).getName());
            if (label == null) {
                throw new MalformedProgramException("Duplicated label " + ((Label) e).getName());
            }
            threadLabels.put(label.getName(), label);
        }
        e = e.getSuccessor();
    }
    for (String labelName : referencedLabels) {
        if (!threadLabels.containsKey(labelName)) {
            throw new MalformedProgramException("Illegal jump to label " + labelName);
        }
    }
}
Also used : MalformedProgramException(com.dat3m.dartagnan.exception.MalformedProgramException) HashMap(java.util.HashMap) Label(com.dat3m.dartagnan.program.event.core.Label) Event(com.dat3m.dartagnan.program.event.core.Event) CondJump(com.dat3m.dartagnan.program.event.core.CondJump) HashSet(java.util.HashSet)

Example 25 with Label

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

the class VisitorLitmusAArch64 method visitBranchRegister.

@Override
public Object visitBranchRegister(LitmusAArch64Parser.BranchRegisterContext ctx) {
    Register register = programBuilder.getOrErrorRegister(mainThread, ctx.rV);
    Atom expr = new Atom(register, ctx.branchRegInstruction().op, IValue.ZERO);
    Label label = programBuilder.getOrCreateLabel(ctx.label().getText());
    return programBuilder.addChild(mainThread, EventFactory.newJump(expr, label));
}
Also used : Register(com.dat3m.dartagnan.program.Register) Label(com.dat3m.dartagnan.program.event.core.Label) 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