1 //===- pdl.c - Test of PDL dialect C API ----------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 // RUN: mlir-capi-pdl-test 2>&1 | FileCheck %s
12 #include "mlir-c/Dialect/PDL.h"
13 #include "mlir-c/BuiltinTypes.h"
14 #include "mlir-c/IR.h"
21 // CHECK-LABEL: testAttributeType
22 void testAttributeType(MlirContext ctx
) {
23 fprintf(stderr
, "testAttributeType\n");
25 MlirType parsedType
= mlirTypeParseGet(
26 ctx
, mlirStringRefCreateFromCString("!pdl.attribute"));
27 MlirType constructedType
= mlirPDLAttributeTypeGet(ctx
);
29 assert(!mlirTypeIsNull(parsedType
) && "couldn't parse PDLAttributeType");
30 assert(!mlirTypeIsNull(constructedType
) && "couldn't construct PDLAttributeType");
32 // CHECK: parsedType isa PDLType: 1
33 fprintf(stderr
, "parsedType isa PDLType: %d\n",
34 mlirTypeIsAPDLType(parsedType
));
35 // CHECK: parsedType isa PDLAttributeType: 1
36 fprintf(stderr
, "parsedType isa PDLAttributeType: %d\n",
37 mlirTypeIsAPDLAttributeType(parsedType
));
38 // CHECK: parsedType isa PDLOperationType: 0
39 fprintf(stderr
, "parsedType isa PDLOperationType: %d\n",
40 mlirTypeIsAPDLOperationType(parsedType
));
41 // CHECK: parsedType isa PDLRangeType: 0
42 fprintf(stderr
, "parsedType isa PDLRangeType: %d\n",
43 mlirTypeIsAPDLRangeType(parsedType
));
44 // CHECK: parsedType isa PDLTypeType: 0
45 fprintf(stderr
, "parsedType isa PDLTypeType: %d\n",
46 mlirTypeIsAPDLTypeType(parsedType
));
47 // CHECK: parsedType isa PDLValueType: 0
48 fprintf(stderr
, "parsedType isa PDLValueType: %d\n",
49 mlirTypeIsAPDLValueType(parsedType
));
51 // CHECK: constructedType isa PDLType: 1
52 fprintf(stderr
, "constructedType isa PDLType: %d\n",
53 mlirTypeIsAPDLType(constructedType
));
54 // CHECK: constructedType isa PDLAttributeType: 1
55 fprintf(stderr
, "constructedType isa PDLAttributeType: %d\n",
56 mlirTypeIsAPDLAttributeType(constructedType
));
57 // CHECK: constructedType isa PDLOperationType: 0
58 fprintf(stderr
, "constructedType isa PDLOperationType: %d\n",
59 mlirTypeIsAPDLOperationType(constructedType
));
60 // CHECK: constructedType isa PDLRangeType: 0
61 fprintf(stderr
, "constructedType isa PDLRangeType: %d\n",
62 mlirTypeIsAPDLRangeType(constructedType
));
63 // CHECK: constructedType isa PDLTypeType: 0
64 fprintf(stderr
, "constructedType isa PDLTypeType: %d\n",
65 mlirTypeIsAPDLTypeType(constructedType
));
66 // CHECK: constructedType isa PDLValueType: 0
67 fprintf(stderr
, "constructedType isa PDLValueType: %d\n",
68 mlirTypeIsAPDLValueType(constructedType
));
71 fprintf(stderr
, "equal: %d\n", mlirTypeEqual(parsedType
, constructedType
));
73 // CHECK: !pdl.attribute
74 mlirTypeDump(parsedType
);
75 // CHECK: !pdl.attribute
76 mlirTypeDump(constructedType
);
78 fprintf(stderr
, "\n\n");
81 // CHECK-LABEL: testOperationType
82 void testOperationType(MlirContext ctx
) {
83 fprintf(stderr
, "testOperationType\n");
85 MlirType parsedType
= mlirTypeParseGet(
86 ctx
, mlirStringRefCreateFromCString("!pdl.operation"));
87 MlirType constructedType
= mlirPDLOperationTypeGet(ctx
);
89 assert(!mlirTypeIsNull(parsedType
) && "couldn't parse PDLAttributeType");
90 assert(!mlirTypeIsNull(constructedType
) && "couldn't construct PDLAttributeType");
92 // CHECK: parsedType isa PDLType: 1
93 fprintf(stderr
, "parsedType isa PDLType: %d\n",
94 mlirTypeIsAPDLType(parsedType
));
95 // CHECK: parsedType isa PDLAttributeType: 0
96 fprintf(stderr
, "parsedType isa PDLAttributeType: %d\n",
97 mlirTypeIsAPDLAttributeType(parsedType
));
98 // CHECK: parsedType isa PDLOperationType: 1
99 fprintf(stderr
, "parsedType isa PDLOperationType: %d\n",
100 mlirTypeIsAPDLOperationType(parsedType
));
101 // CHECK: parsedType isa PDLRangeType: 0
102 fprintf(stderr
, "parsedType isa PDLRangeType: %d\n",
103 mlirTypeIsAPDLRangeType(parsedType
));
104 // CHECK: parsedType isa PDLTypeType: 0
105 fprintf(stderr
, "parsedType isa PDLTypeType: %d\n",
106 mlirTypeIsAPDLTypeType(parsedType
));
107 // CHECK: parsedType isa PDLValueType: 0
108 fprintf(stderr
, "parsedType isa PDLValueType: %d\n",
109 mlirTypeIsAPDLValueType(parsedType
));
111 // CHECK: constructedType isa PDLType: 1
112 fprintf(stderr
, "constructedType isa PDLType: %d\n",
113 mlirTypeIsAPDLType(constructedType
));
114 // CHECK: constructedType isa PDLAttributeType: 0
115 fprintf(stderr
, "constructedType isa PDLAttributeType: %d\n",
116 mlirTypeIsAPDLAttributeType(constructedType
));
117 // CHECK: constructedType isa PDLOperationType: 1
118 fprintf(stderr
, "constructedType isa PDLOperationType: %d\n",
119 mlirTypeIsAPDLOperationType(constructedType
));
120 // CHECK: constructedType isa PDLRangeType: 0
121 fprintf(stderr
, "constructedType isa PDLRangeType: %d\n",
122 mlirTypeIsAPDLRangeType(constructedType
));
123 // CHECK: constructedType isa PDLTypeType: 0
124 fprintf(stderr
, "constructedType isa PDLTypeType: %d\n",
125 mlirTypeIsAPDLTypeType(constructedType
));
126 // CHECK: constructedType isa PDLValueType: 0
127 fprintf(stderr
, "constructedType isa PDLValueType: %d\n",
128 mlirTypeIsAPDLValueType(constructedType
));
131 fprintf(stderr
, "equal: %d\n", mlirTypeEqual(parsedType
, constructedType
));
133 // CHECK: !pdl.operation
134 mlirTypeDump(parsedType
);
135 // CHECK: !pdl.operation
136 mlirTypeDump(constructedType
);
138 fprintf(stderr
, "\n\n");
141 // CHECK-LABEL: testRangeType
142 void testRangeType(MlirContext ctx
) {
143 fprintf(stderr
, "testRangeType\n");
145 MlirType typeType
= mlirPDLTypeTypeGet(ctx
);
146 MlirType parsedType
= mlirTypeParseGet(
147 ctx
, mlirStringRefCreateFromCString("!pdl.range<type>"));
148 MlirType constructedType
= mlirPDLRangeTypeGet(typeType
);
149 MlirType elementType
= mlirPDLRangeTypeGetElementType(constructedType
);
151 assert(!mlirTypeIsNull(typeType
) && "couldn't get PDLTypeType");
152 assert(!mlirTypeIsNull(parsedType
) && "couldn't parse PDLAttributeType");
153 assert(!mlirTypeIsNull(constructedType
) && "couldn't construct PDLAttributeType");
155 // CHECK: parsedType isa PDLType: 1
156 fprintf(stderr
, "parsedType isa PDLType: %d\n",
157 mlirTypeIsAPDLType(parsedType
));
158 // CHECK: parsedType isa PDLAttributeType: 0
159 fprintf(stderr
, "parsedType isa PDLAttributeType: %d\n",
160 mlirTypeIsAPDLAttributeType(parsedType
));
161 // CHECK: parsedType isa PDLOperationType: 0
162 fprintf(stderr
, "parsedType isa PDLOperationType: %d\n",
163 mlirTypeIsAPDLOperationType(parsedType
));
164 // CHECK: parsedType isa PDLRangeType: 1
165 fprintf(stderr
, "parsedType isa PDLRangeType: %d\n",
166 mlirTypeIsAPDLRangeType(parsedType
));
167 // CHECK: parsedType isa PDLTypeType: 0
168 fprintf(stderr
, "parsedType isa PDLTypeType: %d\n",
169 mlirTypeIsAPDLTypeType(parsedType
));
170 // CHECK: parsedType isa PDLValueType: 0
171 fprintf(stderr
, "parsedType isa PDLValueType: %d\n",
172 mlirTypeIsAPDLValueType(parsedType
));
174 // CHECK: constructedType isa PDLType: 1
175 fprintf(stderr
, "constructedType isa PDLType: %d\n",
176 mlirTypeIsAPDLType(constructedType
));
177 // CHECK: constructedType isa PDLAttributeType: 0
178 fprintf(stderr
, "constructedType isa PDLAttributeType: %d\n",
179 mlirTypeIsAPDLAttributeType(constructedType
));
180 // CHECK: constructedType isa PDLOperationType: 0
181 fprintf(stderr
, "constructedType isa PDLOperationType: %d\n",
182 mlirTypeIsAPDLOperationType(constructedType
));
183 // CHECK: constructedType isa PDLRangeType: 1
184 fprintf(stderr
, "constructedType isa PDLRangeType: %d\n",
185 mlirTypeIsAPDLRangeType(constructedType
));
186 // CHECK: constructedType isa PDLTypeType: 0
187 fprintf(stderr
, "constructedType isa PDLTypeType: %d\n",
188 mlirTypeIsAPDLTypeType(constructedType
));
189 // CHECK: constructedType isa PDLValueType: 0
190 fprintf(stderr
, "constructedType isa PDLValueType: %d\n",
191 mlirTypeIsAPDLValueType(constructedType
));
194 fprintf(stderr
, "equal: %d\n", mlirTypeEqual(parsedType
, constructedType
));
196 fprintf(stderr
, "equal: %d\n", mlirTypeEqual(typeType
, elementType
));
198 // CHECK: !pdl.range<type>
199 mlirTypeDump(parsedType
);
200 // CHECK: !pdl.range<type>
201 mlirTypeDump(constructedType
);
203 mlirTypeDump(elementType
);
205 fprintf(stderr
, "\n\n");
208 // CHECK-LABEL: testTypeType
209 void testTypeType(MlirContext ctx
) {
210 fprintf(stderr
, "testTypeType\n");
212 MlirType parsedType
= mlirTypeParseGet(
213 ctx
, mlirStringRefCreateFromCString("!pdl.type"));
214 MlirType constructedType
= mlirPDLTypeTypeGet(ctx
);
216 assert(!mlirTypeIsNull(parsedType
) && "couldn't parse PDLAttributeType");
217 assert(!mlirTypeIsNull(constructedType
) && "couldn't construct PDLAttributeType");
219 // CHECK: parsedType isa PDLType: 1
220 fprintf(stderr
, "parsedType isa PDLType: %d\n",
221 mlirTypeIsAPDLType(parsedType
));
222 // CHECK: parsedType isa PDLAttributeType: 0
223 fprintf(stderr
, "parsedType isa PDLAttributeType: %d\n",
224 mlirTypeIsAPDLAttributeType(parsedType
));
225 // CHECK: parsedType isa PDLOperationType: 0
226 fprintf(stderr
, "parsedType isa PDLOperationType: %d\n",
227 mlirTypeIsAPDLOperationType(parsedType
));
228 // CHECK: parsedType isa PDLRangeType: 0
229 fprintf(stderr
, "parsedType isa PDLRangeType: %d\n",
230 mlirTypeIsAPDLRangeType(parsedType
));
231 // CHECK: parsedType isa PDLTypeType: 1
232 fprintf(stderr
, "parsedType isa PDLTypeType: %d\n",
233 mlirTypeIsAPDLTypeType(parsedType
));
234 // CHECK: parsedType isa PDLValueType: 0
235 fprintf(stderr
, "parsedType isa PDLValueType: %d\n",
236 mlirTypeIsAPDLValueType(parsedType
));
238 // CHECK: constructedType isa PDLType: 1
239 fprintf(stderr
, "constructedType isa PDLType: %d\n",
240 mlirTypeIsAPDLType(constructedType
));
241 // CHECK: constructedType isa PDLAttributeType: 0
242 fprintf(stderr
, "constructedType isa PDLAttributeType: %d\n",
243 mlirTypeIsAPDLAttributeType(constructedType
));
244 // CHECK: constructedType isa PDLOperationType: 0
245 fprintf(stderr
, "constructedType isa PDLOperationType: %d\n",
246 mlirTypeIsAPDLOperationType(constructedType
));
247 // CHECK: constructedType isa PDLRangeType: 0
248 fprintf(stderr
, "constructedType isa PDLRangeType: %d\n",
249 mlirTypeIsAPDLRangeType(constructedType
));
250 // CHECK: constructedType isa PDLTypeType: 1
251 fprintf(stderr
, "constructedType isa PDLTypeType: %d\n",
252 mlirTypeIsAPDLTypeType(constructedType
));
253 // CHECK: constructedType isa PDLValueType: 0
254 fprintf(stderr
, "constructedType isa PDLValueType: %d\n",
255 mlirTypeIsAPDLValueType(constructedType
));
258 fprintf(stderr
, "equal: %d\n", mlirTypeEqual(parsedType
, constructedType
));
261 mlirTypeDump(parsedType
);
263 mlirTypeDump(constructedType
);
265 fprintf(stderr
, "\n\n");
268 // CHECK-LABEL: testValueType
269 void testValueType(MlirContext ctx
) {
270 fprintf(stderr
, "testValueType\n");
272 MlirType parsedType
= mlirTypeParseGet(
273 ctx
, mlirStringRefCreateFromCString("!pdl.value"));
274 MlirType constructedType
= mlirPDLValueTypeGet(ctx
);
276 assert(!mlirTypeIsNull(parsedType
) && "couldn't parse PDLAttributeType");
277 assert(!mlirTypeIsNull(constructedType
) && "couldn't construct PDLAttributeType");
279 // CHECK: parsedType isa PDLType: 1
280 fprintf(stderr
, "parsedType isa PDLType: %d\n",
281 mlirTypeIsAPDLType(parsedType
));
282 // CHECK: parsedType isa PDLAttributeType: 0
283 fprintf(stderr
, "parsedType isa PDLAttributeType: %d\n",
284 mlirTypeIsAPDLAttributeType(parsedType
));
285 // CHECK: parsedType isa PDLOperationType: 0
286 fprintf(stderr
, "parsedType isa PDLOperationType: %d\n",
287 mlirTypeIsAPDLOperationType(parsedType
));
288 // CHECK: parsedType isa PDLRangeType: 0
289 fprintf(stderr
, "parsedType isa PDLRangeType: %d\n",
290 mlirTypeIsAPDLRangeType(parsedType
));
291 // CHECK: parsedType isa PDLTypeType: 0
292 fprintf(stderr
, "parsedType isa PDLTypeType: %d\n",
293 mlirTypeIsAPDLTypeType(parsedType
));
294 // CHECK: parsedType isa PDLValueType: 1
295 fprintf(stderr
, "parsedType isa PDLValueType: %d\n",
296 mlirTypeIsAPDLValueType(parsedType
));
298 // CHECK: constructedType isa PDLType: 1
299 fprintf(stderr
, "constructedType isa PDLType: %d\n",
300 mlirTypeIsAPDLType(constructedType
));
301 // CHECK: constructedType isa PDLAttributeType: 0
302 fprintf(stderr
, "constructedType isa PDLAttributeType: %d\n",
303 mlirTypeIsAPDLAttributeType(constructedType
));
304 // CHECK: constructedType isa PDLOperationType: 0
305 fprintf(stderr
, "constructedType isa PDLOperationType: %d\n",
306 mlirTypeIsAPDLOperationType(constructedType
));
307 // CHECK: constructedType isa PDLRangeType: 0
308 fprintf(stderr
, "constructedType isa PDLRangeType: %d\n",
309 mlirTypeIsAPDLRangeType(constructedType
));
310 // CHECK: constructedType isa PDLTypeType: 0
311 fprintf(stderr
, "constructedType isa PDLTypeType: %d\n",
312 mlirTypeIsAPDLTypeType(constructedType
));
313 // CHECK: constructedType isa PDLValueType: 1
314 fprintf(stderr
, "constructedType isa PDLValueType: %d\n",
315 mlirTypeIsAPDLValueType(constructedType
));
318 fprintf(stderr
, "equal: %d\n", mlirTypeEqual(parsedType
, constructedType
));
321 mlirTypeDump(parsedType
);
323 mlirTypeDump(constructedType
);
325 fprintf(stderr
, "\n\n");
329 MlirContext ctx
= mlirContextCreate();
330 mlirDialectHandleRegisterDialect(mlirGetDialectHandle__pdl__(), ctx
);
331 testAttributeType(ctx
);
332 testOperationType(ctx
);
336 mlirContextDestroy(ctx
);