Search in sources :

Example 6 with ParsingException

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

the class VisitorBoogie method visitProc_decl.

private void visitProc_decl(Proc_declContext ctx, boolean create, List<ExprInterface> callingValues) {
    currentLine = -1;
    if (ctx.proc_sign().proc_sign_out() != null) {
        for (Attr_typed_idents_whereContext atiwC : ctx.proc_sign().proc_sign_out().attr_typed_idents_wheres().attr_typed_idents_where()) {
            for (ParseTree ident : atiwC.typed_idents_where().typed_idents().idents().Ident()) {
                currentReturnName = ident.getText();
            }
        }
    }
    if (create) {
        threadCount++;
        String name = ctx.proc_sign().Ident().getText();
        programBuilder.initThread(name, threadCount);
        if (threadCount != 1) {
            // Used to allow execution of threads after they have been created (pthread_create)
            MemoryObject object = programBuilder.getOrNewObject(String.format("%s(%s)_active", pool.getPtrFromInt(threadCount), pool.getCreatorFromPtr(pool.getPtrFromInt(threadCount))));
            Register reg = programBuilder.getOrCreateRegister(threadCount, null, ARCH_PRECISION);
            programBuilder.addChild(threadCount, EventFactory.Pthread.newStart(reg, object));
        }
    }
    currentScope = new Scope(nextScopeID, currentScope);
    nextScopeID++;
    Impl_bodyContext body = ctx.impl_body();
    if (body == null) {
        throw new ParsingException(ctx.proc_sign().Ident().getText() + " cannot be handled");
    }
    if (ctx.proc_sign().proc_sign_in() != null) {
        int index = 0;
        for (Attr_typed_idents_whereContext atiwC : ctx.proc_sign().proc_sign_in().attr_typed_idents_wheres().attr_typed_idents_where()) {
            for (ParseTree ident : atiwC.typed_idents_where().typed_idents().idents().Ident()) {
                // To deal with references passed to created threads
                if (index < callingValues.size()) {
                    String type = atiwC.typed_idents_where().typed_idents().type().getText();
                    int precision = type.contains("bv") ? Integer.parseInt(type.split("bv")[1]) : ARCH_PRECISION;
                    Register register = programBuilder.getOrCreateRegister(threadCount, currentScope.getID() + ":" + ident.getText(), precision);
                    ExprInterface value = callingValues.get(index);
                    programBuilder.addChild(threadCount, EventFactory.newLocal(register, value)).setCLine(currentLine).setSourceCodeFile(sourceCodeFile);
                    index++;
                }
            }
        }
    }
    for (Local_varsContext localVarContext : body.local_vars()) {
        visitLocal_vars(localVarContext, threadCount);
    }
    visitChildren(body.stmt_list());
    Label label = programBuilder.getOrCreateLabel("END_OF_" + currentScope.getID());
    programBuilder.addChild(threadCount, label);
    currentScope = currentScope.getParent();
    if (create) {
        if (threadCount != 1) {
            // Used to mark the end of the execution of a thread (used by pthread_join)
            MemoryObject object = programBuilder.getOrNewObject(String.format("%s(%s)_active", pool.getPtrFromInt(threadCount), pool.getCreatorFromPtr(pool.getPtrFromInt(threadCount))));
            programBuilder.addChild(threadCount, EventFactory.Pthread.newEnd(object));
        }
    }
}
Also used : Scope(com.dat3m.dartagnan.parsers.program.boogie.Scope) Register(com.dat3m.dartagnan.program.Register) ParsingException(com.dat3m.dartagnan.exception.ParsingException) MemoryObject(com.dat3m.dartagnan.program.memory.MemoryObject) Label(com.dat3m.dartagnan.program.event.core.Label) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 7 with ParsingException

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

the class VisitorBoogie method visitVar_expr.

@Override
public Object visitVar_expr(Var_exprContext ctx) {
    String name = ctx.getText();
    if (currentCall != null && currentCall.getFunction().getBody() != null) {
        return currentCall.replaceVarsByExprs(ctx);
    }
    if (constantsMap.containsKey(name)) {
        return constantsMap.get(name);
    }
    if (constantsTypeMap.containsKey(name)) {
        // Dummy register needed to parse axioms
        return new Register(name, Register.NO_THREAD, constantsTypeMap.get(name));
    }
    Register register = programBuilder.getRegister(threadCount, currentScope.getID() + ":" + name);
    if (register != null) {
        return register;
    }
    MemoryObject object = programBuilder.getObject(name);
    if (object != null) {
        return object;
    }
    throw new ParsingException("Variable " + name + " is not defined");
}
Also used : Register(com.dat3m.dartagnan.program.Register) ParsingException(com.dat3m.dartagnan.exception.ParsingException) MemoryObject(com.dat3m.dartagnan.program.memory.MemoryObject)

Example 8 with ParsingException

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

the class VisitorBoogie method visitMain.

@Override
public Object visitMain(MainContext ctx) {
    visitLine_comment(ctx.line_comment(0));
    for (Func_declContext funDecContext : ctx.func_decl()) {
        visitFunc_decl(funDecContext);
    }
    for (Proc_declContext procDecContext : ctx.proc_decl()) {
        preProc_decl(procDecContext);
    }
    for (Const_declContext constDecContext : ctx.const_decl()) {
        visitConst_decl(constDecContext);
    }
    for (Axiom_declContext axiomDecContext : ctx.axiom_decl()) {
        visitAxiom_decl(axiomDecContext);
    }
    for (Var_declContext varDecContext : ctx.var_decl()) {
        visitVar_decl(varDecContext);
    }
    if (!procedures.containsKey("main")) {
        throw new ParsingException("Program shall have a main procedure");
    }
    Register next = programBuilder.getOrCreateRegister(threadCount, currentScope.getID() + ":" + "ptrMain", ARCH_PRECISION);
    pool.add(next, "main", -1);
    while (pool.canCreate()) {
        next = pool.next();
        String nextName = pool.getNameFromPtr(next);
        pool.addIntPtr(threadCount + 1, next);
        visitProc_decl(procedures.get(nextName), true, threadCallingValues.get(threadCount));
    }
    return programBuilder.build();
}
Also used : Register(com.dat3m.dartagnan.program.Register) ParsingException(com.dat3m.dartagnan.exception.ParsingException)

Example 9 with ParsingException

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

the class VisitorLitmusPPC method visitBranchCond.

@Override
public Object visitBranchCond(LitmusPPCParser.BranchCondContext ctx) {
    Label label = programBuilder.getOrCreateLabel(ctx.Label().getText());
    Event lastEvent = programBuilder.getLastEvent(mainThread);
    if (!(lastEvent instanceof Cmp)) {
        throw new ParsingException("Invalid syntax near " + ctx.getText());
    }
    Cmp cmp = (Cmp) lastEvent;
    Atom expr = new Atom(cmp.getLeft(), ctx.cond().op, cmp.getRight());
    return programBuilder.addChild(mainThread, EventFactory.newJump(expr, label));
}
Also used : Cmp(com.dat3m.dartagnan.program.event.core.Cmp) ParsingException(com.dat3m.dartagnan.exception.ParsingException) Label(com.dat3m.dartagnan.program.event.core.Label) Event(com.dat3m.dartagnan.program.event.core.Event) Atom(com.dat3m.dartagnan.expression.Atom)

Example 10 with ParsingException

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

the class SmackPredicates method smackPredicate.

public static Object smackPredicate(String name, List<Object> callParams) {
    String min = "0";
    String max = "1";
    IExpr var = (IExpr) callParams.get(0);
    if (name.startsWith("$tou.")) {
        switch(name.substring(name.lastIndexOf(".") + 1)) {
            case "i1":
                max = "1";
                break;
            case "i5":
                max = "32";
                break;
            case "i6":
                max = "64";
                break;
            case "i8":
                max = "256";
                break;
            case "i16":
                max = "65536";
                break;
            case "i24":
                max = "16777216";
                break;
            case "i32":
                max = "4294967296";
                break;
            case "i33":
                max = "8589934592";
                break;
            case "i40":
                max = "1099511627776";
                break;
            case "i48":
                max = "281474976710656";
                break;
            case "i56":
                max = "72057594037927936";
                break;
            case "i64":
                max = "18446744073709551616";
                break;
            case "i80":
                max = "1208925819614629174706176";
                break;
            case "i88":
                max = "309485009821345068724781056";
                break;
            case "i96":
                max = "79228162514264337593543950336";
                break;
            case "i128":
                max = "340282366920938463463374607431768211456";
                break;
            case "i160":
                max = "1461501637330902918203684832716283019655932542976";
                break;
            case "i256":
                max = "115792089237316195423570985008687907853269984665640564039457584007913129639936";
                break;
            default:
                throw new ParsingException("Function " + name + " has no implementation");
        }
    }
    if (name.startsWith("$tos.")) {
        switch(name.substring(name.lastIndexOf(".") + 1)) {
            case "i1":
                min = "-1";
                max = "1";
                break;
            case "i5":
                min = "-16";
                max = "16";
                break;
            case "i6":
                min = "-32";
                max = "32";
                break;
            case "i8":
                min = "-128";
                max = "128";
                break;
            case "i16":
                min = "-32768";
                max = "32768";
                break;
            case "i24":
                min = "-8388608";
                max = "8388608";
                break;
            case "i32":
                min = "-2147483648";
                max = "2147483648";
                break;
            case "i33":
                min = "-4294967296";
                max = "4294967296";
                break;
            case "i40":
                min = "-549755813888";
                max = "549755813888";
                break;
            case "i48":
                min = "-140737488355328";
                max = "140737488355328";
                break;
            case "i56":
                min = "-36028797018963968";
                max = "36028797018963968";
                break;
            case "i64":
                min = "-9223372036854775808";
                max = "9223372036854775808";
                break;
            case "i80":
                min = "-604462909807314587353088";
                max = "604462909807314587353088";
                break;
            case "i88":
                min = "-154742504910672534362390528";
                max = "154742504910672534362390528";
                break;
            case "i96":
                min = "-39614081257132168796771975168";
                max = "39614081257132168796771975168";
                break;
            case "i128":
                min = "-170141183460469231731687303715884105728";
                max = "170141183460469231731687303715884105728";
                break;
            case "i160":
                min = "-730750818665451459101842416358141509827966271488";
                max = "730750818665451459101842416358141509827966271488";
                break;
            case "i256":
                min = "-57896044618658097711785492504343953926634992332820282019728792003956564819968";
                max = "57896044618658097711785492504343953926634992332820282019728792003956564819968";
                break;
            default:
                throw new ParsingException("Function " + name + " has no implementation");
        }
    }
    IValue maxValue = new IValue(new BigInteger(max), var.getPrecision());
    Atom c1 = new Atom(var, GTE, new IValue(new BigInteger(min), var.getPrecision()));
    Atom c2 = new Atom(var, LTE, maxValue);
    BExprBin guard = new BExprBin(c1, AND, c2);
    IExpr fbranch = new IExprBin(var, MOD, maxValue);
    return new IfExpr(guard, var, fbranch);
}
Also used : ParsingException(com.dat3m.dartagnan.exception.ParsingException) BigInteger(java.math.BigInteger)

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