[Mlir-commits] [mlir] [mlir][IR] Add `getPropertyFromAttr` and `setPropertyFromAttr` methods. (PR #150060)
Rahul Kayaith
llvmlistbot at llvm.org
Tue Jul 22 10:33:44 PDT 2025
================
@@ -78,6 +81,43 @@ setPropertiesFromAttribute(TestProperties &prop, Attribute attr,
return success();
}
+/// Convert an attribute to a TestProperties struct, optionally emit errors
+/// through the provided diagnostic if any. This is used for example during
+/// parsing with the generic format.
+static LogicalResult
+setPropertyFromAttribute(TestProperties &prop, StringRef name, Attribute attr,
+ function_ref<InFlightDiagnostic()> emitError) {
+ if (name == "a") {
+ auto v = dyn_cast<IntegerAttr>(attr);
+ if (!v)
+ return failure();
+ prop.a = v.getValue().getSExtValue();
+ return success();
+ }
+ if (name == "b") {
+ auto v = dyn_cast<FloatAttr>(attr);
+ if (!v)
+ return failure();
+ prop.a = v.getValue().convertToFloat();
----------------
rkayaith wrote:
```suggestion
prop.b = v.getValue().convertToFloat();
```
https://github.com/llvm/llvm-project/pull/150060
More information about the Mlir-commits
mailing list