[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 hasCustomAssemblyFormat = 1;
}

View File

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