-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[NFC][HLSL] Replace uses of getResourceName
/printEnum
#152211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,24 +17,6 @@ namespace llvm { | |
namespace hlsl { | ||
namespace rootsig { | ||
|
||
template <typename T> | ||
static std::optional<StringRef> getEnumName(const T Value, | ||
ArrayRef<EnumEntry<T>> Enums) { | ||
for (const auto &EnumItem : Enums) | ||
if (EnumItem.Value == Value) | ||
return EnumItem.Name; | ||
return std::nullopt; | ||
} | ||
|
||
template <typename T> | ||
static raw_ostream &printEnum(raw_ostream &OS, const T Value, | ||
ArrayRef<EnumEntry<T>> Enums) { | ||
auto MaybeName = getEnumName(Value, Enums); | ||
if (MaybeName) | ||
OS << *MaybeName; | ||
return OS; | ||
} | ||
|
||
template <typename T> | ||
static raw_ostream &printFlags(raw_ostream &OS, const T Value, | ||
ArrayRef<EnumEntry<T>> Flags) { | ||
|
@@ -46,9 +28,9 @@ static raw_ostream &printFlags(raw_ostream &OS, const T Value, | |
if (FlagSet) | ||
OS << " | "; | ||
|
||
auto MaybeFlag = getEnumName(T(Bit), Flags); | ||
if (MaybeFlag) | ||
OS << *MaybeFlag; | ||
StringRef MaybeFlag = enumToStringRef(T(Bit), Flags); | ||
if (0 < MaybeFlag.size()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a very strange way to write this check. Using an std::optional lets you keep the more typical There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (this applies anywhere you have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively the current code could be written as I don't have strong feelings one way or another but empty strings for optional strings is pretty common. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah fair enough. Checking for |
||
OS << MaybeFlag; | ||
else | ||
OS << "invalid: " << Bit; | ||
|
||
|
@@ -70,43 +52,42 @@ static const EnumEntry<RegisterType> RegisterNames[] = { | |
}; | ||
|
||
static raw_ostream &operator<<(raw_ostream &OS, const Register &Reg) { | ||
printEnum(OS, Reg.ViewType, ArrayRef(RegisterNames)); | ||
OS << Reg.Number; | ||
OS << enumToStringRef(Reg.ViewType, ArrayRef(RegisterNames)) << Reg.Number; | ||
|
||
return OS; | ||
} | ||
|
||
static raw_ostream &operator<<(raw_ostream &OS, | ||
const llvm::dxbc::ShaderVisibility &Visibility) { | ||
printEnum(OS, Visibility, dxbc::getShaderVisibility()); | ||
OS << enumToStringRef(Visibility, dxbc::getShaderVisibility()); | ||
|
||
return OS; | ||
} | ||
|
||
static raw_ostream &operator<<(raw_ostream &OS, | ||
const llvm::dxbc::SamplerFilter &Filter) { | ||
printEnum(OS, Filter, dxbc::getSamplerFilters()); | ||
OS << enumToStringRef(Filter, dxbc::getSamplerFilters()); | ||
|
||
return OS; | ||
} | ||
|
||
static raw_ostream &operator<<(raw_ostream &OS, | ||
const dxbc::TextureAddressMode &Address) { | ||
printEnum(OS, Address, dxbc::getTextureAddressModes()); | ||
OS << enumToStringRef(Address, dxbc::getTextureAddressModes()); | ||
|
||
return OS; | ||
} | ||
|
||
static raw_ostream &operator<<(raw_ostream &OS, | ||
const dxbc::ComparisonFunc &CompFunc) { | ||
printEnum(OS, CompFunc, dxbc::getComparisonFuncs()); | ||
OS << enumToStringRef(CompFunc, dxbc::getComparisonFuncs()); | ||
|
||
return OS; | ||
} | ||
|
||
static raw_ostream &operator<<(raw_ostream &OS, | ||
const dxbc::StaticBorderColor &BorderColor) { | ||
printEnum(OS, BorderColor, dxbc::getStaticBorderColors()); | ||
OS << enumToStringRef(BorderColor, dxbc::getStaticBorderColors()); | ||
|
||
return OS; | ||
} | ||
|
@@ -119,8 +100,8 @@ static const EnumEntry<dxil::ResourceClass> ResourceClassNames[] = { | |
}; | ||
|
||
static raw_ostream &operator<<(raw_ostream &OS, const ClauseType &Type) { | ||
printEnum(OS, dxil::ResourceClass(llvm::to_underlying(Type)), | ||
ArrayRef(ResourceClassNames)); | ||
OS << enumToStringRef(dxil::ResourceClass(llvm::to_underlying(Type)), | ||
ArrayRef(ResourceClassNames)); | ||
|
||
return OS; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is probably useful to add a doxygen comment block above this API explaining that it returns an empty string if the enum doesn't have a direct mapping.