[mlir] Small stylistic changes to Complex_NumberAttr

Differential Revision: https://reviews.llvm.org/D130632
This commit is contained in:
Alexander Belyaev 2022-07-27 15:26:01 +02:00
parent c78144e1c7
commit 824954a8c9
2 changed files with 10 additions and 33 deletions

View File

@ -34,8 +34,9 @@ def Complex_NumberAttr : Complex_Attr<"Number", "number"> {
``` ```
}]; }];
let parameters = (ins APFloatParameter<"">:$real, APFloatParameter<"">:$imag, AttributeSelfTypeParameter<"">:$type); let parameters = (ins APFloatParameter<"">:$real,
APFloatParameter<"">:$imag,
AttributeSelfTypeParameter<"">:$type);
let genVerifyDecl = 1; let genVerifyDecl = 1;
let hasCustomAssemblyFormat = 1; let hasCustomAssemblyFormat = 1;
} }

View File

@ -64,47 +64,23 @@ LogicalResult complex::NumberAttr::verify(
} }
void complex::NumberAttr::print(AsmPrinter &printer) const { void complex::NumberAttr::print(AsmPrinter &printer) const {
printer << "<:"; printer << "<:" << getType() << " " << getReal() << ", " << getImag() << ">";
printer.printType(getType());
printer << " ";
printer.printFloat(getReal());
printer << ", ";
printer.printFloat(getImag());
printer << ">";
} }
Attribute complex::NumberAttr::parse(AsmParser &parser, Type odsType) { Attribute complex::NumberAttr::parse(AsmParser &parser, Type odsType) {
if (failed(parser.parseLess()))
return {};
if (failed(parser.parseColon()))
return {};
Type type; Type type;
if (failed(parser.parseType(type))) double real, imag;
return {}; if (parser.parseLess() || parser.parseColon() || parser.parseType(type) ||
parser.parseFloat(real) || parser.parseComma() ||
double real; parser.parseFloat(imag) || parser.parseGreater())
if (failed(parser.parseFloat(real)))
return {};
if (failed(parser.parseComma()))
return {};
double imag;
if (failed(parser.parseFloat(imag)))
return {};
if (failed(parser.parseGreater()))
return {}; return {};
bool unused = false; bool unused = false;
auto realFloat = APFloat(real); APFloat realFloat(real);
realFloat.convert(type.cast<FloatType>().getFloatSemantics(), realFloat.convert(type.cast<FloatType>().getFloatSemantics(),
APFloat::rmNearestTiesToEven, &unused); APFloat::rmNearestTiesToEven, &unused);
auto imagFloat = APFloat(imag); APFloat imagFloat(imag);
imagFloat.convert(type.cast<FloatType>().getFloatSemantics(), imagFloat.convert(type.cast<FloatType>().getFloatSemantics(),
APFloat::rmNearestTiesToEven, &unused); APFloat::rmNearestTiesToEven, &unused);
return NumberAttr::get(parser.getContext(), realFloat, imagFloat, type); return NumberAttr::get(parser.getContext(), realFloat, imagFloat, type);
} }