19
19
#include " llvm/Support/Endian.h"
20
20
#include " llvm/Support/JSON.h"
21
21
#include " llvm/Support/raw_ostream.h"
22
+ #include < type_traits>
22
23
23
24
namespace llvm {
24
25
@@ -41,8 +42,8 @@ template <typename T> struct EnumEntry {
41
42
struct HexNumber {
42
43
// To avoid sign-extension we have to explicitly cast to the appropriate
43
44
// unsigned type. The overloads are here so that every type that is implicitly
44
- // convertible to an integer (including enums and endian helpers) can be used
45
- // without requiring type traits or call-site changes.
45
+ // convertible to an integer (including endian helpers) can be used without
46
+ // requiring type traits or call-site changes.
46
47
HexNumber (char Value) : Value(static_cast <unsigned char >(Value)) {}
47
48
HexNumber (signed char Value) : Value(static_cast <unsigned char >(Value)) {}
48
49
HexNumber (signed short Value) : Value(static_cast <unsigned short >(Value)) {}
@@ -55,6 +56,10 @@ struct HexNumber {
55
56
HexNumber (unsigned int Value) : Value(Value) {}
56
57
HexNumber (unsigned long Value) : Value(Value) {}
57
58
HexNumber (unsigned long long Value) : Value(Value) {}
59
+ template <typename EnumT, typename = std::enable_if_t <std::is_enum_v<EnumT>>>
60
+ HexNumber (EnumT Value)
61
+ : HexNumber(static_cast <std::underlying_type_t <EnumT>>(Value)) {}
62
+
58
63
uint64_t Value;
59
64
};
60
65
@@ -77,6 +82,10 @@ struct FlagEntry {
77
82
FlagEntry (StringRef Name, unsigned long Value) : Name(Name), Value(Value) {}
78
83
FlagEntry (StringRef Name, unsigned long long Value)
79
84
: Name(Name), Value(Value) {}
85
+ template <typename EnumT, typename = std::enable_if_t <std::is_enum_v<EnumT>>>
86
+ FlagEntry (StringRef Name, EnumT Value)
87
+ : FlagEntry(Name, static_cast <std::underlying_type_t <EnumT>>(Value)) {}
88
+
80
89
StringRef Name;
81
90
uint64_t Value;
82
91
};
@@ -165,17 +174,17 @@ class LLVM_ABI ScopedPrinter {
165
174
SmallVector<FlagEntry, 10 > SetFlags (ExtraFlags);
166
175
167
176
for (const auto &Flag : Flags) {
168
- if (Flag.Value == 0 )
177
+ if (Flag.Value == TFlag{} )
169
178
continue ;
170
179
171
180
TFlag EnumMask{};
172
- if (Flag.Value & EnumMask1)
181
+ if (( Flag.Value & EnumMask1) != TFlag{} )
173
182
EnumMask = EnumMask1;
174
- else if (Flag.Value & EnumMask2)
183
+ else if (( Flag.Value & EnumMask2) != TFlag{} )
175
184
EnumMask = EnumMask2;
176
- else if (Flag.Value & EnumMask3)
185
+ else if (( Flag.Value & EnumMask3) != TFlag{} )
177
186
EnumMask = EnumMask3;
178
- bool IsEnum = (Flag.Value & EnumMask) != 0 ;
187
+ bool IsEnum = (Flag.Value & EnumMask) != TFlag{} ;
179
188
if ((!IsEnum && (Value & Flag.Value ) == Flag.Value ) ||
180
189
(IsEnum && (Value & EnumMask) == Flag.Value )) {
181
190
SetFlags.emplace_back (Flag.Name , Flag.Value );
0 commit comments