@@ -189,45 +189,46 @@ LogicalResult INTTOp::verify() {
189
189
ParseResult ConstantOp::parse (OpAsmParser &parser, OperationState &result) {
190
190
// Using the built-in parser.parseAttribute requires the full
191
191
// #polynomial.typed_int_polynomial syntax, which is excessive.
192
- // Instead we manually parse the components.
192
+ // Instead we parse a keyword int to signal it's an integer polynomial
193
193
Type type;
194
- parser.parseOptionalAttribute ();
195
-
196
- IntPolynomialAttr intPolyAttr;
197
- parser.parseOptionalAttribute (intPolyAttr);
198
- if (intPolyAttr) {
199
- if (parser.parseColon () || parser.parseType (type))
200
- return failure ();
201
-
202
- result.addAttribute (" value" ,
203
- TypedIntPolynomialAttr::get (type, intPolyAttr));
204
- result.addTypes (type);
205
- return success ();
194
+ if (succeeded (parser.parseOptionalKeyword (" float" ))) {
195
+ Attribute floatPolyAttr = FloatPolynomialAttr::parse (parser, nullptr );
196
+ if (floatPolyAttr) {
197
+ if (parser.parseColon () || parser.parseType (type))
198
+ return failure ();
199
+ result.addAttribute (" value" ,
200
+ TypedFloatPolynomialAttr::get (type, floatPolyAttr));
201
+ result.addTypes (type);
202
+ return success ();
203
+ }
206
204
}
207
205
208
- Attribute floatPolyAttr = FloatPolynomialAttr::parse (parser, nullptr , /* optional=*/ true );
209
- if (floatPolyAttr) {
210
- if (parser.parseColon () || parser.parseType (type))
211
- return failure ();
212
- result.addAttribute (" value" ,
213
- TypedFloatPolynomialAttr::get (type, intPolyAttr));
214
- result.addTypes (type);
215
- return success ();
206
+ if (succeeded (parser.parseOptionalKeyword (" int" ))) {
207
+ Attribute intPolyAttr = IntPolynomialAttr::parse (parser, nullptr );
208
+ if (intPolyAttr) {
209
+ if (parser.parseColon () || parser.parseType (type))
210
+ return failure ();
211
+
212
+ result.addAttribute (" value" ,
213
+ TypedIntPolynomialAttr::get (type, intPolyAttr));
214
+ result.addTypes (type);
215
+ return success ();
216
+ }
216
217
}
217
218
218
219
// In the worst case, still accept the verbose versions.
219
220
TypedIntPolynomialAttr typedIntPolyAttr;
220
- ParseResult res = parser.parseAttribute <TypedIntPolynomialAttr>(
221
+ OptionalParseResult res = parser.parseOptionalAttribute <TypedIntPolynomialAttr>(
221
222
typedIntPolyAttr, " value" , result.attributes );
222
- if (succeeded (res)) {
223
+ if (res. has_value () && succeeded (res. value () )) {
223
224
result.addTypes (typedIntPolyAttr.getType ());
224
225
return success ();
225
226
}
226
227
227
228
TypedFloatPolynomialAttr typedFloatPolyAttr;
228
229
res = parser.parseAttribute <TypedFloatPolynomialAttr>(
229
230
typedFloatPolyAttr, " value" , result.attributes );
230
- if (succeeded (res)) {
231
+ if (res. has_value () && succeeded (res. value () )) {
231
232
result.addTypes (typedFloatPolyAttr.getType ());
232
233
return success ();
233
234
}
@@ -237,7 +238,17 @@ ParseResult ConstantOp::parse(OpAsmParser &parser, OperationState &result) {
237
238
238
239
void ConstantOp::print (OpAsmPrinter &p) {
239
240
p << " " ;
240
- p.printAttribute (getValue ());
241
+ if (auto intPoly = dyn_cast<TypedIntPolynomialAttr>(getValue ())) {
242
+ p << " int" ;
243
+ intPoly.getValue ().print (p);
244
+ } else if (auto floatPoly = dyn_cast<TypedFloatPolynomialAttr>(getValue ())) {
245
+ p << " float" ;
246
+ floatPoly.getValue ().print (p);
247
+ } else {
248
+ assert (false && " unexpected attribute type" );
249
+ }
250
+ p << " : " ;
251
+ p.printType (getOutput ().getType ());
241
252
}
242
253
243
254
LogicalResult ConstantOp::inferReturnTypes (
0 commit comments