mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 02:39:11 +00:00
tint/ast: Clean up StorageClass enum
Remove unused enum entries. Add a ParseStorageClass() function. Have the WGSL parser use this. First step to standardizing the way we parse enum-backed token sets. Change-Id: I31c02816493beeabda740ff43946edce097f5fd1 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97148 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
ce8876074f
commit
48085845bd
@@ -16,34 +16,52 @@
|
||||
|
||||
namespace tint::ast {
|
||||
|
||||
const char* ToString(StorageClass sc) {
|
||||
switch (sc) {
|
||||
case StorageClass::kInvalid:
|
||||
return "invalid";
|
||||
case StorageClass::kNone:
|
||||
return "none";
|
||||
case StorageClass::kInput:
|
||||
return "in";
|
||||
case StorageClass::kOutput:
|
||||
return "out";
|
||||
case StorageClass::kUniform:
|
||||
return "uniform";
|
||||
case StorageClass::kWorkgroup:
|
||||
return "workgroup";
|
||||
case StorageClass::kHandle:
|
||||
return "handle";
|
||||
case StorageClass::kStorage:
|
||||
return "storage";
|
||||
case StorageClass::kPrivate:
|
||||
return "private";
|
||||
case StorageClass::kFunction:
|
||||
return "function";
|
||||
/// ParseStorageClass parses a StorageClass from a string.
|
||||
/// @param str the string to parse
|
||||
/// @returns the parsed enum, or StorageClass::kInvalid if the string could not be parsed.
|
||||
StorageClass ParseStorageClass(std::string_view str) {
|
||||
if (str == "function") {
|
||||
return StorageClass::kFunction;
|
||||
}
|
||||
return "<unknown>";
|
||||
if (str == "private") {
|
||||
return StorageClass::kPrivate;
|
||||
}
|
||||
if (str == "workgroup") {
|
||||
return StorageClass::kWorkgroup;
|
||||
}
|
||||
if (str == "uniform") {
|
||||
return StorageClass::kUniform;
|
||||
}
|
||||
if (str == "storage") {
|
||||
return StorageClass::kStorage;
|
||||
}
|
||||
return StorageClass::kInvalid;
|
||||
}
|
||||
std::ostream& operator<<(std::ostream& out, StorageClass sc) {
|
||||
out << ToString(sc);
|
||||
return out;
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, StorageClass value) {
|
||||
switch (value) {
|
||||
case StorageClass::kInvalid:
|
||||
return out << "invalid";
|
||||
case StorageClass::kNone:
|
||||
return out << "none";
|
||||
case StorageClass::kFunction:
|
||||
return out << "function";
|
||||
case StorageClass::kPrivate:
|
||||
return out << "private";
|
||||
case StorageClass::kWorkgroup:
|
||||
return out << "workgroup";
|
||||
case StorageClass::kUniform:
|
||||
return out << "uniform";
|
||||
case StorageClass::kStorage:
|
||||
return out << "storage";
|
||||
case StorageClass::kHandle:
|
||||
return out << "handle";
|
||||
case StorageClass::kIn:
|
||||
return out << "in";
|
||||
case StorageClass::kOut:
|
||||
return out << "out";
|
||||
}
|
||||
return out << "<unknown>";
|
||||
}
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
// 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.
|
||||
@@ -21,18 +21,28 @@ namespace tint::ast {
|
||||
|
||||
/// Storage class of a given pointer.
|
||||
enum class StorageClass {
|
||||
kInvalid = -1,
|
||||
kInvalid,
|
||||
kNone,
|
||||
kInput,
|
||||
kOutput,
|
||||
kUniform,
|
||||
kWorkgroup,
|
||||
kHandle,
|
||||
kStorage,
|
||||
kFunction,
|
||||
kPrivate,
|
||||
kFunction
|
||||
kWorkgroup,
|
||||
kUniform,
|
||||
kStorage,
|
||||
kHandle,
|
||||
kIn,
|
||||
kOut,
|
||||
};
|
||||
|
||||
/// @param out the std::ostream to write to
|
||||
/// @param sc the StorageClass
|
||||
/// @return the std::ostream so calls can be chained
|
||||
std::ostream& operator<<(std::ostream& out, StorageClass sc);
|
||||
|
||||
/// ParseStorageClass parses a StorageClass from a string.
|
||||
/// @param str the string to parse
|
||||
/// @returns the parsed enum, or StorageClass::kInvalid if the string could not be parsed.
|
||||
StorageClass ParseStorageClass(std::string_view str);
|
||||
|
||||
/// @returns true if the StorageClass is host-shareable
|
||||
/// @param sc the StorageClass
|
||||
/// @see https://gpuweb.github.io/gpuweb/wgsl.html#host-shareable
|
||||
@@ -40,15 +50,6 @@ inline bool IsHostShareable(StorageClass sc) {
|
||||
return sc == ast::StorageClass::kUniform || sc == ast::StorageClass::kStorage;
|
||||
}
|
||||
|
||||
/// @param sc the StorageClass
|
||||
/// @return the name of the given storage class
|
||||
const char* ToString(StorageClass sc);
|
||||
|
||||
/// @param out the std::ostream to write to
|
||||
/// @param sc the StorageClass
|
||||
/// @return the std::ostream so calls can be chained
|
||||
std::ostream& operator<<(std::ostream& out, StorageClass sc);
|
||||
|
||||
} // namespace tint::ast
|
||||
|
||||
#endif // SRC_TINT_AST_STORAGE_CLASS_H_
|
||||
|
||||
Reference in New Issue
Block a user