WebKit Bugzilla
Attachment 358883 Details for
Bug 193007
: [WHLSL] Implement the NameResolver
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-193007-20190111002404.patch (text/plain), 32.69 KB, created by
Myles C. Maxfield
on 2019-01-11 00:24:05 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Myles C. Maxfield
Created:
2019-01-11 00:24:05 PST
Size:
32.69 KB
patch
obsolete
>Subversion Revision: 239861 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 76b62769033d12153a576529ab23321418a49b44..3fea41a17e7aba34a92015b47d3adbbb3c95ce9d 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,34 @@ >+2019-01-11 Myles C. Maxfield <mmaxfield@apple.com> >+ >+ [WHLSL] Implement the NameResolver >+ https://bugs.webkit.org/show_bug.cgi?id=193007 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ No new tests (OOPS!). >+ >+ * Modules/webgpu/WHLSL/AST/WHLSLSpecializationConstantSemantic.cpp: >+ * Modules/webgpu/WHLSL/WHLSLNameContext.cpp: Added. >+ (WebCore::WHLSL::NameContext::NameContext): >+ (WebCore::WHLSL::NameContext::add): >+ (WebCore::WHLSL::NameContext::getTypes): >+ (WebCore::WHLSL::NameContext::getFunctions): >+ (WebCore::WHLSL::NameContext::getVariable): >+ (WebCore::WHLSL::NameContext::exists): >+ * Modules/webgpu/WHLSL/WHLSLNameContext.h: Copied from Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLSpecializationConstantSemantic.cpp. >+ * Modules/webgpu/WHLSL/WHLSLNameResolver.cpp: Added. >+ (WebCore::WHLSL::NameResolver::NameResolver): >+ (WebCore::WHLSL::NameResolver::visit): >+ (WebCore::WHLSL::resolveNamesInTypes): >+ (WebCore::WHLSL::resolveNamesInFunctions): >+ * Modules/webgpu/WHLSL/WHLSLNameResolver.h: Copied from Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLSpecializationConstantSemantic.cpp. >+ (WebCore::WHLSL::NameResolver::setCurrentFunctionDefinition): >+ * Modules/webgpu/WHLSL/WHLSLProgram.h: >+ (WebCore::WHLSL::Program::append): >+ (WebCore::WHLSL::Program::nameContext): >+ * Sources.txt: >+ * WebCore.xcodeproj/project.pbxproj: >+ > 2019-01-10 Myles C. Maxfield <mmaxfield@apple.com> > > [WHLSL] Include the standard library >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLSpecializationConstantSemantic.cpp b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLSpecializationConstantSemantic.cpp >index d7f4de7131e5ea1c87d16aa2c2fefaabe617a78f..421c793c922bbf649019aa390759e533ab4068cd 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLSpecializationConstantSemantic.cpp >+++ b/Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLSpecializationConstantSemantic.cpp >@@ -28,6 +28,7 @@ > > #if ENABLE(WEBGPU) > >+#include "WHLSLNativeTypeDeclaration.h" > #include "WHLSLTypeReference.h" > > namespace WebCore { >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameContext.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameContext.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..2d8b11c51279f18c05c21282d8e733cbc41510e7 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameContext.cpp >@@ -0,0 +1,163 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#if ENABLE(WEBGPU) >+ >+#include "config.h" >+#include "WHLSLNameContext.h" >+ >+#include "WHLSLEnumerationDefinition.h" >+#include "WHLSLFunctionDefinition.h" >+#include "WHLSLNativeFunctionDeclaration.h" >+#include "WHLSLNativeTypeDeclaration.h" >+#include "WHLSLStructureDefinition.h" >+#include "WHLSLTypeDefinition.h" >+#include "WHLSLVariableDeclaration.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+NameContext::NameContext(NameContext* parent) >+ : m_parent(parent) >+{ >+} >+ >+bool NameContext::add(AST::TypeDefinition& typeDefinition) >+{ >+ if (exists(typeDefinition.name())) >+ return false; >+ auto result = m_types.add(typeDefinition.name(), Vector<std::reference_wrapper<AST::NamedType>, 1>()); >+ if (!result.isNewEntry) >+ return false; >+ result.iterator->value.append(typeDefinition); >+ return true; >+} >+ >+bool NameContext::add(AST::StructureDefinition& structureDefinition) >+{ >+ if (exists(structureDefinition.name())) >+ return false; >+ auto result = m_types.add(structureDefinition.name(), Vector<std::reference_wrapper<AST::NamedType>, 1>()); >+ if (!result.isNewEntry) >+ return false; >+ result.iterator->value.append(structureDefinition); >+ return true; >+} >+ >+bool NameContext::add(AST::EnumerationDefinition& enumerationDefinition) >+{ >+ if (exists(enumerationDefinition.name())) >+ return false; >+ auto result = m_types.add(enumerationDefinition.name(), Vector<std::reference_wrapper<AST::NamedType>, 1>()); >+ if (!result.isNewEntry) >+ return false; >+ result.iterator->value.append(enumerationDefinition); >+ return true; >+} >+ >+bool NameContext::add(AST::FunctionDefinition& functionDefinition) >+{ >+ if (m_types.find(functionDefinition.name()) != m_types.end() >+ || m_variables.find(functionDefinition.name()) != m_variables.end()) >+ return false; >+ auto result = m_functions.add(functionDefinition.name(), Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>()); >+ result.iterator->value.append(functionDefinition); >+ return true; >+} >+ >+bool NameContext::add(AST::NativeFunctionDeclaration& nativeFunctionDeclaration) >+{ >+ if (m_types.find(nativeFunctionDeclaration.name()) != m_types.end() >+ || m_variables.find(nativeFunctionDeclaration.name()) != m_variables.end()) >+ return false; >+ auto result = m_functions.add(nativeFunctionDeclaration.name(), Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>()); >+ result.iterator->value.append(nativeFunctionDeclaration); >+ return true; >+} >+ >+bool NameContext::add(AST::NativeTypeDeclaration& nativeTypeDeclaration) >+{ >+ if (m_functions.find(nativeTypeDeclaration.name()) != m_functions.end() >+ || m_variables.find(nativeTypeDeclaration.name()) != m_variables.end()) >+ return false; >+ auto result = m_types.add(nativeTypeDeclaration.name(), Vector<std::reference_wrapper<AST::NamedType>, 1>()); >+ result.iterator->value.append(nativeTypeDeclaration); >+ return true; >+} >+ >+bool NameContext::add(AST::VariableDeclaration& variableDeclaration) >+{ >+ if (exists(variableDeclaration.name())) >+ return false; >+ auto result = m_variables.add(String(variableDeclaration.name()), &variableDeclaration); >+ return result.isNewEntry; >+} >+ >+Vector<std::reference_wrapper<AST::NamedType>, 1>* NameContext::getTypes(const String& name) >+{ >+ auto iterator = m_types.find(name); >+ if (iterator == m_types.end()) { >+ if (m_parent) >+ return m_parent->getTypes(name); >+ return nullptr; >+ } >+ return &iterator->value; >+} >+ >+Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>* NameContext::getFunctions(const String& name) >+{ >+ auto iterator = m_functions.find(name); >+ if (iterator == m_functions.end()) { >+ if (m_parent) >+ return m_parent->getFunctions(name); >+ return nullptr; >+ } >+ return &iterator->value; >+} >+ >+AST::VariableDeclaration* NameContext::getVariable(const String& name) >+{ >+ auto iterator = m_variables.find(name); >+ if (iterator == m_variables.end()) { >+ if (m_parent) >+ return m_parent->getVariable(name); >+ return nullptr; >+ } >+ return iterator->value; >+} >+ >+bool NameContext::exists(String& name) >+{ >+ return m_types.find(name) != m_types.end() >+ || m_functions.find(name) != m_functions.end() >+ || m_variables.find(name) != m_variables.end(); >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameContext.h b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameContext.h >new file mode 100644 >index 0000000000000000000000000000000000000000..a04878ae7e9f1d83e5d592c2fd752bedc90fa9cb >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameContext.h >@@ -0,0 +1,82 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#if ENABLE(WEBGPU) >+ >+#include <functional> >+#include <wtf/HashMap.h> >+#include <wtf/Vector.h> >+#include <wtf/text/WTFString.h> >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+namespace AST { >+ >+class NamedType; >+class FunctionDeclaration; >+class TypeDefinition; >+class StructureDefinition; >+class EnumerationDefinition; >+class FunctionDefinition; >+class NativeFunctionDeclaration; >+class NativeTypeDeclaration; >+class VariableDeclaration; >+ >+} >+ >+class NameContext { >+public: >+ NameContext(NameContext* parent = nullptr); >+ >+ bool add(AST::TypeDefinition&); >+ bool add(AST::StructureDefinition&); >+ bool add(AST::EnumerationDefinition&); >+ bool add(AST::FunctionDefinition&); >+ bool add(AST::NativeFunctionDeclaration&); >+ bool add(AST::NativeTypeDeclaration&); >+ bool add(AST::VariableDeclaration&); >+ >+ Vector<std::reference_wrapper<AST::NamedType>, 1>* getTypes(const String&); >+ Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>* getFunctions(const String&); >+ AST::VariableDeclaration* getVariable(const String&); >+ >+private: >+ bool exists(String&); >+ >+ HashMap<String, Vector<std::reference_wrapper<AST::NamedType>, 1>> m_types; >+ HashMap<String, Vector<std::reference_wrapper<AST::FunctionDeclaration>, 1>> m_functions; >+ HashMap<String, AST::VariableDeclaration*> m_variables; >+ NameContext* m_parent; >+}; >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..ba76026a6319d219077461f7d2ab621a6cb976dc >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.cpp >@@ -0,0 +1,280 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#if ENABLE(WEBGPU) >+ >+#include "config.h" >+#include "WHLSLNameResolver.h" >+ >+#include "WHLSLCallExpression.h" >+#include "WHLSLDoWhileLoop.h" >+#include "WHLSLDotExpression.h" >+#include "WHLSLEnumerationDefinition.h" >+#include "WHLSLEnumerationMemberLiteral.h" >+#include "WHLSLForLoop.h" >+#include "WHLSLFunctionDefinition.h" >+#include "WHLSLIfStatement.h" >+#include "WHLSLNameContext.h" >+#include "WHLSLProgram.h" >+#include "WHLSLPropertyAccessExpression.h" >+#include "WHLSLResolveOverloadImpl.h" >+#include "WHLSLReturn.h" >+#include "WHLSLTypeReference.h" >+#include "WHLSLVariableDeclaration.h" >+#include "WHLSLVariableReference.h" >+#include "WHLSLWhileLoop.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+NameResolver::NameResolver(NameContext& nameContext) >+ : m_nameContext(nameContext) >+{ >+} >+ >+void NameResolver::visit(AST::TypeReference& typeReference) >+{ >+ checkErrorAndVisit(typeReference); >+ if (typeReference.resolvedType()) >+ return; >+ >+ auto* candidates = m_nameContext.getTypes(typeReference.name()); >+ if (candidates == nullptr) { >+ setError(); >+ return; >+ } >+ if (auto result = resolveTypeOverloadImpl(*candidates, typeReference.typeArguments())) >+ typeReference.setResolvedType(*result); >+ else { >+ setError(); >+ return; >+ } >+} >+ >+void NameResolver::visit(AST::FunctionDefinition& functionDefinition) >+{ >+ NameContext newNameContext(&m_nameContext); >+ NameResolver newNameResolver(newNameContext); >+ checkErrorAndVisit(functionDefinition.type()); >+ for (auto& parameter : functionDefinition.parameters()) { >+ newNameResolver.checkErrorAndVisit(parameter); >+ auto success = newNameContext.add(parameter); >+ if (!success) { >+ setError(); >+ return; >+ } >+ } >+ newNameResolver.checkErrorAndVisit(functionDefinition.block()); >+} >+ >+void NameResolver::visit(AST::Block& block) >+{ >+ NameContext nameContext(&m_nameContext); >+ NameResolver(nameContext).checkErrorAndVisit(block); >+} >+ >+void NameResolver::visit(AST::IfStatement& ifStatement) >+{ >+ checkErrorAndVisit(ifStatement.conditional()); >+ NameContext nameContext(&m_nameContext); >+ NameResolver(nameContext).checkErrorAndVisit(ifStatement.body()); >+ if (ifStatement.elseBody()) { >+ NameContext nameContext(&m_nameContext); >+ NameResolver(nameContext).checkErrorAndVisit(static_cast<AST::Statement&>(*ifStatement.elseBody())); >+ } >+} >+ >+void NameResolver::visit(AST::WhileLoop& whileLoop) >+{ >+ checkErrorAndVisit(whileLoop.conditional()); >+ NameContext nameContext(&m_nameContext); >+ NameResolver(nameContext).checkErrorAndVisit(whileLoop.body()); >+} >+ >+void NameResolver::visit(AST::DoWhileLoop& whileLoop) >+{ >+ NameContext nameContext(&m_nameContext); >+ NameResolver(nameContext).checkErrorAndVisit(whileLoop.body()); >+ checkErrorAndVisit(whileLoop.conditional()); >+} >+ >+void NameResolver::visit(AST::ForLoop& forLoop) >+{ >+ NameContext nameContext(&m_nameContext); >+ NameResolver(nameContext).checkErrorAndVisit(forLoop); >+} >+ >+void NameResolver::visit(AST::VariableDeclaration& variableDeclaration) >+{ >+ m_nameContext.add(variableDeclaration); >+ checkErrorAndVisit(variableDeclaration); >+} >+ >+void NameResolver::visit(AST::VariableReference& variableReference) >+{ >+ if (variableReference.variable()) >+ return; >+ >+ if (auto* variable = m_nameContext.getVariable(variableReference.name())) >+ variableReference.setVariable(*variable); >+ else { >+ setError(); >+ return; >+ } >+} >+ >+void NameResolver::visit(AST::Return& returnStatement) >+{ >+ ASSERT(m_currentFunction); >+ returnStatement.setFunction(m_currentFunction); >+ checkErrorAndVisit(returnStatement); >+} >+ >+void NameResolver::visit(AST::PropertyAccessExpression& propertyAccessExpression) >+{ >+ if (auto* getFunctions = m_nameContext.getFunctions(propertyAccessExpression.getFunctionName())) >+ propertyAccessExpression.setPossibleGetOverloads(*getFunctions); >+ if (auto* setFunctions = m_nameContext.getFunctions(propertyAccessExpression.setFunctionName())) >+ propertyAccessExpression.setPossibleSetOverloads(*setFunctions); >+ if (auto* andFunctions = m_nameContext.getFunctions(propertyAccessExpression.andFunctionName())) >+ propertyAccessExpression.setPossibleAndOverloads(*andFunctions); >+ checkErrorAndVisit(propertyAccessExpression); >+} >+ >+void NameResolver::visit(AST::DotExpression& dotExpression) >+{ >+ if (is<AST::VariableReference>(dotExpression.base())) { >+ if (auto enumerationTypes = m_nameContext.getTypes(downcast<AST::VariableReference>(dotExpression.base()).name())) { >+ ASSERT(enumerationTypes->size() == 1); >+ AST::NamedType& type = (*enumerationTypes)[0]; >+ if (is<AST::EnumerationDefinition>(type)) { >+ AST::EnumerationDefinition& enumerationDefinition = downcast<AST::EnumerationDefinition>(type); >+ if (auto* member = enumerationDefinition.memberByName(dotExpression.fieldName())) { >+ static_assert(sizeof(AST::EnumerationMemberLiteral) <= sizeof(AST::DotExpression), "Dot expressions need to be able to become EnumerationMemberLiterals without updating backreferences"); >+ Lexer::Token origin = dotExpression.origin(); >+ // FIXME: Perhaps do this with variants or a Rewriter instead. >+ dotExpression.~DotExpression(); >+ new (&dotExpression) AST::EnumerationMemberLiteral(WTFMove(origin), *member); >+ return; >+ } >+ setError(); >+ return; >+ } >+ } >+ } >+ >+ checkErrorAndVisit(dotExpression); >+} >+ >+void NameResolver::visit(AST::CallExpression& callExpression) >+{ >+ if (!callExpression.hasOverloads()) { >+ if (auto* functions = m_nameContext.getFunctions(callExpression.name())) >+ callExpression.setOverloads(*functions); >+ else { >+ if (auto* types = m_nameContext.getTypes(callExpression.name())) { >+ if (types->size() == 1) { >+ if (auto* functions = m_nameContext.getFunctions(String("operator cast", String::ConstructFromLiteral))) { >+ callExpression.setCastData((*types)[0].get()); >+ callExpression.setOverloads(*functions); >+ } >+ } >+ } >+ } >+ } >+ if (!callExpression.hasOverloads()) { >+ setError(); >+ return; >+ } >+ checkErrorAndVisit(callExpression); >+} >+ >+void NameResolver::visit(AST::ConstantExpressionEnumerationMemberReference& constantExpressionEnumerationMemberReference) >+{ >+ if (auto enumerationTypes = m_nameContext.getTypes(constantExpressionEnumerationMemberReference.left())) { >+ ASSERT(enumerationTypes->size() == 1); >+ AST::NamedType& type = (*enumerationTypes)[0]; >+ if (is<AST::EnumerationDefinition>(type)) { >+ AST::EnumerationDefinition& enumerationDefinition = downcast<AST::EnumerationDefinition>(type); >+ if (auto* member = enumerationDefinition.memberByName(constantExpressionEnumerationMemberReference.right())) { >+ constantExpressionEnumerationMemberReference.setEnumerationMember(enumerationDefinition, *member); >+ return; >+ } >+ } >+ } >+ >+ setError(); >+} >+ >+// FIXME: Make sure all the names have been resolved. >+ >+bool resolveNamesInTypes(Program& program, NameResolver& nameResolver) >+{ >+ for (auto& typeDefinition : program.typeDefinitions()) { >+ nameResolver.checkErrorAndVisit(static_cast<AST::TypeDefinition&>(typeDefinition)); >+ if (nameResolver.error()) >+ return false; >+ } >+ for (auto& structureDefinition : program.structureDefinitions()) { >+ nameResolver.checkErrorAndVisit(static_cast<AST::StructureDefinition&>(structureDefinition)); >+ if (nameResolver.error()) >+ return false; >+ } >+ for (auto& enumerationDefinition : program.enumerationDefinitions()) { >+ nameResolver.checkErrorAndVisit(static_cast<AST::EnumerationDefinition&>(enumerationDefinition)); >+ if (nameResolver.error()) >+ return false; >+ } >+ for (auto& nativeTypeDeclaration : program.nativeTypeDeclarations()) { >+ nameResolver.checkErrorAndVisit(static_cast<AST::NativeTypeDeclaration&>(nativeTypeDeclaration)); >+ if (nameResolver.error()) >+ return false; >+ } >+ return true; >+} >+ >+bool resolveNamesInFunctions(Program& program, NameResolver& nameResolver) >+{ >+ for (auto& functionDefinition : program.functionDefinitions()) { >+ nameResolver.setCurrentFunctionDefinition(&static_cast<AST::FunctionDefinition&>(functionDefinition)); >+ nameResolver.checkErrorAndVisit(static_cast<AST::FunctionDefinition&>(functionDefinition)); >+ if (nameResolver.error()) >+ return false; >+ } >+ nameResolver.setCurrentFunctionDefinition(nullptr); >+ for (auto& nativeFunctionDeclaration : program.nativeFunctionDeclarations()) { >+ nameResolver.checkErrorAndVisit(static_cast<AST::FunctionDeclaration&>(nativeFunctionDeclaration)); >+ if (nameResolver.error()) >+ return false; >+ } >+ return true; >+} >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h >new file mode 100644 >index 0000000000000000000000000000000000000000..c72e08e0621067dbe190ca04068a9e9a70bfdcf1 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLNameResolver.h >@@ -0,0 +1,78 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#pragma once >+ >+#if ENABLE(WEBGPU) >+ >+#include "WHLSLNameContext.h" >+#include "WHLSLVisitor.h" >+ >+namespace WebCore { >+ >+namespace WHLSL { >+ >+class Program; >+ >+class NameResolver : public Visitor { >+public: >+ NameResolver(NameContext&); >+ >+ virtual ~NameResolver() = default; >+ >+ void visit(AST::FunctionDefinition&) override; >+ >+ void setCurrentFunctionDefinition(AST::FunctionDefinition* functionDefinition) >+ { >+ m_currentFunction = functionDefinition; >+ } >+ >+private: >+ void visit(AST::TypeReference&) override; >+ void visit(AST::Block&) override; >+ void visit(AST::IfStatement&) override; >+ void visit(AST::WhileLoop&) override; >+ void visit(AST::DoWhileLoop&) override; >+ void visit(AST::ForLoop&) override; >+ void visit(AST::VariableDeclaration&) override; >+ void visit(AST::VariableReference&) override; >+ void visit(AST::Return&) override; >+ void visit(AST::PropertyAccessExpression&) override; >+ void visit(AST::DotExpression&) override; >+ void visit(AST::CallExpression&) override; >+ void visit(AST::ConstantExpressionEnumerationMemberReference&) override; >+ >+ NameContext m_nameContext; >+ AST::FunctionDefinition* m_currentFunction { nullptr }; >+}; >+ >+bool resolveNamesInTypes(Program&, NameResolver&); >+bool resolveNamesInFunctions(Program&, NameResolver&); >+ >+} >+ >+} >+ >+#endif >diff --git a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLProgram.h b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLProgram.h >index a69e843c10fd7cca319553750227aabeccfda79b..8bcea6b047897a629720bef943b889d4c104752d 100644 >--- a/Source/WebCore/Modules/webgpu/WHLSL/WHLSLProgram.h >+++ b/Source/WebCore/Modules/webgpu/WHLSL/WHLSLProgram.h >@@ -47,39 +47,40 @@ public: > bool append(AST::TypeDefinition&& typeDefinition) > { > m_typeDefinitions.append(makeUniqueRef<AST::TypeDefinition>(WTFMove(typeDefinition))); >- return true; >+ return m_nameContext.add(static_cast<AST::TypeDefinition&>(m_typeDefinitions.last())); > } > > bool append(AST::StructureDefinition&& structureDefinition) > { > m_structureDefinitions.append(makeUniqueRef<AST::StructureDefinition>(WTFMove(structureDefinition))); >- return true; >+ return m_nameContext.add(static_cast<AST::StructureDefinition&>(m_structureDefinitions.last())); > } > > bool append(AST::EnumerationDefinition&& enumerationDefinition) > { > m_enumerationDefinitions.append(makeUniqueRef<AST::EnumerationDefinition>(WTFMove(enumerationDefinition))); >- return true; >+ return m_nameContext.add(static_cast<AST::EnumerationDefinition&>(m_enumerationDefinitions.last())); > } > > bool append(AST::FunctionDefinition&& functionDefinition) > { > m_functionDefinitions.append(makeUniqueRef<AST::FunctionDefinition>(WTFMove(functionDefinition))); >- return true; >+ return m_nameContext.add(static_cast<AST::FunctionDefinition&>(m_functionDefinitions.last())); > } > > bool append(AST::NativeFunctionDeclaration&& nativeFunctionDeclaration) > { > m_nativeFunctionDeclarations.append(makeUniqueRef<AST::NativeFunctionDeclaration>(WTFMove(nativeFunctionDeclaration))); >- return true; >+ return m_nameContext.add(static_cast<AST::NativeFunctionDeclaration&>(m_nativeFunctionDeclarations.last())); > } > > bool append(AST::NativeTypeDeclaration&& nativeTypeDeclaration) > { > m_nativeTypeDeclarations.append(makeUniqueRef<AST::NativeTypeDeclaration>(WTFMove(nativeTypeDeclaration))); >- return true; >+ return m_nameContext.add(static_cast<AST::NativeTypeDeclaration&>(m_nativeTypeDeclarations.last())); > } > >+ NameContext& nameContext() { return m_nameContext; } > Vector<UniqueRef<AST::TypeDefinition>>& typeDefinitions() { return m_typeDefinitions; } > Vector<UniqueRef<AST::StructureDefinition>>& structureDefinitions() { return m_structureDefinitions; } > Vector<UniqueRef<AST::EnumerationDefinition>>& enumerationDefinitions() { return m_enumerationDefinitions; } >@@ -90,6 +91,7 @@ public: > Vector<UniqueRef<AST::NativeTypeDeclaration>>& nativeTypeDeclarations() { return m_nativeTypeDeclarations; } > > private: >+ NameContext m_nameContext; > Vector<UniqueRef<AST::TypeDefinition>> m_typeDefinitions; > Vector<UniqueRef<AST::StructureDefinition>> m_structureDefinitions; > Vector<UniqueRef<AST::EnumerationDefinition>> m_enumerationDefinitions; >diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt >index 12a9244c78f5a5575e21b034e5d21377440acf80..06d0269928f08da5cd7626112e120757ac24443d 100644 >--- a/Source/WebCore/Sources.txt >+++ b/Source/WebCore/Sources.txt >@@ -308,6 +308,8 @@ Modules/websockets/WorkerThreadableWebSocketChannel.cpp > Modules/webgpu/DOMWindowWebGPU.cpp > Modules/webgpu/WHLSL/WHLSLLexer.cpp > Modules/webgpu/WHLSL/WHLSLParser.cpp >+Modules/webgpu/WHLSL/WHLSLNameContext.cpp >+Modules/webgpu/WHLSL/WHLSLNameResolver.cpp > Modules/webgpu/WHLSL/AST/WHLSLTypeArgument.cpp > Modules/webgpu/WHLSL/AST/WHLSLBuiltInSemantic.cpp > Modules/webgpu/WHLSL/AST/WHLSLResourceSemantic.cpp >diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >index 915d5441a50b47f0b0e3ba8d139998ec94bf5e23..0002923edf92e8e6a956af5f587ba302795e8c81 100644 >--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj >+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >@@ -13318,6 +13318,10 @@ > C21BF74521CD969800227979 /* WHLSLStandardLibrary.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = WHLSLStandardLibrary.txt; sourceTree = "<group>"; }; > C21DF2E71D9E4E9900F5B24C /* CSSFontVariationValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSFontVariationValue.cpp; sourceTree = "<group>"; }; > C21DF2E81D9E4E9900F5B24C /* CSSFontVariationValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSFontVariationValue.h; sourceTree = "<group>"; }; >+ C234A98A21E8883E003C984D /* WHLSLNameResolver.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLNameResolver.cpp; sourceTree = "<group>"; }; >+ C234A98C21E8883E003C984D /* WHLSLNameResolver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLNameResolver.h; sourceTree = "<group>"; }; >+ C234A98D21E88884003C984D /* WHLSLNameContext.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLNameContext.cpp; sourceTree = "<group>"; }; >+ C234A98E21E88885003C984D /* WHLSLNameContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLNameContext.h; sourceTree = "<group>"; }; > C2458E611FE8979E00594759 /* FontCacheCoreText.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontCacheCoreText.h; sourceTree = "<group>"; }; > C26017A11C72DC9900F74A16 /* CSSFontFaceSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSFontFaceSet.cpp; sourceTree = "<group>"; }; > C26017A21C72DC9900F74A16 /* CSSFontFaceSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSFontFaceSet.h; sourceTree = "<group>"; }; >@@ -19669,7 +19673,6 @@ > 656580EC09D12B20000E61D7 /* Derived Sources */ = { > isa = PBXGroup; > children = ( >- C21BF74221CD963B00227979 /* WHLSLStandardLibrary.h */, > 538EC7EA1F96A95B004D22A8 /* unified-sources */, > 9908B0F31BCACFFE00ED0F65 /* ByteLengthQueuingStrategyBuiltins.cpp */, > 9908B0F51BCAD07D00ED0F65 /* ByteLengthQueuingStrategyBuiltins.h */, >@@ -19759,6 +19762,7 @@ > 656581AF09D14EE6000E61D7 /* UserAgentStyleSheetsData.cpp */, > 1A1414B313A0F0500019996C /* WebKitFontFamilyNames.cpp */, > 1A1414B413A0F0500019996C /* WebKitFontFamilyNames.h */, >+ C21BF74221CD963B00227979 /* WHLSLStandardLibrary.h */, > 51748FA21CC6EEEB00728D84 /* WorkerGlobalScopeConstructors.idl */, > 9908B0F91BCAD07D00ED0F75 /* WritableStreamBuiltins.cpp */, > 9B03D8061BB3110D00B764E8 /* WritableStreamBuiltins.h */, >@@ -25375,13 +25379,17 @@ > C210E90D21B4BCA400B7F83D /* WHLSL */ = { > isa = PBXGroup; > children = ( >- C21BF74521CD969800227979 /* WHLSLStandardLibrary.txt */, > C21BF6F121CD898D00227979 /* AST */, > C210E91121B4BD1000B7F83D /* WHLSLLexer.cpp */, > C210E91221B4BD1000B7F83D /* WHLSLLexer.h */, >+ C234A98D21E88884003C984D /* WHLSLNameContext.cpp */, >+ C234A98E21E88885003C984D /* WHLSLNameContext.h */, >+ C234A98A21E8883E003C984D /* WHLSLNameResolver.cpp */, >+ C234A98C21E8883E003C984D /* WHLSLNameResolver.h */, > C21BF73721CD8A0200227979 /* WHLSLParser.cpp */, > C21BF73821CD8A0300227979 /* WHLSLParser.h */, > C21BF73A21CD8D7000227979 /* WHLSLProgram.h */, >+ C21BF74521CD969800227979 /* WHLSLStandardLibrary.txt */, > ); > path = WHLSL; > sourceTree = "<group>";
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 193007
:
358021
|
358022
|
358157
|
358164
|
358167
|
358169
|
358883
|
358908
|
358922
|
358928
|
358977