[WHLSL] Trivial clean-up of the MSL code generated
authorrmorisset@apple.com <rmorisset@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Aug 2019 17:49:38 +0000 (17:49 +0000)
committerrmorisset@apple.com <rmorisset@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Aug 2019 17:49:38 +0000 (17:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=200525

Reviewed by Darin Adler.

Emit simpler code for ternary expressions
Remove duplicate {} around functions

No new tests as it is covered by the existing ones.

* Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp:
(WebCore::WHLSL::Metal::FunctionDefinitionWriter::visit):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248729 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp

index e82c619..4a140e8 100644 (file)
@@ -1,3 +1,18 @@
+2019-08-15  Robin Morisset  <rmorisset@apple.com>
+
+        [WHLSL] Trivial clean-up of the MSL code generated
+        https://bugs.webkit.org/show_bug.cgi?id=200525
+
+        Reviewed by Darin Adler.
+
+        Emit simpler code for ternary expressions
+        Remove duplicate {} around functions
+
+        No new tests as it is covered by the existing ones.
+
+        * Modules/webgpu/WHLSL/Metal/WHLSLFunctionWriter.cpp:
+        (WebCore::WHLSL::Metal::FunctionDefinitionWriter::visit):
+
 2019-08-15  Youenn Fablet  <youenn@apple.com>
 
         Always create a Document with a valid SessionID
index 82548b8..e500f61 100644 (file)
@@ -247,10 +247,10 @@ void FunctionDefinitionWriter::visit(AST::FunctionDefinition& functionDefinition
             ASSERT_UNUSED(addResult, addResult.isNewEntry);
             m_stringBuilder.flexibleAppend(m_typeNamer.mangledNameForType(*parameter->type()), ' ', parameterName);
         }
-        m_stringBuilder.append(") {\n");
+        m_stringBuilder.append(")\n");
         checkErrorAndVisit(functionDefinition.block());
         ASSERT(m_stack.isEmpty());
-        m_stringBuilder.append("}\n");
+        m_stringBuilder.append('\n');
     }
 }
 
@@ -679,22 +679,13 @@ void FunctionDefinitionWriter::visit(AST::TernaryExpression& ternaryExpression)
 {
     checkErrorAndVisit(ternaryExpression.predicate());
     auto check = takeLastValue();
-
-    auto variableName = generateNextVariableName();
-    m_stringBuilder.flexibleAppend(
-        m_typeNamer.mangledNameForType(ternaryExpression.resolvedType()), ' ', variableName, ";\n"
-        "if (", check, ") {\n"
-    );
     checkErrorAndVisit(ternaryExpression.bodyExpression());
-    m_stringBuilder.flexibleAppend(
-        variableName, " = ", takeLastValue(), ";\n"
-        "} else {\n"
-    );
+    auto body = takeLastValue();
     checkErrorAndVisit(ternaryExpression.elseExpression());
-    m_stringBuilder.flexibleAppend(
-        variableName, " = ", takeLastValue(), ";\n"
-        "}\n"
-    );
+    auto elseBody = takeLastValue();
+
+    auto variableName = generateNextVariableName();
+    m_stringBuilder.flexibleAppend(m_typeNamer.mangledNameForType(ternaryExpression.resolvedType()), ' ', variableName, " = ", check, " ? ", body, " : ", elseBody, ";\n");
     appendRightValue(ternaryExpression, variableName);
 }