@@ -17,24 +17,6 @@ namespace llvm {
17
17
namespace hlsl {
18
18
namespace rootsig {
19
19
20
- template <typename T>
21
- static std::optional<StringRef> getEnumName (const T Value,
22
- ArrayRef<EnumEntry<T>> Enums) {
23
- for (const auto &EnumItem : Enums)
24
- if (EnumItem.Value == Value)
25
- return EnumItem.Name ;
26
- return std::nullopt;
27
- }
28
-
29
- template <typename T>
30
- static raw_ostream &printEnum (raw_ostream &OS, const T Value,
31
- ArrayRef<EnumEntry<T>> Enums) {
32
- auto MaybeName = getEnumName (Value, Enums);
33
- if (MaybeName)
34
- OS << *MaybeName;
35
- return OS;
36
- }
37
-
38
20
template <typename T>
39
21
static raw_ostream &printFlags (raw_ostream &OS, const T Value,
40
22
ArrayRef<EnumEntry<T>> Flags) {
@@ -46,9 +28,9 @@ static raw_ostream &printFlags(raw_ostream &OS, const T Value,
46
28
if (FlagSet)
47
29
OS << " | " ;
48
30
49
- auto MaybeFlag = getEnumName (T (Bit), Flags);
50
- if (MaybeFlag)
51
- OS << * MaybeFlag;
31
+ StringRef MaybeFlag = enumToStringRef (T (Bit), Flags);
32
+ if (0 < MaybeFlag. size () )
33
+ OS << MaybeFlag;
52
34
else
53
35
OS << " invalid: " << Bit;
54
36
@@ -70,43 +52,42 @@ static const EnumEntry<RegisterType> RegisterNames[] = {
70
52
};
71
53
72
54
static raw_ostream &operator <<(raw_ostream &OS, const Register &Reg) {
73
- printEnum (OS, Reg.ViewType , ArrayRef (RegisterNames));
74
- OS << Reg.Number ;
55
+ OS << enumToStringRef (Reg.ViewType , ArrayRef (RegisterNames)) << Reg.Number ;
75
56
76
57
return OS;
77
58
}
78
59
79
60
static raw_ostream &operator <<(raw_ostream &OS,
80
61
const llvm::dxbc::ShaderVisibility &Visibility) {
81
- printEnum (OS, Visibility, dxbc::getShaderVisibility ());
62
+ OS << enumToStringRef ( Visibility, dxbc::getShaderVisibility ());
82
63
83
64
return OS;
84
65
}
85
66
86
67
static raw_ostream &operator <<(raw_ostream &OS,
87
68
const llvm::dxbc::SamplerFilter &Filter) {
88
- printEnum (OS, Filter, dxbc::getSamplerFilters ());
69
+ OS << enumToStringRef ( Filter, dxbc::getSamplerFilters ());
89
70
90
71
return OS;
91
72
}
92
73
93
74
static raw_ostream &operator <<(raw_ostream &OS,
94
75
const dxbc::TextureAddressMode &Address) {
95
- printEnum (OS, Address, dxbc::getTextureAddressModes ());
76
+ OS << enumToStringRef ( Address, dxbc::getTextureAddressModes ());
96
77
97
78
return OS;
98
79
}
99
80
100
81
static raw_ostream &operator <<(raw_ostream &OS,
101
82
const dxbc::ComparisonFunc &CompFunc) {
102
- printEnum (OS, CompFunc, dxbc::getComparisonFuncs ());
83
+ OS << enumToStringRef ( CompFunc, dxbc::getComparisonFuncs ());
103
84
104
85
return OS;
105
86
}
106
87
107
88
static raw_ostream &operator <<(raw_ostream &OS,
108
89
const dxbc::StaticBorderColor &BorderColor) {
109
- printEnum (OS, BorderColor, dxbc::getStaticBorderColors ());
90
+ OS << enumToStringRef ( BorderColor, dxbc::getStaticBorderColors ());
110
91
111
92
return OS;
112
93
}
@@ -119,8 +100,8 @@ static const EnumEntry<dxil::ResourceClass> ResourceClassNames[] = {
119
100
};
120
101
121
102
static raw_ostream &operator <<(raw_ostream &OS, const ClauseType &Type) {
122
- printEnum (OS, dxil::ResourceClass (llvm::to_underlying (Type)),
123
- ArrayRef (ResourceClassNames));
103
+ OS << enumToStringRef ( dxil::ResourceClass (llvm::to_underlying (Type)),
104
+ ArrayRef (ResourceClassNames));
124
105
125
106
return OS;
126
107
}
0 commit comments