class TypeParameter<string type, string desc, string accessorType = "">
: AttrOrTypeParameter<type, desc, accessorType>;
+// An optional parameter.
+class OptionalParameter<string type, string desc = ""> :
+ AttrOrTypeParameter<type, desc> {
+ let defaultValue = cppStorageType # "()";
+}
+
+// A parameter with a default value.
+class DefaultValuedParameter<string type, string value, string desc = ""> :
+ AttrOrTypeParameter<type, desc> {
+ let defaultValue = value;
+}
+
// For StringRefs, which require allocation.
class StringRefParameter<string desc = ""> :
AttrOrTypeParameter<"::llvm::StringRef", desc> {
let cppStorageType = "::llvm::SmallVector<" # arrayOf # ">";
}
+// Regular array parameters cannot be parsed when empty. This optional array
+// parameter can be used with optional groups to be parsed when empty.
+class OptionalArrayRefParameter<string arrayOf, string desc = ""> :
+ OptionalParameter<"::llvm::ArrayRef<" # arrayOf # ">", desc> {
+ let allocator = [{$_dst = $_allocator.copyInto($_self);}];
+ let cppStorageType = "::llvm::SmallVector<" # arrayOf # ">";
+ let comparator = "::llvm::makeArrayRef($_lhs) == ::llvm::makeArrayRef($_rhs)";
+}
+
// For classes which require allocation and have their own allocateInto method.
class SelfAllocationParameter<string type, string desc> :
AttrOrTypeParameter<type, desc> {
}];
}
-// An optional parameter.
-class OptionalParameter<string type, string desc = ""> :
- AttrOrTypeParameter<type, desc> {
- let defaultValue = cppStorageType # "()";
-}
-
-// A parameter with a default value.
-class DefaultValuedParameter<string type, string value, string desc = ""> :
- AttrOrTypeParameter<type, desc> {
- let defaultValue = value;
-}
-
// This is a special attribute parameter that represents the "self" type of the
// attribute. It is specially handled by the assembly format generator to derive
// its value from the optional trailing type after each attribute.
class ArrayOfAttr<Dialect dialect, string attrName, string attrMnemonic,
string eltName, list<Trait> traits = []>
: AttrDef<dialect, attrName, traits> {
- let parameters = (ins ArrayRefParameter<eltName>:$value);
+ let parameters = (ins OptionalArrayRefParameter<eltName>:$value);
let mnemonic = attrMnemonic;
- let assemblyFormat = "`[` $value `]`";
+ let assemblyFormat = "`[` (`]`) : ($value^ `]`)?";
let returnType = "::llvm::ArrayRef<" # eltName # ">";
let constBuilderCall = "$_builder.getAttr<" # attrName # "Attr>($0)";