Search in sources :

Example 1 with NOT

use of com.dat3m.dartagnan.expression.op.BOpUn.NOT in project Dat3M by hernanponcedeleon.

the class VisitorBoogie method visitFun_expr.

@Override
public Object visitFun_expr(Fun_exprContext ctx) {
    String name = ctx.Ident().getText();
    Function function = functions.get(name);
    if (function == null) {
        throw new ParsingException("Function " + name + " is not defined");
    }
    if (name.contains("$load.")) {
        return ctx.expr(1).accept(this);
    }
    if (name.contains("$store.")) {
        if (smackDummyVariables.contains(ctx.expr(1).getText())) {
            return null;
        }
        IExpr address = (IExpr) ctx.expr(1).accept(this);
        IExpr value = (IExpr) ctx.expr(2).accept(this);
        // This improves the blow-up
        if (initMode && !(value instanceof MemoryObject)) {
            ExprInterface lhs = address;
            int rhs = 0;
            while (lhs instanceof IExprBin) {
                rhs += ((IExprBin) lhs).getRHS().reduce().getValueAsInt();
                lhs = ((IExprBin) lhs).getLHS();
            }
            String text = ctx.expr(1).getText();
            String[] split = text.split("add.ref");
            if (split.length > 1) {
                text = split[split.length - 1];
                text = text.substring(text.indexOf("(") + 1, text.indexOf(","));
            }
            programBuilder.getOrNewObject(text).appendInitialValue(rhs, value.reduce());
            return null;
        }
        programBuilder.addChild(threadCount, EventFactory.newStore(address, value, null)).setCLine(currentLine).setSourceCodeFile(sourceCodeFile);
        return null;
    }
    // push currentCall to the call stack
    List<Object> callParams = ctx.expr().stream().map(e -> e.accept(this)).collect(Collectors.toList());
    currentCall = new FunctionCall(function, callParams, currentCall);
    if (LLVMFUNCTIONS.stream().anyMatch(name::startsWith)) {
        currentCall = currentCall.getParent();
        return llvmFunction(name, callParams);
    }
    if (LLVMPREDICATES.stream().anyMatch(name::equals)) {
        currentCall = currentCall.getParent();
        return llvmPredicate(name, callParams);
    }
    if (LLVMUNARY.stream().anyMatch(name::startsWith)) {
        currentCall = currentCall.getParent();
        return llvmUnary(name, callParams);
    }
    if (SMACKPREDICATES.stream().anyMatch(name::equals)) {
        currentCall = currentCall.getParent();
        return smackPredicate(name, callParams);
    }
    // Some functions do not have a body
    if (function.getBody() == null) {
        throw new ParsingException("Function " + name + " has no implementation");
    }
    Object ret = function.getBody().accept(this);
    // pop currentCall from the call stack
    currentCall = currentCall.getParent();
    return ret;
}
Also used : java.util(java.util) COpBin(com.dat3m.dartagnan.expression.op.COpBin) BoogieBaseVisitor(com.dat3m.dartagnan.parsers.BoogieBaseVisitor) NOT(com.dat3m.dartagnan.expression.op.BOpUn.NOT) IOpUn(com.dat3m.dartagnan.expression.op.IOpUn) BoogieVisitor(com.dat3m.dartagnan.parsers.BoogieVisitor) AtomicProcedures.handleAtomicFunction(com.dat3m.dartagnan.parsers.program.visitors.boogie.AtomicProcedures.handleAtomicFunction) Scope(com.dat3m.dartagnan.parsers.program.boogie.Scope) com.dat3m.dartagnan.expression(com.dat3m.dartagnan.expression) PTHREADPROCEDURES(com.dat3m.dartagnan.parsers.program.visitors.boogie.PthreadsProcedures.PTHREADPROCEDURES) LLVMUNARY(com.dat3m.dartagnan.parsers.program.boogie.LlvmUnary.LLVMUNARY) SMACKPREDICATES(com.dat3m.dartagnan.parsers.program.boogie.SmackPredicates.SMACKPREDICATES) DUMMYPROCEDURES(com.dat3m.dartagnan.parsers.program.visitors.boogie.DummyProcedures.DUMMYPROCEDURES) ParseTree(org.antlr.v4.runtime.tree.ParseTree) BigInteger(java.math.BigInteger) BoogieParser(com.dat3m.dartagnan.parsers.BoogieParser) ProgramBuilder(com.dat3m.dartagnan.parsers.program.utils.ProgramBuilder) SvcompProcedures.handleSvcompFunction(com.dat3m.dartagnan.parsers.program.visitors.boogie.SvcompProcedures.handleSvcompFunction) MemoryObject(com.dat3m.dartagnan.program.memory.MemoryObject) PthreadPool(com.dat3m.dartagnan.parsers.program.boogie.PthreadPool) EQ(com.dat3m.dartagnan.expression.op.COpBin.EQ) Function(com.dat3m.dartagnan.parsers.program.boogie.Function) BeginAtomic(com.dat3m.dartagnan.program.event.lang.svcomp.BeginAtomic) LLVMFUNCTIONS(com.dat3m.dartagnan.parsers.program.boogie.LlvmFunctions.LLVMFUNCTIONS) ARCH_PRECISION(com.dat3m.dartagnan.GlobalSettings.ARCH_PRECISION) ExprSimplifier(com.dat3m.dartagnan.expression.processing.ExprSimplifier) LlvmFunctions.llvmFunction(com.dat3m.dartagnan.parsers.program.boogie.LlvmFunctions.llvmFunction) SVCOMPPROCEDURES(com.dat3m.dartagnan.parsers.program.visitors.boogie.SvcompProcedures.SVCOMPPROCEDURES) ParsingException(com.dat3m.dartagnan.exception.ParsingException) SmackPredicates.smackPredicate(com.dat3m.dartagnan.parsers.program.boogie.SmackPredicates.smackPredicate) Collectors(java.util.stream.Collectors) LLVMPREDICATES(com.dat3m.dartagnan.parsers.program.boogie.LlvmPredicates.LLVMPREDICATES) Label(com.dat3m.dartagnan.program.event.core.Label) Tag(com.dat3m.dartagnan.program.event.Tag) EventFactory(com.dat3m.dartagnan.program.event.EventFactory) FunctionCall(com.dat3m.dartagnan.parsers.program.boogie.FunctionCall) Logger(org.apache.logging.log4j.Logger) LlvmPredicates.llvmPredicate(com.dat3m.dartagnan.parsers.program.boogie.LlvmPredicates.llvmPredicate) StdProcedures.handleStdFunction(com.dat3m.dartagnan.parsers.program.visitors.boogie.StdProcedures.handleStdFunction) Register(com.dat3m.dartagnan.program.Register) LlvmUnary.llvmUnary(com.dat3m.dartagnan.parsers.program.boogie.LlvmUnary.llvmUnary) ATOMICPROCEDURES(com.dat3m.dartagnan.parsers.program.visitors.boogie.AtomicProcedures.ATOMICPROCEDURES) STDPROCEDURES(com.dat3m.dartagnan.parsers.program.visitors.boogie.StdProcedures.STDPROCEDURES) GlobalSettings(com.dat3m.dartagnan.GlobalSettings) LogManager(org.apache.logging.log4j.LogManager) FunCall(com.dat3m.dartagnan.program.event.core.annotations.FunCall) PthreadsProcedures.handlePthreadsFunctions(com.dat3m.dartagnan.parsers.program.visitors.boogie.PthreadsProcedures.handlePthreadsFunctions) AtomicProcedures.handleAtomicFunction(com.dat3m.dartagnan.parsers.program.visitors.boogie.AtomicProcedures.handleAtomicFunction) SvcompProcedures.handleSvcompFunction(com.dat3m.dartagnan.parsers.program.visitors.boogie.SvcompProcedures.handleSvcompFunction) Function(com.dat3m.dartagnan.parsers.program.boogie.Function) LlvmFunctions.llvmFunction(com.dat3m.dartagnan.parsers.program.boogie.LlvmFunctions.llvmFunction) StdProcedures.handleStdFunction(com.dat3m.dartagnan.parsers.program.visitors.boogie.StdProcedures.handleStdFunction) ParsingException(com.dat3m.dartagnan.exception.ParsingException) MemoryObject(com.dat3m.dartagnan.program.memory.MemoryObject) MemoryObject(com.dat3m.dartagnan.program.memory.MemoryObject) FunctionCall(com.dat3m.dartagnan.parsers.program.boogie.FunctionCall)

Aggregations

GlobalSettings (com.dat3m.dartagnan.GlobalSettings)1 ARCH_PRECISION (com.dat3m.dartagnan.GlobalSettings.ARCH_PRECISION)1 ParsingException (com.dat3m.dartagnan.exception.ParsingException)1 com.dat3m.dartagnan.expression (com.dat3m.dartagnan.expression)1 NOT (com.dat3m.dartagnan.expression.op.BOpUn.NOT)1 COpBin (com.dat3m.dartagnan.expression.op.COpBin)1 EQ (com.dat3m.dartagnan.expression.op.COpBin.EQ)1 IOpUn (com.dat3m.dartagnan.expression.op.IOpUn)1 ExprSimplifier (com.dat3m.dartagnan.expression.processing.ExprSimplifier)1 BoogieBaseVisitor (com.dat3m.dartagnan.parsers.BoogieBaseVisitor)1 BoogieParser (com.dat3m.dartagnan.parsers.BoogieParser)1 BoogieVisitor (com.dat3m.dartagnan.parsers.BoogieVisitor)1 Function (com.dat3m.dartagnan.parsers.program.boogie.Function)1 FunctionCall (com.dat3m.dartagnan.parsers.program.boogie.FunctionCall)1 LLVMFUNCTIONS (com.dat3m.dartagnan.parsers.program.boogie.LlvmFunctions.LLVMFUNCTIONS)1 LlvmFunctions.llvmFunction (com.dat3m.dartagnan.parsers.program.boogie.LlvmFunctions.llvmFunction)1 LLVMPREDICATES (com.dat3m.dartagnan.parsers.program.boogie.LlvmPredicates.LLVMPREDICATES)1 LlvmPredicates.llvmPredicate (com.dat3m.dartagnan.parsers.program.boogie.LlvmPredicates.llvmPredicate)1 LLVMUNARY (com.dat3m.dartagnan.parsers.program.boogie.LlvmUnary.LLVMUNARY)1 LlvmUnary.llvmUnary (com.dat3m.dartagnan.parsers.program.boogie.LlvmUnary.llvmUnary)1