Search in sources :

Example 1 with Scope

use of com.dat3m.dartagnan.parsers.program.boogie.Scope 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)

Aggregations

ParsingException (com.dat3m.dartagnan.exception.ParsingException)1 Scope (com.dat3m.dartagnan.parsers.program.boogie.Scope)1 Register (com.dat3m.dartagnan.program.Register)1 Label (com.dat3m.dartagnan.program.event.core.Label)1 MemoryObject (com.dat3m.dartagnan.program.memory.MemoryObject)1 ParseTree (org.antlr.v4.runtime.tree.ParseTree)1