Skip to content

Commit

Permalink
Change parsing order to allow metadata to refer to program constants.
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasHaas committed Nov 11, 2024
1 parent 025e4a7 commit 8772b56
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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 &&
Expand Down Expand Up @@ -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<Expression>();
for (final GepIndexContext index : ctx.gepIndex()) {
offsets.add(visitTypeConst(index.typeConst()));
Expand Down

0 comments on commit 8772b56

Please sign in to comment.