From c3777ea10388f97d49de26292a3f05dcd6fed8d5 Mon Sep 17 00:00:00 2001 From: Geoffrey Martin-Noble Date: Mon, 20 May 2019 11:00:24 -0700 Subject: [PATCH] Define a string join tablegen utility -- PiperOrigin-RevId: 249083600 --- mlir/include/mlir/IR/OpBase.td | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td index 48c35e5..429032d 100644 --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -27,12 +27,17 @@ // Common utilities for defining TableGen mechanisms //===----------------------------------------------------------------------===// -// Concatenates a list of integers into a string separated with comma. -class Stringify integers> { - string result = !foldl(/*init*/!cast(!head(integers)), - /*list*/!tail(integers), prev, cur, prev # ", " # cur); +// Concatenates a list of strings with a separator (default ", ") +class StrJoin strings, string sep = ", "> { + string result = + !if(!empty(strings), "", + !foldl(!head(strings), !tail(strings), prev, cur, prev # sep # cur)); } +// Concatenates a list of integers into a string separated with comma. +class Stringify integers> : + StrJoin(i))>; + //===----------------------------------------------------------------------===// // Predicate definitions //===----------------------------------------------------------------------===// @@ -269,11 +274,7 @@ class AnyTypeOf allowedTypes, string description = ""> : Type< // Satisfy any of the allowed type's condition Or, !if(!eq(description, ""), - // Join all allowed types' descriptions with " or " as the description - // if not provided during template specialization - !foldl(!head(allowedTypes).description, !tail(allowedTypes), prev, cur, - prev # " or " # cur.description), - // Otherwise use the provided one + StrJoin.result, description)>; // Integer types. -- 2.7.4