Mercurial > hg > CbC > CbC_llvm
comparison mlir/unittests/TableGen/EnumsGenTest.cpp @ 221:79ff65ed7e25
LLVM12 Original
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 15 Jun 2021 19:15:29 +0900 |
parents | 1d019706d866 |
children | c4bab56944e8 |
comparison
equal
deleted
inserted
replaced
220:42394fc6a535 | 221:79ff65ed7e25 |
---|---|
4 // See https://llvm.org/LICENSE.txt for license information. | 4 // See https://llvm.org/LICENSE.txt for license information. |
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 // | 6 // |
7 //===----------------------------------------------------------------------===// | 7 //===----------------------------------------------------------------------===// |
8 | 8 |
9 #include "mlir/IR/BuiltinAttributes.h" | |
10 #include "mlir/IR/BuiltinTypes.h" | |
11 #include "mlir/IR/MLIRContext.h" | |
12 #include "mlir/Support/LLVM.h" | |
13 | |
9 #include "llvm/ADT/DenseMap.h" | 14 #include "llvm/ADT/DenseMap.h" |
10 #include "llvm/ADT/Optional.h" | |
11 #include "llvm/ADT/SmallVector.h" | |
12 #include "llvm/ADT/StringExtras.h" | 15 #include "llvm/ADT/StringExtras.h" |
13 #include "llvm/ADT/StringSwitch.h" | 16 #include "llvm/ADT/StringSwitch.h" |
17 | |
14 #include "gmock/gmock.h" | 18 #include "gmock/gmock.h" |
19 | |
15 #include <type_traits> | 20 #include <type_traits> |
16 | 21 |
17 // Pull in generated enum utility declarations | 22 /// Pull in generated enum utility declarations and definitions. |
18 #include "EnumsGenTest.h.inc" | 23 #include "EnumsGenTest.h.inc" |
19 // And definitions | 24 |
20 #include "EnumsGenTest.cpp.inc" | 25 #include "EnumsGenTest.cpp.inc" |
21 | 26 |
22 // Test namespaces and enum class/utility names | 27 /// Test namespaces and enum class/utility names. |
23 using Outer::Inner::ConvertToEnum; | 28 using Outer::Inner::ConvertToEnum; |
24 using Outer::Inner::ConvertToString; | 29 using Outer::Inner::ConvertToString; |
25 using Outer::Inner::StrEnum; | 30 using Outer::Inner::StrEnum; |
31 using Outer::Inner::StrEnumAttr; | |
26 | 32 |
27 TEST(EnumsGenTest, GeneratedStrEnumDefinition) { | 33 TEST(EnumsGenTest, GeneratedStrEnumDefinition) { |
28 EXPECT_EQ(0u, static_cast<uint64_t>(StrEnum::CaseA)); | 34 EXPECT_EQ(0u, static_cast<uint64_t>(StrEnum::CaseA)); |
29 EXPECT_EQ(10u, static_cast<uint64_t>(StrEnum::CaseB)); | 35 EXPECT_EQ(10u, static_cast<uint64_t>(StrEnum::CaseB)); |
30 } | 36 } |
110 EXPECT_EQ(*two, PrettyIntEnum::Case2); | 116 EXPECT_EQ(*two, PrettyIntEnum::Case2); |
111 | 117 |
112 auto none = symbolizePrettyIntEnum("Case1"); | 118 auto none = symbolizePrettyIntEnum("Case1"); |
113 EXPECT_FALSE(none); | 119 EXPECT_FALSE(none); |
114 } | 120 } |
121 | |
122 TEST(EnumsGenTest, GeneratedIntAttributeClass) { | |
123 mlir::MLIRContext ctx; | |
124 I32Enum rawVal = I32Enum::Case5; | |
125 | |
126 I32EnumAttr enumAttr = I32EnumAttr::get(&ctx, rawVal); | |
127 EXPECT_NE(enumAttr, nullptr); | |
128 EXPECT_EQ(enumAttr.getValue(), rawVal); | |
129 | |
130 mlir::Type intType = mlir::IntegerType::get(&ctx, 32); | |
131 mlir::Attribute intAttr = mlir::IntegerAttr::get(intType, 5); | |
132 EXPECT_TRUE(intAttr.isa<I32EnumAttr>()); | |
133 EXPECT_EQ(intAttr, enumAttr); | |
134 } | |
135 | |
136 TEST(EnumsGenTest, GeneratedStringAttributeClass) { | |
137 mlir::MLIRContext ctx; | |
138 StrEnum rawVal = StrEnum::CaseA; | |
139 | |
140 StrEnumAttr enumAttr = StrEnumAttr::get(&ctx, rawVal); | |
141 EXPECT_NE(enumAttr, nullptr); | |
142 EXPECT_EQ(enumAttr.getValue(), rawVal); | |
143 | |
144 mlir::Attribute strAttr = mlir::StringAttr::get(&ctx, "CaseA"); | |
145 EXPECT_TRUE(strAttr.isa<StrEnumAttr>()); | |
146 EXPECT_EQ(strAttr, enumAttr); | |
147 } | |
148 | |
149 TEST(EnumsGenTest, GeneratedBitAttributeClass) { | |
150 mlir::MLIRContext ctx; | |
151 | |
152 mlir::Type intType = mlir::IntegerType::get(&ctx, 32); | |
153 mlir::Attribute intAttr = mlir::IntegerAttr::get( | |
154 intType, | |
155 static_cast<uint32_t>(BitEnumWithNone::Bit1 | BitEnumWithNone::Bit3)); | |
156 EXPECT_TRUE(intAttr.isa<BitEnumWithNoneAttr>()); | |
157 EXPECT_TRUE(intAttr.isa<BitEnumWithoutNoneAttr>()); | |
158 } |