Search in sources :

Example 11 with ParsingException

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

the class VisitorLitmusAArch64 method visitBranch.

@Override
public Object visitBranch(LitmusAArch64Parser.BranchContext ctx) {
    Label label = programBuilder.getOrCreateLabel(ctx.label().getText());
    if (ctx.branchCondition() == null) {
        return programBuilder.addChild(mainThread, EventFactory.newGoto(label));
    }
    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.branchCondition().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 12 with ParsingException

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

the class VisitorLitmusAssertions method visitAssertionList.

@Override
public AbstractAssert visitAssertionList(LitmusAssertionsParser.AssertionListContext ctx) {
    AbstractAssert ass = ctx.assertion().accept(this);
    if (ctx.AssertionNot() != null) {
        ass.setType(AbstractAssert.ASSERT_TYPE_NOT_EXISTS);
    } else if (ctx.AssertionExists() != null) {
        ass.setType(AbstractAssert.ASSERT_TYPE_EXISTS);
    } else if (ctx.AssertionForall() != null) {
        ass = new AssertNot(ass);
        ass.setType(AbstractAssert.ASSERT_TYPE_FORALL);
    } else if (ctx.AssertionFinal() != null) {
        ass.setType(AbstractAssert.ASSERT_TYPE_FINAL);
    } else {
        throw new ParsingException("Unrecognised assertion type");
    }
    return ass;
}
Also used : ParsingException(com.dat3m.dartagnan.exception.ParsingException)

Example 13 with ParsingException

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

the class VisitorLitmusC method visitGlobalDeclaratorArray.

@Override
public Object visitGlobalDeclaratorArray(LitmusCParser.GlobalDeclaratorArrayContext ctx) {
    String name = ctx.varName().getText();
    Integer size = ctx.DigitSequence() != null ? Integer.parseInt(ctx.DigitSequence().getText()) : null;
    if (ctx.initArray() == null && size != null && size > 0) {
        programBuilder.newObject(name, size);
        return null;
    }
    if (ctx.initArray() != null) {
        if (size == null || ctx.initArray().arrayElement().size() == size) {
            List<IConst> values = new ArrayList<>();
            for (LitmusCParser.ArrayElementContext elCtx : ctx.initArray().arrayElement()) {
                if (elCtx.constant() != null) {
                    values.add(new IValue(new BigInteger(elCtx.constant().getText()), ARCH_PRECISION));
                } else {
                    String varName = elCtx.varName().getText();
                    // see test/resources/arrays/ok/C-array-ok-17.litmus
                    MemoryObject object = programBuilder.getObject(varName);
                    if (object != null) {
                        values.add(object);
                    } else {
                        object = programBuilder.getOrNewObject(varName);
                        values.add(elCtx.Ast() == null ? object : object.getInitialValue(0));
                    }
                }
            }
            MemoryObject object = programBuilder.newObject(name, values.size());
            for (int i = 0; i < values.size(); i++) {
                object.setInitialValue(i, values.get(i));
            }
            return null;
        }
    }
    throw new ParsingException("Invalid syntax near " + ctx.getText());
}
Also used : BigInteger(java.math.BigInteger) LitmusCParser(com.dat3m.dartagnan.parsers.LitmusCParser) ParsingException(com.dat3m.dartagnan.exception.ParsingException) ArrayList(java.util.ArrayList) MemoryObject(com.dat3m.dartagnan.program.memory.MemoryObject) BigInteger(java.math.BigInteger)

Example 14 with ParsingException

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

the class VisitorLitmusC method visitNreAssignment.

@Override
public Object visitNreAssignment(LitmusCParser.NreAssignmentContext ctx) {
    ExprInterface variable = (ExprInterface) ctx.varName().accept(this);
    if (ctx.Ast() == null) {
        if (variable instanceof Register) {
            returnRegister = (Register) variable;
            ctx.re().accept(this);
            return null;
        }
        throw new ParsingException("Invalid syntax near " + ctx.getText());
    }
    ExprInterface value = (ExprInterface) ctx.re().accept(this);
    if (variable instanceof MemoryObject || variable instanceof Register) {
        Event event = EventFactory.newStore((IExpr) variable, value, "NA");
        return programBuilder.addChild(currentThread, event);
    }
    throw new ParsingException("Invalid syntax near " + ctx.getText());
}
Also used : Register(com.dat3m.dartagnan.program.Register) ParsingException(com.dat3m.dartagnan.exception.ParsingException) MemoryObject(com.dat3m.dartagnan.program.memory.MemoryObject) Event(com.dat3m.dartagnan.program.event.core.Event)

Example 15 with ParsingException

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

the class VisitorLitmusC method visitNreRegDeclaration.

@Override
public Object visitNreRegDeclaration(LitmusCParser.NreRegDeclarationContext ctx) {
    Register register = programBuilder.getRegister(scope, ctx.varName().getText());
    if (register == null) {
        register = programBuilder.getOrCreateRegister(scope, ctx.varName().getText(), ARCH_PRECISION);
        if (ctx.re() != null) {
            returnRegister = register;
            ctx.re().accept(this);
        }
        return null;
    }
    throw new ParsingException("Register " + ctx.varName().getText() + " is already initialised");
}
Also used : Register(com.dat3m.dartagnan.program.Register) ParsingException(com.dat3m.dartagnan.exception.ParsingException)

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