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));
}
}
}
Aggregations