Search in sources :

Example 6 with CondJump

use of com.dat3m.dartagnan.program.event.core.CondJump 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 7 with CondJump

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

Example 8 with CondJump

use of com.dat3m.dartagnan.program.event.core.CondJump 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 9 with CondJump

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

the class Dependency method process.

private void process(Thread thread, ExecutionAnalysis exec) {
    Map<Event, Set<Writer>> jumps = new HashMap<>();
    Set<Writer> state = new HashSet<>();
    for (Register register : thread.getRegisters()) {
        state.add(new Writer(register, null));
    }
    for (Event event : thread.getEvents()) {
        // merge with incoming jumps
        Set<Writer> j = jumps.remove(event);
        if (j != null) {
            state.addAll(j);
        }
        // collecting dependencies, mixing 'data' and 'addr'
        Set<Register> registers = new HashSet<>();
        if (event instanceof RegReaderData) {
            registers.addAll(((RegReaderData) event).getDataRegs());
        }
        if (event instanceof MemEvent) {
            registers.addAll(((MemEvent) event).getAddress().getRegs());
        }
        if (!registers.isEmpty()) {
            Map<Register, State> result = new HashMap<>();
            for (Register register : registers) {
                if (register.getThreadId() == Register.NO_THREAD) {
                    continue;
                }
                State writers;
                if (register.getThreadId() != event.getThread().getId()) {
                    writers = finalWriters.get(register);
                    checkArgument(writers != null, "Helper thread %s should be listed after their creator thread %s.", thread.getId(), register.getThreadId());
                    if (writers.may.size() != 1) {
                        logger.warn("Writers {} for inter-thread register {} read by event {} of thread {}", writers.may, register, event, thread.getId());
                    }
                } else {
                    writers = process(state, register, exec);
                    if (!writers.initialized) {
                        logger.warn("Uninitialized register {} read by event {} of thread {}", register, event, thread.getId());
                    }
                }
                result.put(register, writers);
            }
            map.put(event, result);
        }
        // update state, if changed by event
        if (event instanceof RegWriter) {
            Register register = ((RegWriter) event).getResultRegister();
            if (event.cfImpliesExec()) {
                state.removeIf(e -> e.register.equals(register));
            }
            state.add(new Writer(register, event));
        }
        // copy state, if branching
        if (event instanceof CondJump) {
            jumps.computeIfAbsent(((CondJump) event).getLabel(), k -> new HashSet<>()).addAll(state);
            if (((CondJump) event).isGoto()) {
                state.clear();
            }
        }
    }
    if (!jumps.isEmpty()) {
        logger.warn("Thread {} contains jumps to removed labels {}", thread.getId(), jumps.keySet());
        for (Set<Writer> j : jumps.values()) {
            state.addAll(j);
        }
    }
    for (Register register : thread.getRegisters()) {
        finalWriters.put(register, process(state, register, exec));
    }
}
Also used : Options(org.sosy_lab.common.configuration.Options) java.util(java.util) Configuration(org.sosy_lab.common.configuration.Configuration) IntStream.range(java.util.stream.IntStream.range) Thread(com.dat3m.dartagnan.program.Thread) Collectors(java.util.stream.Collectors) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) Context(com.dat3m.dartagnan.verification.Context) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Collectors.toList(java.util.stream.Collectors.toList) Logger(org.apache.logging.log4j.Logger) Verify.verify(com.google.common.base.Verify.verify) Program(com.dat3m.dartagnan.program.Program) Event(com.dat3m.dartagnan.program.event.core.Event) RegReaderData(com.dat3m.dartagnan.program.event.core.utils.RegReaderData) Register(com.dat3m.dartagnan.program.Register) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) CondJump(com.dat3m.dartagnan.program.event.core.CondJump) LogManager(org.apache.logging.log4j.LogManager) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException) CondJump(com.dat3m.dartagnan.program.event.core.CondJump) Register(com.dat3m.dartagnan.program.Register) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) RegReaderData(com.dat3m.dartagnan.program.event.core.utils.RegReaderData) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) Event(com.dat3m.dartagnan.program.event.core.Event) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter)

Example 10 with CondJump

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

Aggregations

CondJump (com.dat3m.dartagnan.program.event.core.CondJump)14 Event (com.dat3m.dartagnan.program.event.core.Event)10 Label (com.dat3m.dartagnan.program.event.core.Label)9 Program (com.dat3m.dartagnan.program.Program)4 Thread (com.dat3m.dartagnan.program.Thread)4 LogManager (org.apache.logging.log4j.LogManager)4 Logger (org.apache.logging.log4j.Logger)4 MemEvent (com.dat3m.dartagnan.program.event.core.MemEvent)3 Preconditions (com.google.common.base.Preconditions)3 HashMap (java.util.HashMap)3 Configuration (org.sosy_lab.common.configuration.Configuration)3 InvalidConfigurationException (org.sosy_lab.common.configuration.InvalidConfigurationException)3 Atom (com.dat3m.dartagnan.expression.Atom)2 BExprUn (com.dat3m.dartagnan.expression.BExprUn)2 ProgramBuilder (com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder)2 Register (com.dat3m.dartagnan.program.Register)2 Tag (com.dat3m.dartagnan.program.event.Tag)2 RegWriter (com.dat3m.dartagnan.program.event.core.utils.RegWriter)2 Context (com.dat3m.dartagnan.verification.Context)2 java.util (java.util)2