tint: Move resolver/type_alias to type/short_name
'Short-name' is way less overloaded than 'alias' and 'builtin'. The package move allows transforms to use these enums. Change-Id: I61c6b3f7deee8e835990a948cd5427c07034fa5e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113440 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
04f792de9f
commit
d00663d882
|
@ -408,8 +408,6 @@ libtint_source_set("libtint_core_all_src") {
|
||||||
"resolver/resolver.h",
|
"resolver/resolver.h",
|
||||||
"resolver/sem_helper.cc",
|
"resolver/sem_helper.cc",
|
||||||
"resolver/sem_helper.h",
|
"resolver/sem_helper.h",
|
||||||
"resolver/type_alias.cc",
|
|
||||||
"resolver/type_alias.h",
|
|
||||||
"resolver/uniformity.cc",
|
"resolver/uniformity.cc",
|
||||||
"resolver/uniformity.h",
|
"resolver/uniformity.h",
|
||||||
"resolver/validator.cc",
|
"resolver/validator.cc",
|
||||||
|
@ -574,6 +572,7 @@ libtint_source_set("libtint_core_all_src") {
|
||||||
"type/reference.h",
|
"type/reference.h",
|
||||||
"type/sampled_texture.h",
|
"type/sampled_texture.h",
|
||||||
"type/sampler.h",
|
"type/sampler.h",
|
||||||
|
"type/short_name.h",
|
||||||
"type/storage_texture.h",
|
"type/storage_texture.h",
|
||||||
"type/texture.h",
|
"type/texture.h",
|
||||||
"type/type.h",
|
"type/type.h",
|
||||||
|
@ -737,6 +736,8 @@ libtint_source_set("libtint_type_src") {
|
||||||
"type/sampled_texture.h",
|
"type/sampled_texture.h",
|
||||||
"type/sampler.cc",
|
"type/sampler.cc",
|
||||||
"type/sampler.h",
|
"type/sampler.h",
|
||||||
|
"type/short_name.cc",
|
||||||
|
"type/short_name.h",
|
||||||
"type/storage_texture.cc",
|
"type/storage_texture.cc",
|
||||||
"type/storage_texture.h",
|
"type/storage_texture.h",
|
||||||
"type/texture.cc",
|
"type/texture.cc",
|
||||||
|
@ -1226,6 +1227,7 @@ if (tint_build_unittests) {
|
||||||
"type/reference_test.cc",
|
"type/reference_test.cc",
|
||||||
"type/sampled_texture_test.cc",
|
"type/sampled_texture_test.cc",
|
||||||
"type/sampler_test.cc",
|
"type/sampler_test.cc",
|
||||||
|
"type/short_name_test.cc",
|
||||||
"type/storage_texture_test.cc",
|
"type/storage_texture_test.cc",
|
||||||
"type/texture_test.cc",
|
"type/texture_test.cc",
|
||||||
"type/type_manager_test.cc",
|
"type/type_manager_test.cc",
|
||||||
|
|
|
@ -552,9 +552,9 @@ tint_generated(ast/extension BENCH TEST)
|
||||||
tint_generated(ast/interpolate_attribute BENCH TEST)
|
tint_generated(ast/interpolate_attribute BENCH TEST)
|
||||||
tint_generated(ast/texel_format BENCH TEST)
|
tint_generated(ast/texel_format BENCH TEST)
|
||||||
tint_generated(resolver/init_conv_intrinsic)
|
tint_generated(resolver/init_conv_intrinsic)
|
||||||
tint_generated(resolver/type_alias BENCH TEST)
|
|
||||||
tint_generated(sem/builtin_type)
|
tint_generated(sem/builtin_type)
|
||||||
tint_generated(sem/parameter_usage)
|
tint_generated(sem/parameter_usage)
|
||||||
|
tint_generated(type/short_name BENCH TEST)
|
||||||
|
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
list(APPEND TINT_LIB_SRCS diagnostic/printer_linux.cc)
|
list(APPEND TINT_LIB_SRCS diagnostic/printer_linux.cc)
|
||||||
|
|
|
@ -112,7 +112,7 @@ enum interpolation_sampling {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.w3.org/TR/WGSL/#vector-types
|
// https://www.w3.org/TR/WGSL/#vector-types
|
||||||
enum type_alias {
|
enum short_name {
|
||||||
vec2f
|
vec2f
|
||||||
vec2h
|
vec2h
|
||||||
vec2i
|
vec2i
|
||||||
|
|
|
@ -66,10 +66,10 @@
|
||||||
#include "src/tint/ast/void.h"
|
#include "src/tint/ast/void.h"
|
||||||
#include "src/tint/ast/while_statement.h"
|
#include "src/tint/ast/while_statement.h"
|
||||||
#include "src/tint/ast/workgroup_attribute.h"
|
#include "src/tint/ast/workgroup_attribute.h"
|
||||||
#include "src/tint/resolver/type_alias.h"
|
|
||||||
#include "src/tint/scope_stack.h"
|
#include "src/tint/scope_stack.h"
|
||||||
#include "src/tint/sem/builtin.h"
|
#include "src/tint/sem/builtin.h"
|
||||||
#include "src/tint/symbol_table.h"
|
#include "src/tint/symbol_table.h"
|
||||||
|
#include "src/tint/type/short_name.h"
|
||||||
#include "src/tint/utils/block_allocator.h"
|
#include "src/tint/utils/block_allocator.h"
|
||||||
#include "src/tint/utils/defer.h"
|
#include "src/tint/utils/defer.h"
|
||||||
#include "src/tint/utils/map.h"
|
#include "src/tint/utils/map.h"
|
||||||
|
@ -486,7 +486,7 @@ class DependencyScanner {
|
||||||
bool IsBuiltin(Symbol name) const {
|
bool IsBuiltin(Symbol name) const {
|
||||||
auto s = symbols_.NameFor(name);
|
auto s = symbols_.NameFor(name);
|
||||||
if (sem::ParseBuiltinType(s) != sem::BuiltinType::kNone ||
|
if (sem::ParseBuiltinType(s) != sem::BuiltinType::kNone ||
|
||||||
ParseTypeAlias(s) != TypeAlias::kUndefined) {
|
type::ParseShortName(s) != type::ShortName::kUndefined) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -51,7 +51,6 @@
|
||||||
#include "src/tint/ast/vector.h"
|
#include "src/tint/ast/vector.h"
|
||||||
#include "src/tint/ast/while_statement.h"
|
#include "src/tint/ast/while_statement.h"
|
||||||
#include "src/tint/ast/workgroup_attribute.h"
|
#include "src/tint/ast/workgroup_attribute.h"
|
||||||
#include "src/tint/resolver/type_alias.h"
|
|
||||||
#include "src/tint/resolver/uniformity.h"
|
#include "src/tint/resolver/uniformity.h"
|
||||||
#include "src/tint/sem/array.h"
|
#include "src/tint/sem/array.h"
|
||||||
#include "src/tint/sem/atomic.h"
|
#include "src/tint/sem/atomic.h"
|
||||||
|
@ -81,6 +80,7 @@
|
||||||
#include "src/tint/type/reference.h"
|
#include "src/tint/type/reference.h"
|
||||||
#include "src/tint/type/sampled_texture.h"
|
#include "src/tint/type/sampled_texture.h"
|
||||||
#include "src/tint/type/sampler.h"
|
#include "src/tint/type/sampler.h"
|
||||||
|
#include "src/tint/type/short_name.h"
|
||||||
#include "src/tint/type/storage_texture.h"
|
#include "src/tint/type/storage_texture.h"
|
||||||
#include "src/tint/utils/defer.h"
|
#include "src/tint/utils/defer.h"
|
||||||
#include "src/tint/utils/math.h"
|
#include "src/tint/utils/math.h"
|
||||||
|
@ -2349,32 +2349,32 @@ sem::Call* Resolver::BuiltinCall(const ast::CallExpression* expr,
|
||||||
type::Type* Resolver::BuiltinTypeAlias(Symbol sym) const {
|
type::Type* Resolver::BuiltinTypeAlias(Symbol sym) const {
|
||||||
auto name = builder_->Symbols().NameFor(sym);
|
auto name = builder_->Symbols().NameFor(sym);
|
||||||
auto& b = *builder_;
|
auto& b = *builder_;
|
||||||
switch (ParseTypeAlias(name)) {
|
switch (type::ParseShortName(name)) {
|
||||||
case TypeAlias::kVec2F:
|
case type::ShortName::kVec2F:
|
||||||
return b.create<sem::Vector>(b.create<type::F32>(), 2u);
|
return b.create<sem::Vector>(b.create<type::F32>(), 2u);
|
||||||
case TypeAlias::kVec3F:
|
case type::ShortName::kVec3F:
|
||||||
return b.create<sem::Vector>(b.create<type::F32>(), 3u);
|
return b.create<sem::Vector>(b.create<type::F32>(), 3u);
|
||||||
case TypeAlias::kVec4F:
|
case type::ShortName::kVec4F:
|
||||||
return b.create<sem::Vector>(b.create<type::F32>(), 4u);
|
return b.create<sem::Vector>(b.create<type::F32>(), 4u);
|
||||||
case TypeAlias::kVec2H:
|
case type::ShortName::kVec2H:
|
||||||
return b.create<sem::Vector>(b.create<type::F16>(), 2u);
|
return b.create<sem::Vector>(b.create<type::F16>(), 2u);
|
||||||
case TypeAlias::kVec3H:
|
case type::ShortName::kVec3H:
|
||||||
return b.create<sem::Vector>(b.create<type::F16>(), 3u);
|
return b.create<sem::Vector>(b.create<type::F16>(), 3u);
|
||||||
case TypeAlias::kVec4H:
|
case type::ShortName::kVec4H:
|
||||||
return b.create<sem::Vector>(b.create<type::F16>(), 4u);
|
return b.create<sem::Vector>(b.create<type::F16>(), 4u);
|
||||||
case TypeAlias::kVec2I:
|
case type::ShortName::kVec2I:
|
||||||
return b.create<sem::Vector>(b.create<type::I32>(), 2u);
|
return b.create<sem::Vector>(b.create<type::I32>(), 2u);
|
||||||
case TypeAlias::kVec3I:
|
case type::ShortName::kVec3I:
|
||||||
return b.create<sem::Vector>(b.create<type::I32>(), 3u);
|
return b.create<sem::Vector>(b.create<type::I32>(), 3u);
|
||||||
case TypeAlias::kVec4I:
|
case type::ShortName::kVec4I:
|
||||||
return b.create<sem::Vector>(b.create<type::I32>(), 4u);
|
return b.create<sem::Vector>(b.create<type::I32>(), 4u);
|
||||||
case TypeAlias::kVec2U:
|
case type::ShortName::kVec2U:
|
||||||
return b.create<sem::Vector>(b.create<type::U32>(), 2u);
|
return b.create<sem::Vector>(b.create<type::U32>(), 2u);
|
||||||
case TypeAlias::kVec3U:
|
case type::ShortName::kVec3U:
|
||||||
return b.create<sem::Vector>(b.create<type::U32>(), 3u);
|
return b.create<sem::Vector>(b.create<type::U32>(), 3u);
|
||||||
case TypeAlias::kVec4U:
|
case type::ShortName::kVec4U:
|
||||||
return b.create<sem::Vector>(b.create<type::U32>(), 4u);
|
return b.create<sem::Vector>(b.create<type::U32>(), 4u);
|
||||||
case TypeAlias::kUndefined:
|
case type::ShortName::kUndefined:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -1,97 +0,0 @@
|
||||||
// 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.
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// File generated by tools/src/cmd/gen
|
|
||||||
// using the template:
|
|
||||||
// src/tint/resolver/type_alias_test.cc.tmpl
|
|
||||||
//
|
|
||||||
// Do not modify this file directly
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#include "src/tint/resolver/type_alias.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
|
||||||
|
|
||||||
#include "src/tint/utils/string.h"
|
|
||||||
|
|
||||||
namespace tint::resolver {
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
namespace parse_print_tests {
|
|
||||||
|
|
||||||
struct Case {
|
|
||||||
const char* string;
|
|
||||||
TypeAlias value;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline std::ostream& operator<<(std::ostream& out, Case c) {
|
|
||||||
return out << "'" << std::string(c.string) << "'";
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr Case kValidCases[] = {
|
|
||||||
{"vec2f", TypeAlias::kVec2F}, {"vec2h", TypeAlias::kVec2H}, {"vec2i", TypeAlias::kVec2I},
|
|
||||||
{"vec2u", TypeAlias::kVec2U}, {"vec3f", TypeAlias::kVec3F}, {"vec3h", TypeAlias::kVec3H},
|
|
||||||
{"vec3i", TypeAlias::kVec3I}, {"vec3u", TypeAlias::kVec3U}, {"vec4f", TypeAlias::kVec4F},
|
|
||||||
{"vec4h", TypeAlias::kVec4H}, {"vec4i", TypeAlias::kVec4I}, {"vec4u", TypeAlias::kVec4U},
|
|
||||||
};
|
|
||||||
|
|
||||||
static constexpr Case kInvalidCases[] = {
|
|
||||||
{"veccf", TypeAlias::kUndefined}, {"32", TypeAlias::kUndefined},
|
|
||||||
{"vVc2f", TypeAlias::kUndefined}, {"vec21", TypeAlias::kUndefined},
|
|
||||||
{"qqeJh", TypeAlias::kUndefined}, {"vecll7h", TypeAlias::kUndefined},
|
|
||||||
{"veqH2pp", TypeAlias::kUndefined}, {"vi", TypeAlias::kUndefined},
|
|
||||||
{"Gebi", TypeAlias::kUndefined}, {"vevi2u", TypeAlias::kUndefined},
|
|
||||||
{"ve8WWu", TypeAlias::kUndefined}, {"Mxxc2", TypeAlias::kUndefined},
|
|
||||||
{"vgg3f", TypeAlias::kUndefined}, {"V3X", TypeAlias::kUndefined},
|
|
||||||
{"vec33", TypeAlias::kUndefined}, {"vec3E", TypeAlias::kUndefined},
|
|
||||||
{"TTeP3h", TypeAlias::kUndefined}, {"vxxcdd", TypeAlias::kUndefined},
|
|
||||||
{"v44c3i", TypeAlias::kUndefined}, {"veVVSSi", TypeAlias::kUndefined},
|
|
||||||
{"22RRi", TypeAlias::kUndefined}, {"vF3u", TypeAlias::kUndefined},
|
|
||||||
{"vecu", TypeAlias::kUndefined}, {"ROOHVu", TypeAlias::kUndefined},
|
|
||||||
{"ecyf", TypeAlias::kUndefined}, {"n77rrlcGf", TypeAlias::kUndefined},
|
|
||||||
{"vec440", TypeAlias::kUndefined}, {"ooh", TypeAlias::kUndefined},
|
|
||||||
{"vezz", TypeAlias::kUndefined}, {"1ipp4h", TypeAlias::kUndefined},
|
|
||||||
{"XXec4i", TypeAlias::kUndefined}, {"ve9IInn5i", TypeAlias::kUndefined},
|
|
||||||
{"HHreSSaYi", TypeAlias::kUndefined}, {"kk4", TypeAlias::kUndefined},
|
|
||||||
{"jgRR", TypeAlias::kUndefined}, {"veb", TypeAlias::kUndefined},
|
|
||||||
};
|
|
||||||
|
|
||||||
using TypeAliasParseTest = testing::TestWithParam<Case>;
|
|
||||||
|
|
||||||
TEST_P(TypeAliasParseTest, Parse) {
|
|
||||||
const char* string = GetParam().string;
|
|
||||||
TypeAlias expect = GetParam().value;
|
|
||||||
EXPECT_EQ(expect, ParseTypeAlias(string));
|
|
||||||
}
|
|
||||||
|
|
||||||
INSTANTIATE_TEST_SUITE_P(ValidCases, TypeAliasParseTest, testing::ValuesIn(kValidCases));
|
|
||||||
INSTANTIATE_TEST_SUITE_P(InvalidCases, TypeAliasParseTest, testing::ValuesIn(kInvalidCases));
|
|
||||||
|
|
||||||
using TypeAliasPrintTest = testing::TestWithParam<Case>;
|
|
||||||
|
|
||||||
TEST_P(TypeAliasPrintTest, Print) {
|
|
||||||
TypeAlias value = GetParam().value;
|
|
||||||
const char* expect = GetParam().string;
|
|
||||||
EXPECT_EQ(expect, utils::ToString(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
INSTANTIATE_TEST_SUITE_P(ValidCases, TypeAliasPrintTest, testing::ValuesIn(kValidCases));
|
|
||||||
|
|
||||||
} // namespace parse_print_tests
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
} // namespace tint::resolver
|
|
|
@ -15,88 +15,88 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// File generated by tools/src/cmd/gen
|
// File generated by tools/src/cmd/gen
|
||||||
// using the template:
|
// using the template:
|
||||||
// src/tint/resolver/type_alias.cc.tmpl
|
// src/tint/type/short_name.cc.tmpl
|
||||||
//
|
//
|
||||||
// Do not modify this file directly
|
// Do not modify this file directly
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "src/tint/resolver/type_alias.h"
|
#include "src/tint/type/short_name.h"
|
||||||
|
|
||||||
namespace tint::resolver {
|
namespace tint::type {
|
||||||
|
|
||||||
/// ParseTypeAlias parses a TypeAlias from a string.
|
/// ParseShortName parses a ShortName from a string.
|
||||||
/// @param str the string to parse
|
/// @param str the string to parse
|
||||||
/// @returns the parsed enum, or TypeAlias::kUndefined if the string could not be parsed.
|
/// @returns the parsed enum, or ShortName::kUndefined if the string could not be parsed.
|
||||||
TypeAlias ParseTypeAlias(std::string_view str) {
|
ShortName ParseShortName(std::string_view str) {
|
||||||
if (str == "vec2f") {
|
if (str == "vec2f") {
|
||||||
return TypeAlias::kVec2F;
|
return ShortName::kVec2F;
|
||||||
}
|
}
|
||||||
if (str == "vec2h") {
|
if (str == "vec2h") {
|
||||||
return TypeAlias::kVec2H;
|
return ShortName::kVec2H;
|
||||||
}
|
}
|
||||||
if (str == "vec2i") {
|
if (str == "vec2i") {
|
||||||
return TypeAlias::kVec2I;
|
return ShortName::kVec2I;
|
||||||
}
|
}
|
||||||
if (str == "vec2u") {
|
if (str == "vec2u") {
|
||||||
return TypeAlias::kVec2U;
|
return ShortName::kVec2U;
|
||||||
}
|
}
|
||||||
if (str == "vec3f") {
|
if (str == "vec3f") {
|
||||||
return TypeAlias::kVec3F;
|
return ShortName::kVec3F;
|
||||||
}
|
}
|
||||||
if (str == "vec3h") {
|
if (str == "vec3h") {
|
||||||
return TypeAlias::kVec3H;
|
return ShortName::kVec3H;
|
||||||
}
|
}
|
||||||
if (str == "vec3i") {
|
if (str == "vec3i") {
|
||||||
return TypeAlias::kVec3I;
|
return ShortName::kVec3I;
|
||||||
}
|
}
|
||||||
if (str == "vec3u") {
|
if (str == "vec3u") {
|
||||||
return TypeAlias::kVec3U;
|
return ShortName::kVec3U;
|
||||||
}
|
}
|
||||||
if (str == "vec4f") {
|
if (str == "vec4f") {
|
||||||
return TypeAlias::kVec4F;
|
return ShortName::kVec4F;
|
||||||
}
|
}
|
||||||
if (str == "vec4h") {
|
if (str == "vec4h") {
|
||||||
return TypeAlias::kVec4H;
|
return ShortName::kVec4H;
|
||||||
}
|
}
|
||||||
if (str == "vec4i") {
|
if (str == "vec4i") {
|
||||||
return TypeAlias::kVec4I;
|
return ShortName::kVec4I;
|
||||||
}
|
}
|
||||||
if (str == "vec4u") {
|
if (str == "vec4u") {
|
||||||
return TypeAlias::kVec4U;
|
return ShortName::kVec4U;
|
||||||
}
|
}
|
||||||
return TypeAlias::kUndefined;
|
return ShortName::kUndefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& out, TypeAlias value) {
|
std::ostream& operator<<(std::ostream& out, ShortName value) {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case TypeAlias::kUndefined:
|
case ShortName::kUndefined:
|
||||||
return out << "undefined";
|
return out << "undefined";
|
||||||
case TypeAlias::kVec2F:
|
case ShortName::kVec2F:
|
||||||
return out << "vec2f";
|
return out << "vec2f";
|
||||||
case TypeAlias::kVec2H:
|
case ShortName::kVec2H:
|
||||||
return out << "vec2h";
|
return out << "vec2h";
|
||||||
case TypeAlias::kVec2I:
|
case ShortName::kVec2I:
|
||||||
return out << "vec2i";
|
return out << "vec2i";
|
||||||
case TypeAlias::kVec2U:
|
case ShortName::kVec2U:
|
||||||
return out << "vec2u";
|
return out << "vec2u";
|
||||||
case TypeAlias::kVec3F:
|
case ShortName::kVec3F:
|
||||||
return out << "vec3f";
|
return out << "vec3f";
|
||||||
case TypeAlias::kVec3H:
|
case ShortName::kVec3H:
|
||||||
return out << "vec3h";
|
return out << "vec3h";
|
||||||
case TypeAlias::kVec3I:
|
case ShortName::kVec3I:
|
||||||
return out << "vec3i";
|
return out << "vec3i";
|
||||||
case TypeAlias::kVec3U:
|
case ShortName::kVec3U:
|
||||||
return out << "vec3u";
|
return out << "vec3u";
|
||||||
case TypeAlias::kVec4F:
|
case ShortName::kVec4F:
|
||||||
return out << "vec4f";
|
return out << "vec4f";
|
||||||
case TypeAlias::kVec4H:
|
case ShortName::kVec4H:
|
||||||
return out << "vec4h";
|
return out << "vec4h";
|
||||||
case TypeAlias::kVec4I:
|
case ShortName::kVec4I:
|
||||||
return out << "vec4i";
|
return out << "vec4i";
|
||||||
case TypeAlias::kVec4U:
|
case ShortName::kVec4U:
|
||||||
return out << "vec4u";
|
return out << "vec4u";
|
||||||
}
|
}
|
||||||
return out << "<unknown>";
|
return out << "<unknown>";
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace tint::resolver
|
} // namespace tint::type
|
|
@ -1,6 +1,6 @@
|
||||||
{{- /*
|
{{- /*
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
Template file for use with tools/src/cmd/gen to generate type_alias.cc
|
Template file for use with tools/src/cmd/gen to generate short_name.cc
|
||||||
|
|
||||||
To update the generated file, run:
|
To update the generated file, run:
|
||||||
./tools/run gen
|
./tools/run gen
|
||||||
|
@ -12,14 +12,14 @@ See:
|
||||||
*/ -}}
|
*/ -}}
|
||||||
|
|
||||||
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
|
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
|
||||||
{{- $enum := (Sem.Enum "type_alias") -}}
|
{{- $enum := (Sem.Enum "short_name") -}}
|
||||||
|
|
||||||
#include "src/tint/resolver/type_alias.h"
|
#include "src/tint/type/short_name.h"
|
||||||
|
|
||||||
namespace tint::resolver {
|
namespace tint::type {
|
||||||
|
|
||||||
{{ Eval "ParseEnum" $enum}}
|
{{ Eval "ParseEnum" $enum}}
|
||||||
|
|
||||||
{{ Eval "EnumOStream" $enum}}
|
{{ Eval "EnumOStream" $enum}}
|
||||||
|
|
||||||
} // namespace tint::resolver
|
} // namespace tint::type
|
|
@ -15,20 +15,20 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// File generated by tools/src/cmd/gen
|
// File generated by tools/src/cmd/gen
|
||||||
// using the template:
|
// using the template:
|
||||||
// src/tint/resolver/type_alias.h.tmpl
|
// src/tint/type/short_name.h.tmpl
|
||||||
//
|
//
|
||||||
// Do not modify this file directly
|
// Do not modify this file directly
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SRC_TINT_RESOLVER_TYPE_ALIAS_H_
|
#ifndef SRC_TINT_TYPE_SHORT_NAME_H_
|
||||||
#define SRC_TINT_RESOLVER_TYPE_ALIAS_H_
|
#define SRC_TINT_TYPE_SHORT_NAME_H_
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
namespace tint::resolver {
|
namespace tint::type {
|
||||||
|
|
||||||
/// An enumerator of builtin type aliases.
|
/// An enumerator of builtin type aliases.
|
||||||
enum class TypeAlias {
|
enum class ShortName {
|
||||||
kUndefined,
|
kUndefined,
|
||||||
kVec2F,
|
kVec2F,
|
||||||
kVec2H,
|
kVec2H,
|
||||||
|
@ -45,20 +45,20 @@ enum class TypeAlias {
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @param out the std::ostream to write to
|
/// @param out the std::ostream to write to
|
||||||
/// @param value the TypeAlias
|
/// @param value the ShortName
|
||||||
/// @returns `out` so calls can be chained
|
/// @returns `out` so calls can be chained
|
||||||
std::ostream& operator<<(std::ostream& out, TypeAlias value);
|
std::ostream& operator<<(std::ostream& out, ShortName value);
|
||||||
|
|
||||||
/// ParseTypeAlias parses a TypeAlias from a string.
|
/// ParseShortName parses a ShortName from a string.
|
||||||
/// @param str the string to parse
|
/// @param str the string to parse
|
||||||
/// @returns the parsed enum, or TypeAlias::kUndefined if the string could not be parsed.
|
/// @returns the parsed enum, or ShortName::kUndefined if the string could not be parsed.
|
||||||
TypeAlias ParseTypeAlias(std::string_view str);
|
ShortName ParseShortName(std::string_view str);
|
||||||
|
|
||||||
constexpr const char* kTypeAliasStrings[] = {
|
constexpr const char* kShortNameStrings[] = {
|
||||||
"vec2f", "vec2h", "vec2i", "vec2u", "vec3f", "vec3h",
|
"vec2f", "vec2h", "vec2i", "vec2u", "vec3f", "vec3h",
|
||||||
"vec3i", "vec3u", "vec4f", "vec4h", "vec4i", "vec4u",
|
"vec3i", "vec3u", "vec4f", "vec4h", "vec4i", "vec4u",
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tint::resolver
|
} // namespace tint::type
|
||||||
|
|
||||||
#endif // SRC_TINT_RESOLVER_TYPE_ALIAS_H_
|
#endif // SRC_TINT_TYPE_SHORT_NAME_H_
|
|
@ -1,6 +1,6 @@
|
||||||
{{- /*
|
{{- /*
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
Template file for use with tools/src/cmd/gen to generate type_alias.h
|
Template file for use with tools/src/cmd/gen to generate short_name.h
|
||||||
|
|
||||||
To update the generated file, run:
|
To update the generated file, run:
|
||||||
./tools/run gen
|
./tools/run gen
|
||||||
|
@ -12,18 +12,18 @@ See:
|
||||||
*/ -}}
|
*/ -}}
|
||||||
|
|
||||||
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
|
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
|
||||||
{{- $enum := (Sem.Enum "type_alias") -}}
|
{{- $enum := (Sem.Enum "short_name") -}}
|
||||||
|
|
||||||
#ifndef SRC_TINT_RESOLVER_TYPE_ALIAS_H_
|
#ifndef SRC_TINT_TYPE_SHORT_NAME_H_
|
||||||
#define SRC_TINT_RESOLVER_TYPE_ALIAS_H_
|
#define SRC_TINT_TYPE_SHORT_NAME_H_
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
namespace tint::resolver {
|
namespace tint::type {
|
||||||
|
|
||||||
/// An enumerator of builtin type aliases.
|
/// An enumerator of builtin type aliases.
|
||||||
{{ Eval "DeclareEnum" $enum}}
|
{{ Eval "DeclareEnum" $enum}}
|
||||||
|
|
||||||
} // namespace tint::resolver
|
} // namespace tint::type
|
||||||
|
|
||||||
#endif // SRC_TINT_RESOLVER_TYPE_ALIAS_H_
|
#endif // SRC_TINT_TYPE_SHORT_NAME_H_
|
|
@ -15,21 +15,21 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// File generated by tools/src/cmd/gen
|
// File generated by tools/src/cmd/gen
|
||||||
// using the template:
|
// using the template:
|
||||||
// src/tint/resolver/type_alias_bench.cc.tmpl
|
// src/tint/type/short_name_bench.cc.tmpl
|
||||||
//
|
//
|
||||||
// Do not modify this file directly
|
// Do not modify this file directly
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "src/tint/resolver/type_alias.h"
|
#include "src/tint/type/short_name.h"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
#include "benchmark/benchmark.h"
|
#include "benchmark/benchmark.h"
|
||||||
|
|
||||||
namespace tint::resolver {
|
namespace tint::type {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void TypeAliasParser(::benchmark::State& state) {
|
void ShortNameParser(::benchmark::State& state) {
|
||||||
std::array kStrings{
|
std::array kStrings{
|
||||||
"veccf", "32", "vVc2f", "vec2f", "vec21", "qqeJf", "vecll7f", "veqH2pp",
|
"veccf", "32", "vVc2f", "vec2f", "vec21", "qqeJf", "vecll7f", "veqH2pp",
|
||||||
"vh", "Gebh", "vec2h", "vevi2h", "ve8WWh", "Mxxc2", "vgg2i", "V2X",
|
"vh", "Gebh", "vec2h", "vevi2h", "ve8WWh", "Mxxc2", "vgg2i", "V2X",
|
||||||
|
@ -45,13 +45,13 @@ void TypeAliasParser(::benchmark::State& state) {
|
||||||
};
|
};
|
||||||
for (auto _ : state) {
|
for (auto _ : state) {
|
||||||
for (auto& str : kStrings) {
|
for (auto& str : kStrings) {
|
||||||
auto result = ParseTypeAlias(str);
|
auto result = ParseShortName(str);
|
||||||
benchmark::DoNotOptimize(result);
|
benchmark::DoNotOptimize(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BENCHMARK(TypeAliasParser);
|
BENCHMARK(ShortNameParser);
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace tint::resolver
|
} // namespace tint::type
|
|
@ -1,6 +1,6 @@
|
||||||
{{- /*
|
{{- /*
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
Template file for use with tools/src/cmd/gen to generate type_alias_bench.cc
|
Template file for use with tools/src/cmd/gen to generate short_name_bench.cc
|
||||||
|
|
||||||
To update the generated file, run:
|
To update the generated file, run:
|
||||||
./tools/run gen
|
./tools/run gen
|
||||||
|
@ -12,18 +12,18 @@ See:
|
||||||
*/ -}}
|
*/ -}}
|
||||||
|
|
||||||
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
|
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
|
||||||
{{- $enum := (Sem.Enum "type_alias") -}}
|
{{- $enum := (Sem.Enum "short_name") -}}
|
||||||
|
|
||||||
#include "src/tint/resolver/type_alias.h"
|
#include "src/tint/type/short_name.h"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
#include "benchmark/benchmark.h"
|
#include "benchmark/benchmark.h"
|
||||||
|
|
||||||
namespace tint::resolver {
|
namespace tint::type {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
{{ Eval "BenchmarkParseEnum" $enum }}
|
{{ Eval "BenchmarkParseEnum" $enum }}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace tint::resolver
|
} // namespace tint::type
|
|
@ -0,0 +1,97 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// File generated by tools/src/cmd/gen
|
||||||
|
// using the template:
|
||||||
|
// src/tint/type/short_name_test.cc.tmpl
|
||||||
|
//
|
||||||
|
// Do not modify this file directly
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "src/tint/type/short_name.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
#include "src/tint/utils/string.h"
|
||||||
|
|
||||||
|
namespace tint::type {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
namespace parse_print_tests {
|
||||||
|
|
||||||
|
struct Case {
|
||||||
|
const char* string;
|
||||||
|
ShortName value;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline std::ostream& operator<<(std::ostream& out, Case c) {
|
||||||
|
return out << "'" << std::string(c.string) << "'";
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr Case kValidCases[] = {
|
||||||
|
{"vec2f", ShortName::kVec2F}, {"vec2h", ShortName::kVec2H}, {"vec2i", ShortName::kVec2I},
|
||||||
|
{"vec2u", ShortName::kVec2U}, {"vec3f", ShortName::kVec3F}, {"vec3h", ShortName::kVec3H},
|
||||||
|
{"vec3i", ShortName::kVec3I}, {"vec3u", ShortName::kVec3U}, {"vec4f", ShortName::kVec4F},
|
||||||
|
{"vec4h", ShortName::kVec4H}, {"vec4i", ShortName::kVec4I}, {"vec4u", ShortName::kVec4U},
|
||||||
|
};
|
||||||
|
|
||||||
|
static constexpr Case kInvalidCases[] = {
|
||||||
|
{"veccf", ShortName::kUndefined}, {"32", ShortName::kUndefined},
|
||||||
|
{"vVc2f", ShortName::kUndefined}, {"vec21", ShortName::kUndefined},
|
||||||
|
{"qqeJh", ShortName::kUndefined}, {"vecll7h", ShortName::kUndefined},
|
||||||
|
{"veqH2pp", ShortName::kUndefined}, {"vi", ShortName::kUndefined},
|
||||||
|
{"Gebi", ShortName::kUndefined}, {"vevi2u", ShortName::kUndefined},
|
||||||
|
{"ve8WWu", ShortName::kUndefined}, {"Mxxc2", ShortName::kUndefined},
|
||||||
|
{"vgg3f", ShortName::kUndefined}, {"V3X", ShortName::kUndefined},
|
||||||
|
{"vec33", ShortName::kUndefined}, {"vec3E", ShortName::kUndefined},
|
||||||
|
{"TTeP3h", ShortName::kUndefined}, {"vxxcdd", ShortName::kUndefined},
|
||||||
|
{"v44c3i", ShortName::kUndefined}, {"veVVSSi", ShortName::kUndefined},
|
||||||
|
{"22RRi", ShortName::kUndefined}, {"vF3u", ShortName::kUndefined},
|
||||||
|
{"vecu", ShortName::kUndefined}, {"ROOHVu", ShortName::kUndefined},
|
||||||
|
{"ecyf", ShortName::kUndefined}, {"n77rrlcGf", ShortName::kUndefined},
|
||||||
|
{"vec440", ShortName::kUndefined}, {"ooh", ShortName::kUndefined},
|
||||||
|
{"vezz", ShortName::kUndefined}, {"1ipp4h", ShortName::kUndefined},
|
||||||
|
{"XXec4i", ShortName::kUndefined}, {"ve9IInn5i", ShortName::kUndefined},
|
||||||
|
{"HHreSSaYi", ShortName::kUndefined}, {"kk4", ShortName::kUndefined},
|
||||||
|
{"jgRR", ShortName::kUndefined}, {"veb", ShortName::kUndefined},
|
||||||
|
};
|
||||||
|
|
||||||
|
using ShortNameParseTest = testing::TestWithParam<Case>;
|
||||||
|
|
||||||
|
TEST_P(ShortNameParseTest, Parse) {
|
||||||
|
const char* string = GetParam().string;
|
||||||
|
ShortName expect = GetParam().value;
|
||||||
|
EXPECT_EQ(expect, ParseShortName(string));
|
||||||
|
}
|
||||||
|
|
||||||
|
INSTANTIATE_TEST_SUITE_P(ValidCases, ShortNameParseTest, testing::ValuesIn(kValidCases));
|
||||||
|
INSTANTIATE_TEST_SUITE_P(InvalidCases, ShortNameParseTest, testing::ValuesIn(kInvalidCases));
|
||||||
|
|
||||||
|
using ShortNamePrintTest = testing::TestWithParam<Case>;
|
||||||
|
|
||||||
|
TEST_P(ShortNamePrintTest, Print) {
|
||||||
|
ShortName value = GetParam().value;
|
||||||
|
const char* expect = GetParam().string;
|
||||||
|
EXPECT_EQ(expect, utils::ToString(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
INSTANTIATE_TEST_SUITE_P(ValidCases, ShortNamePrintTest, testing::ValuesIn(kValidCases));
|
||||||
|
|
||||||
|
} // namespace parse_print_tests
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace tint::type
|
|
@ -1,6 +1,6 @@
|
||||||
{{- /*
|
{{- /*
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
Template file for use with tools/src/cmd/gen to generate type_alias_test.cc
|
Template file for use with tools/src/cmd/gen to generate short_name_test.cc
|
||||||
|
|
||||||
To update the generated file, run:
|
To update the generated file, run:
|
||||||
./tools/run gen
|
./tools/run gen
|
||||||
|
@ -12,9 +12,9 @@ See:
|
||||||
*/ -}}
|
*/ -}}
|
||||||
|
|
||||||
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
|
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
|
||||||
{{- $enum := (Sem.Enum "type_alias") -}}
|
{{- $enum := (Sem.Enum "short_name") -}}
|
||||||
|
|
||||||
#include "src/tint/resolver/type_alias.h"
|
#include "src/tint/type/short_name.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -22,10 +22,10 @@ See:
|
||||||
|
|
||||||
#include "src/tint/utils/string.h"
|
#include "src/tint/utils/string.h"
|
||||||
|
|
||||||
namespace tint::resolver {
|
namespace tint::type {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
{{ Eval "TestParsePrintEnum" $enum}}
|
{{ Eval "TestParsePrintEnum" $enum}}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace tint::resolver
|
} // namespace tint::type
|
Loading…
Reference in New Issue