}
};
+/// Parse an Optional integer.
+template <typename IntT>
+struct FieldParser<
+ llvm::Optional<IntT>,
+ std::enable_if_t<std::is_integral<IntT>::value, Optional<IntT>>> {
+ static FailureOr<Optional<IntT>> parse(AsmParser &parser) {
+ IntT value;
+ OptionalParseResult result = parser.parseOptionalInteger(value);
+ if (result.has_value()) {
+ if (succeeded(*result))
+ return {Optional<IntT>(value)};
+ return failure();
+ }
+ return {llvm::None};
+ }
+};
+
/// Parse any container that supports back insertion as a list.
template <typename ContainerT>
struct FieldParser<
let printer = "::printIntArray($_printer, $_self)";
}
+def TestParamUnsigned : AttrParameter<"uint64_t", ""> {}
+
def TestAttrWithFormat : Test_Attr<"TestAttrWithFormat"> {
let parameters = (
ins
TestParamTwo:$two,
"::mlir::IntegerAttr":$three,
TestParamFour:$four,
+ TestParamUnsigned:$five,
// Array of another attribute.
ArrayRefParameter<
"AttrWithTypeBuilderAttr", // The parameter C++ type.
let mnemonic = "attr_with_format";
let assemblyFormat = [{
- `<` $one `:` struct($two, $four) `:` $three `,`
+ `<` $one `:` struct($two, $four) `:` $three `:` $five `,`
`[` `` $arrayOfAttrWithTypeBuilderAttr `]` `>`
}];
let genVerifyDecl = 1;
}
+def TestAttrWithOptionalSigned : Test_Attr<"TestAttrWithOptionalSigned"> {
+ let parameters = (ins OptionalParameter<"mlir::Optional<int64_t>">:$value);
+ let assemblyFormat = "`<` $value `>`";
+ let mnemonic = "attr_with_optional_signed";
+}
+
+def TestAttrWithOptionalUnsigned : Test_Attr<"TestAttrWithOptionalUnsigned"> {
+ let parameters = (ins OptionalParameter<"mlir::Optional<uint64_t>">:$value);
+ let assemblyFormat = "`<` $value `>`";
+ let mnemonic = "attr_with_optional_unsigned";
+}
+
def TestAttrUgly : Test_Attr<"TestAttrUgly"> {
let parameters = (ins "::mlir::Attribute":$attr);
// CHECK: !test.type_with_format<2147, three = "hi", two = "hi">
func.func private @test_roundtrip_parameter_parsers(!test.type_with_format<111, three = #test<attr_ugly begin 5 : index end>, two = "foo">) -> !test.type_with_format<2147, two = "hi", three = "hi">
attributes {
- // CHECK: #test.attr_with_format<3 : two = "hello", four = [1, 2, 3] : 42 : i64, [ 10 : i16]
- attr0 = #test.attr_with_format<3 : two = "hello", four = [1, 2, 3] : 42 : i64, [10 : i16]>,
- // CHECK: #test.attr_with_format<5 : two = "a_string", four = [4, 5, 6, 7, 8] : 8 : i8, [ 10 : i16]>,
- attr1 = #test.attr_with_format<5 : two = "a_string", four = [4, 5, 6, 7, 8] : 8 : i8, [10 : i16]>,
+ // CHECK: #test.attr_with_format<3 : two = "hello", four = [1, 2, 3] : 42 : i64 : 0, [ 10 : i16]
+ attr0 = #test.attr_with_format<3 : two = "hello", four = [1, 2, 3] : 42 : i64 : 0, [10 : i16]>,
+ // CHECK: #test.attr_with_format<5 : two = "a_string", four = [4, 5, 6, 7, 8] : 8 : i8 : 255, [ 10 : i16]>,
+ attr1 = #test.attr_with_format<5 : two = "a_string", four = [4, 5, 6, 7, 8] : 8 : i8 : 255, [10 : i16]>,
// CHECK: #test<attr_ugly begin 5 : index end>
attr2 = #test<attr_ugly begin 5 : index end>,
// CHECK: #test.attr_params<42, 24>
// CHECK: #test.custom_anchor<5>
attr7 = #test.custom_anchor<5>,
// CHECK: #test.custom_anchor<5, true>
- attr8 = #test.custom_anchor<5, true>
+ attr8 = #test.custom_anchor<5, true>,
+ // CHECK: #test.attr_with_optional_signed<-12>
+ attr9 = #test.attr_with_optional_signed<-12>,
+ // CHECK: #test.attr_with_optional_unsigned<22>
+ attr_10 = #test.attr_with_optional_unsigned<22>
}
// CHECK-LABEL: @test_roundtrip_default_parsers_struct