diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn index 691b435abd..5a52e55420 100644 --- a/src/tint/BUILD.gn +++ b/src/tint/BUILD.gn @@ -553,6 +553,12 @@ libtint_source_set("libtint_core_all_src") { libtint_source_set("libtint_sem_src") { sources = [ + "sem/abstract_float.cc", + "sem/abstract_float.h", + "sem/abstract_int.cc", + "sem/abstract_int.h", + "sem/abstract_numeric.cc", + "sem/abstract_numeric.h", "sem/array.cc", "sem/array.h", "sem/atomic.cc", diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt index ac9723f585..e5dcb14833 100644 --- a/src/tint/CMakeLists.txt +++ b/src/tint/CMakeLists.txt @@ -262,6 +262,12 @@ set(TINT_LIB_SRCS resolver/validator.cc resolver/validator.h scope_stack.h + sem/abstract_float.cc + sem/abstract_float.h + sem/abstract_int.cc + sem/abstract_int.h + sem/abstract_numeric.cc + sem/abstract_numeric.h sem/array.cc sem/array.h sem/atomic.cc diff --git a/src/tint/sem/abstract_float.cc b/src/tint/sem/abstract_float.cc new file mode 100644 index 0000000000..e9282bfe40 --- /dev/null +++ b/src/tint/sem/abstract_float.cc @@ -0,0 +1,40 @@ +// Copyright 2022 The Tint Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "src/tint/sem/abstract_float.h" + +#include "src/tint/program_builder.h" +#include "src/tint/utils/hash.h" + +TINT_INSTANTIATE_TYPEINFO(tint::sem::AbstractFloat); + +namespace tint::sem { + +AbstractFloat::AbstractFloat() = default; +AbstractFloat::AbstractFloat(AbstractFloat&&) = default; +AbstractFloat::~AbstractFloat() = default; + +size_t AbstractFloat::Hash() const { + return utils::Hash(TypeInfo::Of().full_hashcode); +} + +bool AbstractFloat::Equals(const sem::Type& other) const { + return other.Is(); +} + +std::string AbstractFloat::FriendlyName(const SymbolTable&) const { + return "AbstractFloat"; +} + +} // namespace tint::sem diff --git a/src/tint/sem/abstract_float.h b/src/tint/sem/abstract_float.h new file mode 100644 index 0000000000..8fb00fb4e0 --- /dev/null +++ b/src/tint/sem/abstract_float.h @@ -0,0 +1,49 @@ +// Copyright 2022 The Tint Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef SRC_TINT_SEM_ABSTRACT_FLOAT_H_ +#define SRC_TINT_SEM_ABSTRACT_FLOAT_H_ + +#include + +#include "src/tint/sem/abstract_numeric.h" + +namespace tint::sem { + +/// An abstract-float type. +/// @see https://www.w3.org/TR/WGSL/#abstractFloat +class AbstractFloat final : public Castable { + public: + /// Constructor + AbstractFloat(); + + /// Move constructor + AbstractFloat(AbstractFloat&&); + ~AbstractFloat() override; + + /// @returns a hash of the type. + size_t Hash() const override; + + /// @param other the other type to compare against + /// @returns true if this type is equal to the given type + bool Equals(const Type& other) const override; + + /// @param symbols the program's symbol table + /// @returns the name for this type when printed in diagnostics. + std::string FriendlyName(const SymbolTable& symbols) const override; +}; + +} // namespace tint::sem + +#endif // SRC_TINT_SEM_ABSTRACT_FLOAT_H_ diff --git a/src/tint/sem/abstract_int.cc b/src/tint/sem/abstract_int.cc new file mode 100644 index 0000000000..31b242c4e3 --- /dev/null +++ b/src/tint/sem/abstract_int.cc @@ -0,0 +1,40 @@ +// Copyright 2022 The Tint Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "src/tint/sem/abstract_int.h" + +#include "src/tint/program_builder.h" +#include "src/tint/utils/hash.h" + +TINT_INSTANTIATE_TYPEINFO(tint::sem::AbstractInt); + +namespace tint::sem { + +AbstractInt::AbstractInt() = default; +AbstractInt::AbstractInt(AbstractInt&&) = default; +AbstractInt::~AbstractInt() = default; + +size_t AbstractInt::Hash() const { + return utils::Hash(TypeInfo::Of().full_hashcode); +} + +bool AbstractInt::Equals(const sem::Type& other) const { + return other.Is(); +} + +std::string AbstractInt::FriendlyName(const SymbolTable&) const { + return "AbstractInt"; +} + +} // namespace tint::sem diff --git a/src/tint/sem/abstract_int.h b/src/tint/sem/abstract_int.h new file mode 100644 index 0000000000..95ec46198e --- /dev/null +++ b/src/tint/sem/abstract_int.h @@ -0,0 +1,49 @@ +// Copyright 2022 The Tint Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef SRC_TINT_SEM_ABSTRACT_INT_H_ +#define SRC_TINT_SEM_ABSTRACT_INT_H_ + +#include + +#include "src/tint/sem/abstract_numeric.h" + +namespace tint::sem { + +/// An abstract-int type. +/// @see https://www.w3.org/TR/WGSL/#abstractint +class AbstractInt final : public Castable { + public: + /// Constructor + AbstractInt(); + + /// Move constructor + AbstractInt(AbstractInt&&); + ~AbstractInt() override; + + /// @returns a hash of the type. + size_t Hash() const override; + + /// @param other the other type to compare against + /// @returns true if the this type is equal to the given type + bool Equals(const Type& other) const override; + + /// @param symbols the program's symbol table + /// @returns the name for this type when printed in diagnostics. + std::string FriendlyName(const SymbolTable& symbols) const override; +}; + +} // namespace tint::sem + +#endif // SRC_TINT_SEM_ABSTRACT_INT_H_ diff --git a/src/tint/sem/abstract_numeric.cc b/src/tint/sem/abstract_numeric.cc new file mode 100644 index 0000000000..34291712a0 --- /dev/null +++ b/src/tint/sem/abstract_numeric.cc @@ -0,0 +1,37 @@ +// Copyright 2022 The Tint Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "src/tint/sem/abstract_numeric.h" + +TINT_INSTANTIATE_TYPEINFO(tint::sem::AbstractNumeric); + +namespace tint::sem { + +AbstractNumeric::AbstractNumeric() = default; +AbstractNumeric::AbstractNumeric(AbstractNumeric&&) = default; +AbstractNumeric::~AbstractNumeric() = default; + +uint32_t AbstractNumeric::Size() const { + return 0; +} + +uint32_t AbstractNumeric::Align() const { + return 0; +} + +bool AbstractNumeric::IsConstructible() const { + return false; +} + +} // namespace tint::sem diff --git a/src/tint/sem/abstract_numeric.h b/src/tint/sem/abstract_numeric.h new file mode 100644 index 0000000000..637d9551cf --- /dev/null +++ b/src/tint/sem/abstract_numeric.h @@ -0,0 +1,47 @@ +// Copyright 2022 The Tint Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef SRC_TINT_SEM_ABSTRACT_NUMERIC_H_ +#define SRC_TINT_SEM_ABSTRACT_NUMERIC_H_ + +#include + +#include "src/tint/sem/type.h" + +namespace tint::sem { + +/// The base class for abstract-int and abstract-float types. +/// @see https://www.w3.org/TR/WGSL/#types-for-creation-time-constants +class AbstractNumeric : public Castable { + public: + /// Constructor + AbstractNumeric(); + + /// Move constructor + AbstractNumeric(AbstractNumeric&&); + ~AbstractNumeric() override; + + /// @returns 0, as the type is abstract. + uint32_t Size() const override; + + /// @returns 0, as the type is abstract. + uint32_t Align() const override; + + /// @returns 0, as the type is abstract. + bool IsConstructible() const override; +}; + +} // namespace tint::sem + +#endif // SRC_TINT_SEM_ABSTRACT_NUMERIC_H_ diff --git a/src/tint/sem/atomic.h b/src/tint/sem/atomic.h index 0bc98080c7..cdfa562563 100644 --- a/src/tint/sem/atomic.h +++ b/src/tint/sem/atomic.h @@ -54,7 +54,7 @@ class Atomic final : public Castable { uint32_t Align() const override; /// @returns true if constructible as per - /// https://gpuweb.github.io/gpuweb/wgsl/#constructible-typesd + /// https://gpuweb.github.io/gpuweb/wgsl/#constructible-types bool IsConstructible() const override; private: