// Copyright 2023 The Dawn & Tint Authors // // 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. // // 3. Neither the name of the copyright holder nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT HOLDER OR 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. #ifndef SRC_TINT_LANG_CORE_INTRINSIC_TABLE_DATA_H_ #define SRC_TINT_LANG_CORE_INTRINSIC_TABLE_DATA_H_ #include <stdint.h> #include <limits> #include <string> #include "src/tint/lang/core/constant/eval.h" #include "src/tint/lang/core/evaluation_stage.h" #include "src/tint/lang/core/parameter_usage.h" #include "src/tint/utils/containers/enum_set.h" #include "src/tint/utils/containers/slice.h" #include "src/tint/utils/text/styled_text.h" #include "src/tint/utils/text/text_style.h" /// Forward declaration namespace tint::core::intrinsic { struct TableData; } // namespace tint::core::intrinsic namespace tint::core::intrinsic { /// An enumerator of index namespaces. enum class TableIndexNamespace : uint8_t { … }; /// A wrapper around an integer type, used to index intrinsic table data /// @tparam T the index data type /// @tparam N the index namespace template <TableIndexNamespace N, typename T> struct TableIndex { … }; /// Index type used to index TableData::template_types TemplateIndex; /// Index type used to index TableData::type_matchers or TableData::number_matchers MatcherIndex; /// Index type used to index TableData::matcher_indices MatcherIndicesIndex; /// Index type used to index TableData::type_matchers TypeMatcherIndex; /// Index type used to index TableData::number_matchers NumberMatcherIndex; /// Index type used to index TableData::parameters ParameterIndex; /// Index type used to index TableData::overloads OverloadIndex; /// Index type used to index TableData::const_eval_functions ConstEvalFunctionIndex; /// Unique flag bits for overloads enum class OverloadFlag : uint8_t { … }; /// An enum set of OverloadFlag, used by OperatorInfo OverloadFlags; /// ParameterInfo describes a parameter struct ParameterInfo { … }; /// TemplateInfo describes an template struct TemplateInfo { … }; /// OverloadInfo describes a single function overload struct OverloadInfo { … }; /// IntrinsicInfo describes a builtin function or operator overload struct IntrinsicInfo { … }; /// A IntrinsicInfo with no overloads static constexpr IntrinsicInfo kNoOverloads{ … }; /// Number is an 32 bit unsigned integer, which can be in one of three states: /// * Invalid - Number has not been assigned a value /// * Valid - a fixed integer value /// * Any - matches any other non-invalid number class Number { … }; /// A special type that matches all TypeMatchers class Any final : public Castable<Any, core::type::Type> { … }; /// TemplateState holds the state of the template numbers and types. /// Used by the MatchState. class TemplateState { … }; /// The current overload match state /// MatchState holds the state used to match an overload. class MatchState { … }; /// A TypeMatcher is the interface used to match an type used as part of an /// overload's parameter or return type. struct TypeMatcher { … }; /// A NumberMatcher is the interface used to match a number or enumerator used /// as part of an overload's parameter or return type. struct NumberMatcher { … }; /// TableData holds the immutable data that holds the intrinsic data for a language. struct TableData { … }; const core::type::Type* MatchState::Type(const core::type::Type* ty) { … } Number MatchState::Num(Number number) { … } void MatchState::PrintType(StyledText& out) { … } void MatchState::PrintNum(StyledText& out) { … } /// TemplateTypeMatcher is a Matcher for a template type. /// The TemplateTypeMatcher will initially match against any type, and then will only be further /// constrained based on the conversion rules defined at /// https://www.w3.org/TR/WGSL/#conversion-rank template <size_t INDEX> struct TemplateTypeMatcher { … }; /// TemplateNumberMatcher is a Matcher for a template number. /// The TemplateNumberMatcher will match against any number (so long as it is /// consistent for all uses in the overload) template <size_t INDEX> struct TemplateNumberMatcher { … }; } // namespace tint::core::intrinsic #endif // SRC_TINT_LANG_CORE_INTRINSIC_TABLE_DATA_H_