comparison mlir/unittests/TableGen/EnumsGenTest.cpp @ 252:1f2b6ac9f198 llvm-original

LLVM16-1
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 18 Aug 2023 09:04:13 +0900
parents c4bab56944e8
children
comparison
equal deleted inserted replaced
237:c80f45b162ad 252:1f2b6ac9f198
52 EXPECT_EQ(ConvertToString(FooEnum::CaseA), "CaseA"); 52 EXPECT_EQ(ConvertToString(FooEnum::CaseA), "CaseA");
53 EXPECT_EQ(ConvertToString(FooEnum::CaseB), "CaseB"); 53 EXPECT_EQ(ConvertToString(FooEnum::CaseB), "CaseB");
54 } 54 }
55 55
56 TEST(EnumsGenTest, GeneratedStringToSymbolFn) { 56 TEST(EnumsGenTest, GeneratedStringToSymbolFn) {
57 EXPECT_EQ(llvm::Optional<FooEnum>(FooEnum::CaseA), ConvertToEnum("CaseA")); 57 EXPECT_EQ(std::optional<FooEnum>(FooEnum::CaseA), ConvertToEnum("CaseA"));
58 EXPECT_EQ(llvm::Optional<FooEnum>(FooEnum::CaseB), ConvertToEnum("CaseB")); 58 EXPECT_EQ(std::optional<FooEnum>(FooEnum::CaseB), ConvertToEnum("CaseB"));
59 EXPECT_EQ(llvm::None, ConvertToEnum("X")); 59 EXPECT_EQ(std::nullopt, ConvertToEnum("X"));
60 } 60 }
61 61
62 TEST(EnumsGenTest, GeneratedUnderlyingType) { 62 TEST(EnumsGenTest, GeneratedUnderlyingType) {
63 bool v = std::is_same<uint32_t, std::underlying_type<I32Enum>::type>::value; 63 bool v = std::is_same<uint32_t, std::underlying_type<I32Enum>::type>::value;
64 EXPECT_TRUE(v); 64 EXPECT_TRUE(v);
92 EXPECT_EQ(symbolizeBitEnumWithNone("Bit0"), BitEnumWithNone::Bit0); 92 EXPECT_EQ(symbolizeBitEnumWithNone("Bit0"), BitEnumWithNone::Bit0);
93 EXPECT_EQ(symbolizeBitEnumWithNone("Bit3"), BitEnumWithNone::Bit3); 93 EXPECT_EQ(symbolizeBitEnumWithNone("Bit3"), BitEnumWithNone::Bit3);
94 EXPECT_EQ(symbolizeBitEnumWithNone("Bit3|Bit0"), 94 EXPECT_EQ(symbolizeBitEnumWithNone("Bit3|Bit0"),
95 BitEnumWithNone::Bit3 | BitEnumWithNone::Bit0); 95 BitEnumWithNone::Bit3 | BitEnumWithNone::Bit0);
96 96
97 EXPECT_EQ(symbolizeBitEnumWithNone("Bit2"), llvm::None); 97 EXPECT_EQ(symbolizeBitEnumWithNone("Bit2"), std::nullopt);
98 EXPECT_EQ(symbolizeBitEnumWithNone("Bit3 | Bit4"), llvm::None); 98 EXPECT_EQ(symbolizeBitEnumWithNone("Bit3 | Bit4"), std::nullopt);
99 99
100 EXPECT_EQ(symbolizeBitEnumWithoutNone("None"), llvm::None); 100 EXPECT_EQ(symbolizeBitEnumWithoutNone("None"), std::nullopt);
101 } 101 }
102 102
103 TEST(EnumsGenTest, GeneratedSymbolToStringFnForGroupedBitEnum) { 103 TEST(EnumsGenTest, GeneratedSymbolToStringFnForGroupedBitEnum) {
104 EXPECT_EQ(stringifyBitEnumWithGroup(BitEnumWithGroup::Bit0), "Bit0"); 104 EXPECT_EQ(stringifyBitEnumWithGroup(BitEnumWithGroup::Bit0), "Bit0");
105 EXPECT_EQ(stringifyBitEnumWithGroup(BitEnumWithGroup::Bit3), "Bit3"); 105 EXPECT_EQ(stringifyBitEnumWithGroup(BitEnumWithGroup::Bit3), "Bit3");
113 } 113 }
114 114
115 TEST(EnumsGenTest, GeneratedStringToSymbolForGroupedBitEnum) { 115 TEST(EnumsGenTest, GeneratedStringToSymbolForGroupedBitEnum) {
116 EXPECT_EQ(symbolizeBitEnumWithGroup("Bit0"), BitEnumWithGroup::Bit0); 116 EXPECT_EQ(symbolizeBitEnumWithGroup("Bit0"), BitEnumWithGroup::Bit0);
117 EXPECT_EQ(symbolizeBitEnumWithGroup("Bit3"), BitEnumWithGroup::Bit3); 117 EXPECT_EQ(symbolizeBitEnumWithGroup("Bit3"), BitEnumWithGroup::Bit3);
118 EXPECT_EQ(symbolizeBitEnumWithGroup("Bit5"), llvm::None); 118 EXPECT_EQ(symbolizeBitEnumWithGroup("Bit5"), std::nullopt);
119 EXPECT_EQ(symbolizeBitEnumWithGroup("Bit3|Bit0"), 119 EXPECT_EQ(symbolizeBitEnumWithGroup("Bit3|Bit0"),
120 BitEnumWithGroup::Bit3 | BitEnumWithGroup::Bit0); 120 BitEnumWithGroup::Bit3 | BitEnumWithGroup::Bit0);
121 } 121 }
122 122
123 TEST(EnumsGenTest, GeneratedSymbolToStringFnForPrimaryGroupBitEnum) { 123 TEST(EnumsGenTest, GeneratedSymbolToStringFnForPrimaryGroupBitEnum) {
173 EXPECT_NE(enumAttr, nullptr); 173 EXPECT_NE(enumAttr, nullptr);
174 EXPECT_EQ(enumAttr.getValue(), rawVal); 174 EXPECT_EQ(enumAttr.getValue(), rawVal);
175 175
176 mlir::Type intType = mlir::IntegerType::get(&ctx, 32); 176 mlir::Type intType = mlir::IntegerType::get(&ctx, 32);
177 mlir::Attribute intAttr = mlir::IntegerAttr::get(intType, 5); 177 mlir::Attribute intAttr = mlir::IntegerAttr::get(intType, 5);
178 EXPECT_TRUE(intAttr.isa<I32EnumAttr>()); 178 EXPECT_TRUE(llvm::isa<I32EnumAttr>(intAttr));
179 EXPECT_EQ(intAttr, enumAttr); 179 EXPECT_EQ(intAttr, enumAttr);
180 } 180 }
181 181
182 TEST(EnumsGenTest, GeneratedBitAttributeClass) { 182 TEST(EnumsGenTest, GeneratedBitAttributeClass) {
183 mlir::MLIRContext ctx; 183 mlir::MLIRContext ctx;
184 184
185 mlir::Type intType = mlir::IntegerType::get(&ctx, 32); 185 mlir::Type intType = mlir::IntegerType::get(&ctx, 32);
186 mlir::Attribute intAttr = mlir::IntegerAttr::get( 186 mlir::Attribute intAttr = mlir::IntegerAttr::get(
187 intType, 187 intType,
188 static_cast<uint32_t>(BitEnumWithNone::Bit0 | BitEnumWithNone::Bit3)); 188 static_cast<uint32_t>(BitEnumWithNone::Bit0 | BitEnumWithNone::Bit3));
189 EXPECT_TRUE(intAttr.isa<BitEnumWithNoneAttr>()); 189 EXPECT_TRUE(llvm::isa<BitEnumWithNoneAttr>(intAttr));
190 EXPECT_TRUE(intAttr.isa<BitEnumWithoutNoneAttr>()); 190 EXPECT_TRUE(llvm::isa<BitEnumWithoutNoneAttr>(intAttr));
191 191
192 intAttr = mlir::IntegerAttr::get( 192 intAttr = mlir::IntegerAttr::get(
193 intType, static_cast<uint32_t>(BitEnumWithGroup::Bits0To3) | (1u << 6)); 193 intType, static_cast<uint32_t>(BitEnumWithGroup::Bits0To3) | (1u << 6));
194 EXPECT_FALSE(intAttr.isa<BitEnumWithGroupAttr>()); 194 EXPECT_FALSE(llvm::isa<BitEnumWithGroupAttr>(intAttr));
195 } 195 }