From 125f5733128899ecde931953fd8fa68b83b6654a Mon Sep 17 00:00:00 2001 From: Ahmed Harmouche Date: Fri, 20 Sep 2024 08:58:20 +0200 Subject: [PATCH] Array indexing with expressions --- lib/Parser/Parser.cpp | 4 +--- test/CodeGen/arrays.glsl | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/Parser/Parser.cpp b/lib/Parser/Parser.cpp index 9a1d4e4..f1af614 100644 --- a/lib/Parser/Parser.cpp +++ b/lib/Parser/Parser.cpp @@ -253,7 +253,7 @@ Parser::parseRhs(int exprPrec, std::unique_ptr lhs) { advanceToken(); - auto rhs = parsePrimaryExpression(); + auto rhs = parseUnaryExpression(); if (!rhs) return nullptr; @@ -763,8 +763,6 @@ std::unique_ptr Parser::parseForStatement() { return nullptr; } - advanceToken(); - auto inductionExp = parseConditionalExpression(); if (!inductionExp) { diff --git a/test/CodeGen/arrays.glsl b/test/CodeGen/arrays.glsl index f1d7a72..f8765c3 100644 --- a/test/CodeGen/arrays.glsl +++ b/test/CodeGen/arrays.glsl @@ -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, 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, 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]; }