Search in sources :

Example 16 with ParsingException

use of com.dat3m.dartagnan.exception.ParsingException in project Dat3M by hernanponcedeleon.

the class VisitorLitmusC method visitReVarName.

@Override
public ExprInterface visitReVarName(LitmusCParser.ReVarNameContext ctx) {
    Register register = getReturnRegister(false);
    IExpr variable = visitVarName(ctx.varName());
    if (variable instanceof Register) {
        Register result = (Register) variable;
        return assignToReturnRegister(register, result);
    }
    throw new ParsingException("Invalid syntax near " + ctx.getText());
}
Also used : Register(com.dat3m.dartagnan.program.Register) ParsingException(com.dat3m.dartagnan.exception.ParsingException)

Example 17 with ParsingException

use of com.dat3m.dartagnan.exception.ParsingException in project Dat3M by hernanponcedeleon.

the class SvcompProcedures method __VERIFIER_nondet.

private static void __VERIFIER_nondet(VisitorBoogie visitor, Call_cmdContext ctx, String name) {
    INonDetTypes type = null;
    switch(name) {
        case "__VERIFIER_nondet_int":
            type = INonDetTypes.INT;
            break;
        case "__VERIFIER_nondet_uint":
        case "__VERIFIER_nondet_unsigned_int":
            type = INonDetTypes.UINT;
            break;
        case "__VERIFIER_nondet_short":
            type = INonDetTypes.SHORT;
            break;
        case "__VERIFIER_nondet_ushort":
        case "__VERIFIER_nondet_unsigned_short":
            type = INonDetTypes.USHORT;
            break;
        case "__VERIFIER_nondet_long":
            type = INonDetTypes.LONG;
            break;
        case "__VERIFIER_nondet_ulong":
            type = INonDetTypes.ULONG;
            break;
        case "__VERIFIER_nondet_char":
            type = INonDetTypes.CHAR;
            break;
        case "__VERIFIER_nondet_uchar":
            type = INonDetTypes.UCHAR;
            break;
        default:
            throw new ParsingException(name + " is not supported");
    }
    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 INonDet(type, register.getPrecision()))).setCLine(visitor.currentLine).setSourceCodeFile(visitor.sourceCodeFile);
    }
}
Also used : Register(com.dat3m.dartagnan.program.Register) ParsingException(com.dat3m.dartagnan.exception.ParsingException)

Example 18 with ParsingException

use of com.dat3m.dartagnan.exception.ParsingException in project Dat3M by hernanponcedeleon.

the class VisitorBoogie method visitLocal_vars.

public Object visitLocal_vars(Local_varsContext ctx, int scope) {
    for (Attr_typed_idents_whereContext atiwC : ctx.typed_idents_wheres().attr_typed_idents_where()) {
        for (ParseTree ident : atiwC.typed_idents_where().typed_idents().idents().Ident()) {
            String name = ident.getText();
            String type = atiwC.typed_idents_where().typed_idents().type().getText();
            int precision = type.contains("bv") ? Integer.parseInt(type.split("bv")[1]) : ARCH_PRECISION;
            if (constantsTypeMap.containsKey(name)) {
                throw new ParsingException("Variable " + name + " is already defined as a constant");
            }
            if (programBuilder.getObject(name) != null) {
                throw new ParsingException("Variable " + name + " is already defined globally");
            }
            programBuilder.getOrCreateRegister(scope, currentScope.getID() + ":" + name, precision);
        }
    }
    return null;
}
Also used : ParsingException(com.dat3m.dartagnan.exception.ParsingException) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 19 with ParsingException

use of com.dat3m.dartagnan.exception.ParsingException 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 20 with ParsingException

use of com.dat3m.dartagnan.exception.ParsingException 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

ParsingException (com.dat3m.dartagnan.exception.ParsingException)22 Register (com.dat3m.dartagnan.program.Register)10 MemoryObject (com.dat3m.dartagnan.program.memory.MemoryObject)7 Label (com.dat3m.dartagnan.program.event.core.Label)5 ParseTree (org.antlr.v4.runtime.tree.ParseTree)4 RecursiveRelation (com.dat3m.dartagnan.wmm.relation.RecursiveRelation)3 Relation (com.dat3m.dartagnan.wmm.relation.Relation)3 BigInteger (java.math.BigInteger)3 Atom (com.dat3m.dartagnan.expression.Atom)2 Scope (com.dat3m.dartagnan.parsers.program.boogie.Scope)2 Cmp (com.dat3m.dartagnan.program.event.core.Cmp)2 Event (com.dat3m.dartagnan.program.event.core.Event)2 FunCall (com.dat3m.dartagnan.program.event.core.annotations.FunCall)2 GlobalSettings (com.dat3m.dartagnan.GlobalSettings)1 ARCH_PRECISION (com.dat3m.dartagnan.GlobalSettings.ARCH_PRECISION)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