From 8772b56229851600c0dde2aaa11221442127815c Mon Sep 17 00:00:00 2001 From: Thomas Haas Date: Mon, 11 Nov 2024 14:04:45 +0100 Subject: [PATCH] Change parsing order to allow metadata to refer to program constants. --- .../parsers/program/visitors/VisitorLlvm.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/VisitorLlvm.java b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/VisitorLlvm.java index 2043c3c2a9..ca6ffe4180 100644 --- a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/VisitorLlvm.java +++ b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/VisitorLlvm.java @@ -72,12 +72,8 @@ public Program buildProgram() { @Override public Expression visitCompilationUnit(CompilationUnitContext ctx) { - // Create the metadata mapping beforehand, so that instructions can get all attachments. - // Also parse all type definitions. + // Define types for (final TopLevelEntityContext entity : ctx.topLevelEntity()) { - if (entity.metadataDef() != null) { - entity.accept(this); - } if (entity.typeDef() != null) { entity.accept(this); } @@ -96,14 +92,21 @@ public Expression visitCompilationUnit(CompilationUnitContext ctx) { } } - // Parse global definitions after declarations. + // Create the metadata mapping beforehand, so that instructions can get all attachments. + for (final TopLevelEntityContext entity : ctx.topLevelEntity()) { + if (entity.metadataDef() != null) { + entity.accept(this); + } + } + + // Parse global definitions. for (final TopLevelEntityContext entity : ctx.topLevelEntity()) { if (entity.globalDef() != null) { visitGlobalDef(entity.globalDef()); } } - // Parse definitions + // Parse remaining definitions (~ function bodies). for (final TopLevelEntityContext entity : ctx.topLevelEntity()) { if (entity.metadataDef() == null && entity.globalDef() == null && @@ -1018,6 +1021,11 @@ public Expression visitAddrSpaceCastExpr(AddrSpaceCastExprContext ctx) { public Expression visitGetElementPtrExpr(GetElementPtrExprContext ctx) { final Type indexingType = parseType(ctx.type()); final Expression base = visitTypeConst(ctx.typeConst()); + if (base == null) { + final String typeConst = ctx.typeConst().getText(); + final String rep = ctx.getText(); + int i = 5; + } final var offsets = new ArrayList(); for (final GepIndexContext index : ctx.gepIndex()) { offsets.add(visitTypeConst(index.typeConst()));