[llvm-branch-commits] [mlir] [mlir] Add predicates to tablegen-defined properties (PR #120176)
Markus Böck via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Dec 17 04:08:34 PST 2024
================
@@ -1033,6 +1033,60 @@ while (true) {{
emitVerifier(namedAttr.attr, namedAttr.name, getVarName(namedAttr.name));
}
+static void genPropertyVerifier(const OpOrAdaptorHelper &emitHelper,
+ FmtContext &ctx, MethodBody &body) {
+
+ // Code to get a reference to a property into a variable to avoid multiple
+ // evaluations while verifying a property.
+ // {0}: Property variable name.
+ // {1}: Property name, with the first letter capitalized, to find the getter.
+ // {2}: Property interface type.
+ const char *const fetchProperty = R"(
+ {2} {0} = this->get{1}(); (void){0};
+)";
+
+ // Code to verify that the predicate of a property holds. Embeds the
+ // condition inline.
+ // {0}: Property condition code, pre-tgfmt()'d.
+ // {1}: Emit error prefix.
+ // {2}: Property name.
+ // {3}: Property description.
+ const char *const verifyProperty = R"(
+ if (!({0}))
+ return {1}"property '{2}' failed to satiisfy constraint: {3}");
+)";
+
+ // Prefix variables with `tblgen_` to avoid hiding the attribute accessor.
+ const auto getVarName = [&](const NamedProperty &prop) {
+ std::string varName =
+ convertToCamelFromSnakeCase(prop.name, /*capitalizeFirst=*/false);
+ return (tblgenNamePrefix + Twine(varName)).str();
+ };
+
+ body.indent();
----------------
zero9178 wrote:
The code here does nothing but indent the property verifier although no construct is output that would necessitate such indentation.
Did you mean to use `auto scope = body.scope("{", "}", /*indent=*/true)` instead?
https://github.com/llvm/llvm-project/pull/120176
More information about the llvm-branch-commits
mailing list