Skip to content

Commit

Permalink
Array indexing with expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
wpmed92 committed Sep 20, 2024
1 parent 5ccec51 commit 125f573
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/Parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ Parser::parseRhs(int exprPrec, std::unique_ptr<ast::Expression> lhs) {

advanceToken();

auto rhs = parsePrimaryExpression();
auto rhs = parseUnaryExpression();

if (!rhs)
return nullptr;
Expand Down Expand Up @@ -763,8 +763,6 @@ std::unique_ptr<ForStatement> Parser::parseForStatement() {
return nullptr;
}

advanceToken();

auto inductionExp = parseConditionalExpression();

if (!inductionExp) {
Expand Down
15 changes: 15 additions & 0 deletions test/CodeGen/arrays.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,19 @@ void main() {
// CHECK-NEXT: %cst_f32_16 = spirv.Constant 1.000000e+00 : f32
// CHECK-NEXT: spirv.Store "Function" %22, %cst_f32_16 : f32
multiArr[0][1] = 1.0;

// CHECK: %cst2_si32_17 = spirv.Constant 2 : si32
// CHECK-NEXT: %23 = spirv.Load "Function" %12 : si32
// CHECK-NEXT: %24 = spirv.IMul %23, %cst2_si32_17 : si32
// CHECK-NEXT: %cst1_si32_18 = spirv.Constant 1 : si32
// CHECK-NEXT: %25 = spirv.ISub %24, %cst1_si32_18 : si32
// CHECK-NEXT: %26 = spirv.AccessChain %1[%25] : !spirv.ptr<!spirv.array<3 x f32>, Function>, si32
// CHECK-NEXT: %cst4_si32 = spirv.Constant 4 : si32
// CHECK-NEXT: %27 = spirv.Load "Function" %12 : si32
// CHECK-NEXT: %28 = spirv.IMul %27, %cst4_si32 : si32
// CHECK-NEXT: %29 = spirv.AccessChain %1[%28] : !spirv.ptr<!spirv.array<3 x f32>, Function>, si32
// CHECK-NEXT: %30 = spirv.Load "Function" %29 : f32
// CHECK-NEXT: %31 = spirv.Load "Function" %26 : f32
// CHECK-NEXT: %32 = spirv.FAdd %31, %30 : f32
float expr = myArray[(varIdx*2) - 1] + myArray[varIdx * 4];
}

0 comments on commit 125f573

Please sign in to comment.