From b7aef033fa73937cbc837478d9244999df26257d Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Tue, 11 Oct 2022 19:29:11 +0000 Subject: [PATCH] tint/templates: Generate enum string arrays This will be useful for emitting possible enum values when an enum fails to parse. Bug: tint:1629 Change-Id: I0be177a2bc27962580f4465ec18fdc5f2e930a99 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/105322 Reviewed-by: Dan Sinclair Kokoro: Kokoro Commit-Queue: Ben Clayton --- src/tint/ast/address_space.h | 4 ++++ src/tint/ast/builtin_value.h | 9 +++++++++ src/tint/ast/extension.h | 7 +++++++ src/tint/ast/texel_format.h | 6 ++++++ src/tint/templates/enums.tmpl.inc | 8 ++++++++ 5 files changed, 34 insertions(+) diff --git a/src/tint/ast/address_space.h b/src/tint/ast/address_space.h index 9ff471dc3f..8b96f0f26c 100644 --- a/src/tint/ast/address_space.h +++ b/src/tint/ast/address_space.h @@ -52,6 +52,10 @@ std::ostream& operator<<(std::ostream& out, AddressSpace value); /// @returns the parsed enum, or AddressSpace::kInvalid if the string could not be parsed. AddressSpace ParseAddressSpace(std::string_view str); +constexpr const char* kAddressSpaceStrings[] = { + "function", "private", "push_constant", "storage", "uniform", "workgroup", +}; + /// @returns true if the AddressSpace is host-shareable /// @param address_space the AddressSpace /// @see https://gpuweb.github.io/gpuweb/wgsl.html#host-shareable diff --git a/src/tint/ast/builtin_value.h b/src/tint/ast/builtin_value.h index 06bedf3fb2..eb45b39b10 100644 --- a/src/tint/ast/builtin_value.h +++ b/src/tint/ast/builtin_value.h @@ -55,6 +55,15 @@ std::ostream& operator<<(std::ostream& out, BuiltinValue value); /// @returns the parsed enum, or BuiltinValue::kInvalid if the string could not be parsed. BuiltinValue ParseBuiltinValue(std::string_view str); +constexpr const char* kBuiltinValueStrings[] = { + "frag_depth", "front_facing", + "global_invocation_id", "instance_index", + "local_invocation_id", "local_invocation_index", + "num_workgroups", "position", + "sample_index", "sample_mask", + "vertex_index", "workgroup_id", +}; + } // namespace tint::ast #endif // SRC_TINT_AST_BUILTIN_VALUE_H_ diff --git a/src/tint/ast/extension.h b/src/tint/ast/extension.h index 9d1c96a3fe..4d1a93770e 100644 --- a/src/tint/ast/extension.h +++ b/src/tint/ast/extension.h @@ -49,6 +49,13 @@ std::ostream& operator<<(std::ostream& out, Extension value); /// @returns the parsed enum, or Extension::kInvalid if the string could not be parsed. Extension ParseExtension(std::string_view str); +constexpr const char* kExtensionStrings[] = { + "chromium_disable_uniformity_analysis", + "chromium_experimental_dp4a", + "chromium_experimental_push_constant", + "f16", +}; + // A unique vector of extensions using Extensions = utils::UniqueVector; diff --git a/src/tint/ast/texel_format.h b/src/tint/ast/texel_format.h index ed1e32695c..9c65fb6ad2 100644 --- a/src/tint/ast/texel_format.h +++ b/src/tint/ast/texel_format.h @@ -58,6 +58,12 @@ std::ostream& operator<<(std::ostream& out, TexelFormat value); /// @returns the parsed enum, or TexelFormat::kInvalid if the string could not be parsed. TexelFormat ParseTexelFormat(std::string_view str); +constexpr const char* kTexelFormatStrings[] = { + "r32float", "r32sint", "r32uint", "rg32float", "rg32sint", "rg32uint", + "rgba16float", "rgba16sint", "rgba16uint", "rgba32float", "rgba32sint", "rgba32uint", + "rgba8sint", "rgba8snorm", "rgba8uint", "rgba8unorm", +}; + } // namespace tint::ast #endif // SRC_TINT_AST_TEXEL_FORMAT_H_ diff --git a/src/tint/templates/enums.tmpl.inc b/src/tint/templates/enums.tmpl.inc index d05d76331d..4726d80c09 100644 --- a/src/tint/templates/enums.tmpl.inc +++ b/src/tint/templates/enums.tmpl.inc @@ -28,6 +28,14 @@ std::ostream& operator<<(std::ostream& out, {{$enum}} value); /// @returns the parsed enum, or {{$enum}}::kInvalid if the string could not be parsed. {{$enum}} Parse{{$enum}}(std::string_view str); +constexpr const char* k{{$enum}}Strings[] = { +{{- range $entry := $.Entries }} +{{- if not $entry.IsInternal}} + "{{$entry.Name}}", +{{- end }} +{{- end }} +}; + {{- end -}}