Search in sources :

Example 6 with IConst

use of com.dat3m.dartagnan.expression.IConst in project Dat3M by hernanponcedeleon.

the class AtomicProcedures method atomicCmpXchg.

private static void atomicCmpXchg(VisitorBoogie visitor, Call_cmdContext ctx) {
    Register reg = visitor.programBuilder.getOrCreateRegister(visitor.threadCount, visitor.currentScope.getID() + ":" + ctx.call_params().Ident(0).getText(), ARCH_PRECISION);
    List<BoogieParser.ExprContext> params = ctx.call_params().exprs().expr();
    IExpr addr = (IExpr) params.get(0).accept(visitor);
    // NOTE: We assume a register here
    IExpr expectedAddr = (IExpr) params.get(1).accept(visitor);
    IExpr desiredVal = (IExpr) params.get(2).accept(visitor);
    String mo = null;
    boolean strong = ctx.getText().contains("strong");
    if (params.size() > 3) {
        mo = intToMo(((IConst) params.get(3).accept(visitor)).getValueAsInt());
    // NOTE: We forget about the 5th parameter (MO on fail) because it is never used
    // (see issue #123 for an explanation)
    }
    visitor.programBuilder.addChild(visitor.threadCount, Atomic.newCompareExchange(reg, addr, expectedAddr, desiredVal, mo, strong)).setCLine(visitor.currentLine).setSourceCodeFile(visitor.sourceCodeFile);
}
Also used : Register(com.dat3m.dartagnan.program.Register) IExpr(com.dat3m.dartagnan.expression.IExpr) IConst(com.dat3m.dartagnan.expression.IConst)

Example 7 with IConst

use of com.dat3m.dartagnan.expression.IConst in project Dat3M by hernanponcedeleon.

the class StdProcedures method __assert.

private static void __assert(VisitorBoogie visitor, Call_cmdContext ctx) {
    Register ass = visitor.programBuilder.getOrCreateRegister(visitor.threadCount, "assert_" + visitor.assertionIndex, ARCH_PRECISION);
    visitor.assertionIndex++;
    ExprInterface expr = (ExprInterface) ctx.call_params().exprs().accept(visitor);
    if (expr instanceof IConst && ((IConst) expr).getValue().compareTo(BigInteger.ONE) == 0) {
        return;
    }
    Local event = EventFactory.newLocal(ass, expr);
    event.addFilters(Tag.ASSERTION);
    visitor.programBuilder.addChild(visitor.threadCount, event);
}
Also used : ExprInterface(com.dat3m.dartagnan.expression.ExprInterface) Register(com.dat3m.dartagnan.program.Register) Local(com.dat3m.dartagnan.program.event.core.Local) IConst(com.dat3m.dartagnan.expression.IConst)

Example 8 with IConst

use of com.dat3m.dartagnan.expression.IConst in project Dat3M by hernanponcedeleon.

the class AndersenAliasAnalysis method processResults.

private void processResults(Program program) {
    // Used to have pointer analysis when having arrays and structures
    Map<Register, Set<Location>> targets = new HashMap<>();
    BiConsumer<Register, Location> addTarget = (r, l) -> targets.put(r, Set.of(l));
    BiConsumer<Register, MemoryObject> addTargetArray = (r, b) -> targets.put(r, IntStream.range(0, b.size()).mapToObj(i -> new Location(b, i)).collect(Collectors.toSet()));
    for (Event ev : program.getCache().getEvents(FilterBasic.get(Tag.LOCAL))) {
        // Not only Local events have EType.LOCAL tag
        if (!(ev instanceof Local)) {
            continue;
        }
        Local l = (Local) ev;
        ExprInterface exp = l.getExpr();
        Register reg = l.getResultRegister();
        if (exp instanceof MemoryObject) {
            addTarget.accept(reg, new Location((MemoryObject) exp, 0));
        } else if (exp instanceof IExprBin) {
            IExpr base = ((IExprBin) exp).getBase();
            if (base instanceof MemoryObject) {
                IExpr rhs = ((IExprBin) exp).getRHS();
                // FIXME Address extends IConst
                if (rhs instanceof IConst) {
                    addTarget.accept(reg, new Location((MemoryObject) base, ((IConst) rhs).getValueAsInt()));
                } else {
                    addTargetArray.accept(reg, (MemoryObject) base);
                }
                continue;
            }
            if (!(base instanceof Register)) {
                continue;
            }
            // accept register2 = register1 + constant
            for (Location target : targets.getOrDefault(base, Set.of())) {
                IExpr rhs = ((IExprBin) exp).getRHS();
                // FIXME Address extends IConst
                if (rhs instanceof IConst) {
                    int o = target.offset + ((IConst) rhs).getValueAsInt();
                    if (o < target.base.size()) {
                        addTarget.accept(reg, new Location(target.base, o));
                    }
                } else {
                    addTargetArray.accept(reg, target.base);
                }
            }
        }
    }
    for (Event e : program.getCache().getEvents(FilterBasic.get(Tag.MEMORY))) {
        IExpr address = ((MemEvent) e).getAddress();
        Set<Location> addresses;
        if (address instanceof Register) {
            Set<Location> target = targets.get(address);
            if (target != null) {
                addresses = target;
            } else {
                addresses = graph.getAddresses(address);
            }
        } else {
            Constant addressConstant = new Constant(address);
            if (addressConstant.failed) {
                addresses = maxAddressSet;
            } else {
                Verify.verify(addressConstant.location != null, "memory event accessing a pure constant address");
                addresses = ImmutableSet.of(addressConstant.location);
            }
        }
        if (addresses.size() == 0) {
            addresses = maxAddressSet;
        }
        eventAddressSpaceMap.put((MemEvent) e, ImmutableSet.copyOf(addresses));
    }
}
Also used : MemoryObject(com.dat3m.dartagnan.program.memory.MemoryObject) IntStream(java.util.stream.IntStream) java.util(java.util) Verify(com.google.common.base.Verify) ImmutableSet(com.google.common.collect.ImmutableSet) ExprInterface(com.dat3m.dartagnan.expression.ExprInterface) Configuration(org.sosy_lab.common.configuration.Configuration) com.dat3m.dartagnan.program.event.core(com.dat3m.dartagnan.program.event.core) Collectors(java.util.stream.Collectors) IConst(com.dat3m.dartagnan.expression.IConst) Sets(com.google.common.collect.Sets) Tag(com.dat3m.dartagnan.program.event.Tag) PLUS(com.dat3m.dartagnan.expression.op.IOpBin.PLUS) IExpr(com.dat3m.dartagnan.expression.IExpr) BiConsumer(java.util.function.BiConsumer) IExprBin(com.dat3m.dartagnan.expression.IExprBin) Program(com.dat3m.dartagnan.program.Program) Preconditions(com.google.common.base.Preconditions) Register(com.dat3m.dartagnan.program.Register) RegWriter(com.dat3m.dartagnan.program.event.core.utils.RegWriter) FilterBasic(com.dat3m.dartagnan.program.filter.FilterBasic) InvalidConfigurationException(org.sosy_lab.common.configuration.InvalidConfigurationException) IExprBin(com.dat3m.dartagnan.expression.IExprBin) ImmutableSet(com.google.common.collect.ImmutableSet) ExprInterface(com.dat3m.dartagnan.expression.ExprInterface) IConst(com.dat3m.dartagnan.expression.IConst) Register(com.dat3m.dartagnan.program.Register) MemoryObject(com.dat3m.dartagnan.program.memory.MemoryObject) IExpr(com.dat3m.dartagnan.expression.IExpr)

Aggregations

IConst (com.dat3m.dartagnan.expression.IConst)8 IExpr (com.dat3m.dartagnan.expression.IExpr)7 Register (com.dat3m.dartagnan.program.Register)7 ExprInterface (com.dat3m.dartagnan.expression.ExprInterface)3 IExprBin (com.dat3m.dartagnan.expression.IExprBin)1 IOpBin (com.dat3m.dartagnan.expression.op.IOpBin)1 PLUS (com.dat3m.dartagnan.expression.op.IOpBin.PLUS)1 Program (com.dat3m.dartagnan.program.Program)1 Tag (com.dat3m.dartagnan.program.event.Tag)1 com.dat3m.dartagnan.program.event.core (com.dat3m.dartagnan.program.event.core)1 Local (com.dat3m.dartagnan.program.event.core.Local)1 RegWriter (com.dat3m.dartagnan.program.event.core.utils.RegWriter)1 FilterBasic (com.dat3m.dartagnan.program.filter.FilterBasic)1 MemoryObject (com.dat3m.dartagnan.program.memory.MemoryObject)1 Preconditions (com.google.common.base.Preconditions)1 Verify (com.google.common.base.Verify)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1 java.util (java.util)1 BiConsumer (java.util.function.BiConsumer)1