[Mlir-commits] [flang] [mlir] [MLIR][DLTI] Pretty parsing and printing for DLTI attrs (PR #113365)

Rolf Morel llvmlistbot at llvm.org
Wed Oct 30 12:25:49 PDT 2024


================
@@ -28,6 +29,123 @@ using namespace mlir;
 
 #define DEBUG_TYPE "dlti"
 
+//===----------------------------------------------------------------------===//
+// parsing
+//===----------------------------------------------------------------------===//
+
+static ParseResult parseKeyValuePair(AsmParser &parser,
+                                     DataLayoutEntryInterface &entry,
+                                     bool tryType = false) {
+  Attribute value;
+
+  if (tryType) {
+    Type type;
+    OptionalParseResult parsedType = parser.parseOptionalType(type);
+    if (parsedType.has_value()) {
+      if (failed(parsedType.value()))
+        return parser.emitError(parser.getCurrentLocation())
+               << "error while parsing type DLTI key";
+
+      if (failed(parser.parseEqual()) || failed(parser.parseAttribute(value)))
+        return failure();
+
+      entry = DataLayoutEntryAttr::get(type, value);
+      return ParseResult::success();
+    }
+  }
+
+  std::string ident;
+  OptionalParseResult parsedStr = parser.parseOptionalString(&ident);
+  if (parsedStr.has_value() && !ident.empty()) {
----------------
rolfmorel wrote:

If there's a use case for an empty string key, we can discuss it. For now we can be conservative and have it be banned, as codified in the verifier.

https://github.com/llvm/llvm-project/pull/113365


More information about the Mlir-commits mailing list