mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 18:29:23 +00:00
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:
committed by
Dawn LUCI CQ
parent
04f792de9f
commit
d00663d882
102
src/tint/type/short_name.cc
Normal file
102
src/tint/type/short_name.cc
Normal file
@@ -0,0 +1,102 @@
|
||||
// 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.cc.tmpl
|
||||
//
|
||||
// Do not modify this file directly
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "src/tint/type/short_name.h"
|
||||
|
||||
namespace tint::type {
|
||||
|
||||
/// ParseShortName parses a ShortName from a string.
|
||||
/// @param str the string to parse
|
||||
/// @returns the parsed enum, or ShortName::kUndefined if the string could not be parsed.
|
||||
ShortName ParseShortName(std::string_view str) {
|
||||
if (str == "vec2f") {
|
||||
return ShortName::kVec2F;
|
||||
}
|
||||
if (str == "vec2h") {
|
||||
return ShortName::kVec2H;
|
||||
}
|
||||
if (str == "vec2i") {
|
||||
return ShortName::kVec2I;
|
||||
}
|
||||
if (str == "vec2u") {
|
||||
return ShortName::kVec2U;
|
||||
}
|
||||
if (str == "vec3f") {
|
||||
return ShortName::kVec3F;
|
||||
}
|
||||
if (str == "vec3h") {
|
||||
return ShortName::kVec3H;
|
||||
}
|
||||
if (str == "vec3i") {
|
||||
return ShortName::kVec3I;
|
||||
}
|
||||
if (str == "vec3u") {
|
||||
return ShortName::kVec3U;
|
||||
}
|
||||
if (str == "vec4f") {
|
||||
return ShortName::kVec4F;
|
||||
}
|
||||
if (str == "vec4h") {
|
||||
return ShortName::kVec4H;
|
||||
}
|
||||
if (str == "vec4i") {
|
||||
return ShortName::kVec4I;
|
||||
}
|
||||
if (str == "vec4u") {
|
||||
return ShortName::kVec4U;
|
||||
}
|
||||
return ShortName::kUndefined;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, ShortName value) {
|
||||
switch (value) {
|
||||
case ShortName::kUndefined:
|
||||
return out << "undefined";
|
||||
case ShortName::kVec2F:
|
||||
return out << "vec2f";
|
||||
case ShortName::kVec2H:
|
||||
return out << "vec2h";
|
||||
case ShortName::kVec2I:
|
||||
return out << "vec2i";
|
||||
case ShortName::kVec2U:
|
||||
return out << "vec2u";
|
||||
case ShortName::kVec3F:
|
||||
return out << "vec3f";
|
||||
case ShortName::kVec3H:
|
||||
return out << "vec3h";
|
||||
case ShortName::kVec3I:
|
||||
return out << "vec3i";
|
||||
case ShortName::kVec3U:
|
||||
return out << "vec3u";
|
||||
case ShortName::kVec4F:
|
||||
return out << "vec4f";
|
||||
case ShortName::kVec4H:
|
||||
return out << "vec4h";
|
||||
case ShortName::kVec4I:
|
||||
return out << "vec4i";
|
||||
case ShortName::kVec4U:
|
||||
return out << "vec4u";
|
||||
}
|
||||
return out << "<unknown>";
|
||||
}
|
||||
|
||||
} // namespace tint::type
|
||||
25
src/tint/type/short_name.cc.tmpl
Normal file
25
src/tint/type/short_name.cc.tmpl
Normal file
@@ -0,0 +1,25 @@
|
||||
{{- /*
|
||||
--------------------------------------------------------------------------------
|
||||
Template file for use with tools/src/cmd/gen to generate short_name.cc
|
||||
|
||||
To update the generated file, run:
|
||||
./tools/run gen
|
||||
|
||||
See:
|
||||
* tools/src/cmd/gen for structures used by this template
|
||||
* https://golang.org/pkg/text/template/ for documentation on the template syntax
|
||||
--------------------------------------------------------------------------------
|
||||
*/ -}}
|
||||
|
||||
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
|
||||
{{- $enum := (Sem.Enum "short_name") -}}
|
||||
|
||||
#include "src/tint/type/short_name.h"
|
||||
|
||||
namespace tint::type {
|
||||
|
||||
{{ Eval "ParseEnum" $enum}}
|
||||
|
||||
{{ Eval "EnumOStream" $enum}}
|
||||
|
||||
} // namespace tint::type
|
||||
64
src/tint/type/short_name.h
Normal file
64
src/tint/type/short_name.h
Normal file
@@ -0,0 +1,64 @@
|
||||
// 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.h.tmpl
|
||||
//
|
||||
// Do not modify this file directly
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SRC_TINT_TYPE_SHORT_NAME_H_
|
||||
#define SRC_TINT_TYPE_SHORT_NAME_H_
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace tint::type {
|
||||
|
||||
/// An enumerator of builtin type aliases.
|
||||
enum class ShortName {
|
||||
kUndefined,
|
||||
kVec2F,
|
||||
kVec2H,
|
||||
kVec2I,
|
||||
kVec2U,
|
||||
kVec3F,
|
||||
kVec3H,
|
||||
kVec3I,
|
||||
kVec3U,
|
||||
kVec4F,
|
||||
kVec4H,
|
||||
kVec4I,
|
||||
kVec4U,
|
||||
};
|
||||
|
||||
/// @param out the std::ostream to write to
|
||||
/// @param value the ShortName
|
||||
/// @returns `out` so calls can be chained
|
||||
std::ostream& operator<<(std::ostream& out, ShortName value);
|
||||
|
||||
/// ParseShortName parses a ShortName from a string.
|
||||
/// @param str the string to parse
|
||||
/// @returns the parsed enum, or ShortName::kUndefined if the string could not be parsed.
|
||||
ShortName ParseShortName(std::string_view str);
|
||||
|
||||
constexpr const char* kShortNameStrings[] = {
|
||||
"vec2f", "vec2h", "vec2i", "vec2u", "vec3f", "vec3h",
|
||||
"vec3i", "vec3u", "vec4f", "vec4h", "vec4i", "vec4u",
|
||||
};
|
||||
|
||||
} // namespace tint::type
|
||||
|
||||
#endif // SRC_TINT_TYPE_SHORT_NAME_H_
|
||||
29
src/tint/type/short_name.h.tmpl
Normal file
29
src/tint/type/short_name.h.tmpl
Normal file
@@ -0,0 +1,29 @@
|
||||
{{- /*
|
||||
--------------------------------------------------------------------------------
|
||||
Template file for use with tools/src/cmd/gen to generate short_name.h
|
||||
|
||||
To update the generated file, run:
|
||||
./tools/run gen
|
||||
|
||||
See:
|
||||
* tools/src/cmd/gen for structures used by this template
|
||||
* https://golang.org/pkg/text/template/ for documentation on the template syntax
|
||||
--------------------------------------------------------------------------------
|
||||
*/ -}}
|
||||
|
||||
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
|
||||
{{- $enum := (Sem.Enum "short_name") -}}
|
||||
|
||||
#ifndef SRC_TINT_TYPE_SHORT_NAME_H_
|
||||
#define SRC_TINT_TYPE_SHORT_NAME_H_
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace tint::type {
|
||||
|
||||
/// An enumerator of builtin type aliases.
|
||||
{{ Eval "DeclareEnum" $enum}}
|
||||
|
||||
} // namespace tint::type
|
||||
|
||||
#endif // SRC_TINT_TYPE_SHORT_NAME_H_
|
||||
57
src/tint/type/short_name_bench.cc
Normal file
57
src/tint/type/short_name_bench.cc
Normal file
@@ -0,0 +1,57 @@
|
||||
// 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_bench.cc.tmpl
|
||||
//
|
||||
// Do not modify this file directly
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "src/tint/type/short_name.h"
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "benchmark/benchmark.h"
|
||||
|
||||
namespace tint::type {
|
||||
namespace {
|
||||
|
||||
void ShortNameParser(::benchmark::State& state) {
|
||||
std::array kStrings{
|
||||
"veccf", "32", "vVc2f", "vec2f", "vec21", "qqeJf", "vecll7f", "veqH2pp",
|
||||
"vh", "Gebh", "vec2h", "vevi2h", "ve8WWh", "Mxxc2", "vgg2i", "V2X",
|
||||
"vec23", "vec2i", "vec2E", "TTeP2i", "vxxcdd", "v44c2u", "veVVSSu", "22RRu",
|
||||
"vec2u", "vF2u", "vecu", "ROOHVu", "ecyf", "n77rrlcGf", "vec340", "vec3f",
|
||||
"oof", "vezz", "1ipp3f", "XXec3h", "ve9IInn5h", "HHreSSaYh", "vec3h", "kk3",
|
||||
"jgRR", "veb", "vjc3i", "vc3i", "vcq", "vec3i", "Nec3i", "vcvv",
|
||||
"ve3QQ", "vrcf", "vecju", "NNew23", "vec3u", "ve3u", "vrrc3u", "Gec3u",
|
||||
"veFF4f", "vE", "verrf", "vec4f", "vef", "veJJD", "v4", "e4k",
|
||||
"vech", "Jech", "vec4h", "ec4h", "_KKttcH", "vexxh", "__qcF", "vc4qq",
|
||||
"33e64i", "vec4i", "6QQott4i", "v6c4i", "zzc4O6", "vyyc4u", "vcZZ", "ecWq4u",
|
||||
"vec4u", "vOO4u", "oYe4", "v4",
|
||||
};
|
||||
for (auto _ : state) {
|
||||
for (auto& str : kStrings) {
|
||||
auto result = ParseShortName(str);
|
||||
benchmark::DoNotOptimize(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK(ShortNameParser);
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::type
|
||||
29
src/tint/type/short_name_bench.cc.tmpl
Normal file
29
src/tint/type/short_name_bench.cc.tmpl
Normal file
@@ -0,0 +1,29 @@
|
||||
{{- /*
|
||||
--------------------------------------------------------------------------------
|
||||
Template file for use with tools/src/cmd/gen to generate short_name_bench.cc
|
||||
|
||||
To update the generated file, run:
|
||||
./tools/run gen
|
||||
|
||||
See:
|
||||
* tools/src/cmd/gen for structures used by this template
|
||||
* https://golang.org/pkg/text/template/ for documentation on the template syntax
|
||||
--------------------------------------------------------------------------------
|
||||
*/ -}}
|
||||
|
||||
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
|
||||
{{- $enum := (Sem.Enum "short_name") -}}
|
||||
|
||||
#include "src/tint/type/short_name.h"
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "benchmark/benchmark.h"
|
||||
|
||||
namespace tint::type {
|
||||
namespace {
|
||||
|
||||
{{ Eval "BenchmarkParseEnum" $enum }}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::type
|
||||
97
src/tint/type/short_name_test.cc
Normal file
97
src/tint/type/short_name_test.cc
Normal file
@@ -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
|
||||
31
src/tint/type/short_name_test.cc.tmpl
Normal file
31
src/tint/type/short_name_test.cc.tmpl
Normal file
@@ -0,0 +1,31 @@
|
||||
{{- /*
|
||||
--------------------------------------------------------------------------------
|
||||
Template file for use with tools/src/cmd/gen to generate short_name_test.cc
|
||||
|
||||
To update the generated file, run:
|
||||
./tools/run gen
|
||||
|
||||
See:
|
||||
* tools/src/cmd/gen for structures used by this template
|
||||
* https://golang.org/pkg/text/template/ for documentation on the template syntax
|
||||
--------------------------------------------------------------------------------
|
||||
*/ -}}
|
||||
|
||||
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
|
||||
{{- $enum := (Sem.Enum "short_name") -}}
|
||||
|
||||
#include "src/tint/type/short_name.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "src/tint/utils/string.h"
|
||||
|
||||
namespace tint::type {
|
||||
namespace {
|
||||
|
||||
{{ Eval "TestParsePrintEnum" $enum}}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::type
|
||||
Reference in New Issue
Block a user