diff --git a/mlir/docs/AttributesAndTypes.md b/mlir/docs/AttributesAndTypes.md --- a/mlir/docs/AttributesAndTypes.md +++ b/mlir/docs/AttributesAndTypes.md @@ -587,7 +587,7 @@ ```tablegen def MyParameter : TypeParameter<"std::pair", "pair of ints"> { let printer = [{ $_printer << $_self.first << " * " << $_self.second }]; - let parser = [{ [&] -> FailureOr> { + let parser = [{ [&]() -> FailureOr> { int a, b; if ($_parser.parseInteger(a) || $_parser.parseStar() || $_parser.parseInteger(b)) diff --git a/mlir/include/mlir/IR/DialectImplementation.h b/mlir/include/mlir/IR/DialectImplementation.h --- a/mlir/include/mlir/IR/DialectImplementation.h +++ b/mlir/include/mlir/IR/DialectImplementation.h @@ -121,7 +121,8 @@ elements.push_back(element.getValue()); return success(); }; - if (parser.parseCommaSeparatedList(elementParser)) + if (parser.parseCommaSeparatedList(AsmParser::Delimiter::Square, + elementParser)) return failure(); return elements; } diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h --- a/mlir/include/mlir/IR/OpImplementation.h +++ b/mlir/include/mlir/IR/OpImplementation.h @@ -80,6 +80,15 @@ *this << attrOrType; } + /// Overload for printing the provided array in the context of an operation + /// custom printer. + template + void printStrippedAttrOrType(ArrayRef attrsOrTypes) { + getStream() << '['; + *this << attrsOrTypes; + getStream() << ']'; + } + /// Print the given attribute without its type. The corresponding parser must /// provide a valid type for the attribute. virtual void printAttributeWithoutType(Attribute attr); diff --git a/mlir/include/mlir/Support/StorageUniquer.h b/mlir/include/mlir/Support/StorageUniquer.h --- a/mlir/include/mlir/Support/StorageUniquer.h +++ b/mlir/include/mlir/Support/StorageUniquer.h @@ -93,7 +93,7 @@ class StorageAllocator { public: /// Copy the specified array of elements into memory managed by our bump - /// pointer allocator. This assumes the elements are all PODs. + /// pointer allocator. T must be copy-constructible. template ArrayRef copyInto(ArrayRef elements) { if (elements.empty()) return llvm::None; diff --git a/mlir/test/lib/Dialect/Test/TestAttrDefs.td b/mlir/test/lib/Dialect/Test/TestAttrDefs.td --- a/mlir/test/lib/Dialect/Test/TestAttrDefs.td +++ b/mlir/test/lib/Dialect/Test/TestAttrDefs.td @@ -160,14 +160,16 @@ def TestParamOne : AttrParameter<"int64_t", ""> {} def TestParamTwo : AttrParameter<"std::string", "", "llvm::StringRef"> { + let parser = [{ [&]() -> FailureOr { + std::string str; + if (failed($_parser.parseString(&str))) + return failure(); + return str; + }() }]; let printer = "$_printer << '\"' << $_self << '\"'"; } -def TestParamFour : ArrayRefParameter<"int", ""> { - let cppStorageType = "llvm::SmallVector"; - let parser = "::parseIntArray($_parser)"; - let printer = "::printIntArray($_printer, $_self)"; -} +def TestParamFour : ArrayRefParameter<"int", "">; def TestAttrWithFormat : Test_Attr<"TestAttrWithFormat"> { let parameters = ( diff --git a/mlir/test/lib/Dialect/Test/TestAttributes.cpp b/mlir/test/lib/Dialect/Test/TestAttributes.cpp --- a/mlir/test/lib/Dialect/Test/TestAttributes.cpp +++ b/mlir/test/lib/Dialect/Test/TestAttributes.cpp @@ -74,7 +74,7 @@ } //===----------------------------------------------------------------------===// -// CompoundAAttr +// TestI64ElementsAttr //===----------------------------------------------------------------------===// Attribute TestI64ElementsAttr::parse(AsmParser &parser, Type type) { @@ -123,27 +123,6 @@ return success(); } -//===----------------------------------------------------------------------===// -// Utility Functions for Generated Attributes -//===----------------------------------------------------------------------===// - -static FailureOr> parseIntArray(AsmParser &parser) { - SmallVector ints; - if (parser.parseLSquare() || parser.parseCommaSeparatedList([&]() { - ints.push_back(0); - return parser.parseInteger(ints.back()); - }) || - parser.parseRSquare()) - return failure(); - return ints; -} - -static void printIntArray(AsmPrinter &printer, ArrayRef ints) { - printer << '['; - llvm::interleaveComma(ints, printer); - printer << ']'; -} - //===----------------------------------------------------------------------===// // TestSubElementsAccessAttr //===----------------------------------------------------------------------===// diff --git a/mlir/test/lib/Dialect/Test/TestTypeDefs.td b/mlir/test/lib/Dialect/Test/TestTypeDefs.td --- a/mlir/test/lib/Dialect/Test/TestTypeDefs.td +++ b/mlir/test/lib/Dialect/Test/TestTypeDefs.td @@ -201,7 +201,7 @@ ); let mnemonic = "no_parser"; - let assemblyFormat = "`<` $one `,` `[` $two `]` `,` $three `,` $four `>`"; + let assemblyFormat = "`<` $one `,` $two `,` $three `,` $four `>`"; } def TestTypeStructCaptureAll : Test_Type<"TestStructTypeCaptureAll"> {