Search in sources :

Example 1 with ParsingException

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

the class VisitorBase method visitAxiomDefinition.

@Override
public Object visitAxiomDefinition(CatParser.AxiomDefinitionContext ctx) {
    try {
        Relation r = ctx.e.accept(relationVisitor);
        if (r == null) {
            throw new ParsingException(ctx.getText());
        }
        Constructor<?> constructor = ctx.cls.getConstructor(Relation.class);
        wmm.addAxiom((Axiom) constructor.newInstance(r));
    } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
        throw new ParsingException(ctx.getText());
    }
    return null;
}
Also used : RecursiveRelation(com.dat3m.dartagnan.wmm.relation.RecursiveRelation) Relation(com.dat3m.dartagnan.wmm.relation.Relation) ParsingException(com.dat3m.dartagnan.exception.ParsingException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with ParsingException

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

the class VisitorBase method visitLetRecAndDefinition.

@Override
public Object visitLetRecAndDefinition(CatParser.LetRecAndDefinitionContext ctx) {
    RecursiveRelation rRecursive = (RecursiveRelation) relationRepository.getRelation(RecursiveRelation.class, ctx.n.getText());
    Relation rConcrete = ctx.e.accept(relationVisitor);
    if (rRecursive == null || rConcrete == null) {
        throw new ParsingException(ctx.getText());
    }
    rRecursive.setConcreteRelation(rConcrete);
    recursiveGroup.add(rRecursive);
    return null;
}
Also used : RecursiveRelation(com.dat3m.dartagnan.wmm.relation.RecursiveRelation) Relation(com.dat3m.dartagnan.wmm.relation.Relation) RecursiveRelation(com.dat3m.dartagnan.wmm.relation.RecursiveRelation) ParsingException(com.dat3m.dartagnan.exception.ParsingException)

Example 3 with ParsingException

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

the class VisitorBase method visitLetRecDefinition.

@Override
public Object visitLetRecDefinition(CatParser.LetRecDefinitionContext ctx) {
    recursiveGroup = new HashSet<>();
    recursiveDef = true;
    RecursiveRelation rRecursive = (RecursiveRelation) relationRepository.getRelation(RecursiveRelation.class, ctx.n.getText());
    Relation rConcrete = ctx.e.accept(relationVisitor);
    if (rRecursive == null || rConcrete == null) {
        throw new ParsingException(ctx.getText());
    }
    rRecursive.setConcreteRelation(rConcrete);
    recursiveGroup.add(rRecursive);
    for (CatParser.LetRecAndDefinitionContext c : ctx.letRecAndDefinition()) {
        c.accept(this);
    }
    wmm.addRecursiveGroup(recursiveGroup);
    recursiveDef = false;
    return null;
}
Also used : RecursiveRelation(com.dat3m.dartagnan.wmm.relation.RecursiveRelation) Relation(com.dat3m.dartagnan.wmm.relation.Relation) RecursiveRelation(com.dat3m.dartagnan.wmm.relation.RecursiveRelation) ParsingException(com.dat3m.dartagnan.exception.ParsingException) CatParser(com.dat3m.dartagnan.parsers.CatParser)

Example 4 with ParsingException

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

the class ProgramParser method parse.

public Program parse(String raw, String format) throws Exception {
    switch(format) {
        case "c":
        case "i":
            File CFile = File.createTempFile("dat3m", ".c");
            CFile.deleteOnExit();
            String name = CFile.getName().substring(0, CFile.getName().lastIndexOf('.'));
            try (FileWriter writer = new FileWriter(CFile)) {
                writer.write(raw);
            }
            compileWithClang(CFile);
            compileWithSmack(CFile);
            File BplFile = new File(System.getenv("DAT3M_HOME") + "/output/" + name + ".bpl");
            BplFile.deleteOnExit();
            Program p = new ProgramParser().parse(BplFile);
            CFile.delete();
            BplFile.delete();
            return p;
        case "bpl":
            return new ParserBoogie().parse(CharStreams.fromString(raw));
        case "litmus":
            return getConcreteLitmusParser(raw.toUpperCase()).parse(CharStreams.fromString(raw));
    }
    throw new ParsingException("Unknown input file type");
}
Also used : Program(com.dat3m.dartagnan.program.Program) ParsingException(com.dat3m.dartagnan.exception.ParsingException)

Example 5 with ParsingException

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

the class VisitorBoogie method preProc_decl.

private void preProc_decl(Proc_declContext ctx) {
    String name = ctx.proc_sign().Ident().getText();
    if (procedures.containsKey(name)) {
        throw new ParsingException("Procedure " + name + " is already defined");
    }
    if (name.equals("main") && ctx.proc_sign().proc_sign_in() != null) {
        threadCallingValues.put(threadCount, new ArrayList<>());
        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()) {
                String type = atiwC.typed_idents_where().typed_idents().type().getText();
                int precision = type.contains("bv") ? Integer.parseInt(type.split("bv")[1]) : ARCH_PRECISION;
                threadCallingValues.get(threadCount).add(programBuilder.getOrCreateRegister(threadCount, currentScope.getID() + ":" + ident.getText(), precision));
            }
        }
    }
    procedures.put(name, ctx);
}
Also used : ParsingException(com.dat3m.dartagnan.exception.ParsingException) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

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