15 #ifndef MLIR_TABLEGEN_FORMAT_H_ 16 #define MLIR_TABLEGEN_FORMAT_H_ 19 #include "llvm/ADT/DenseMap.h" 20 #include "llvm/ADT/StringMap.h" 21 #include "llvm/Support/FormatVariadic.h" 70 static inline PHKind getEmptyKey() {
71 return static_cast<PHKind>(CharInfo::getEmptyKey());
73 static inline PHKind getTombstoneKey() {
74 return static_cast<PHKind>(CharInfo::getTombstoneKey());
76 static unsigned getHashValue(
const PHKind &val) {
77 return CharInfo::getHashValue(static_cast<char>(val));
80 static bool isEqual(
const PHKind &lhs,
const PHKind &rhs) {
85 llvm::SmallDenseMap<PHKind, std::string, 4, PHKindInfo> builtinSubstMap;
86 llvm::StringMap<std::string> customSubstMap;
93 enum class Type { Empty, Literal, PositionalPH, SpecialPH };
97 : type(
Type::Literal), spec(literal) {}
99 : type(
Type::PositionalPH), spec(spec), index(index) {}
101 : type(
Type::SpecialPH), spec(spec), placeholder(placeholder) {}
111 static std::pair<FmtReplacement, StringRef> splitFmtSegment(StringRef fmt);
112 static std::vector<FmtReplacement> parseFormatString(StringRef fmt);
123 template <
typename... Ts>
124 std::vector<llvm::detail::format_adapter *>
operator()(Ts &... items) {
125 return std::vector<llvm::detail::format_adapter *>{&items...};
131 std::vector<llvm::detail::format_adapter *>
adapters;
136 : fmt(fmt), context(ctx), replacements(parseFormatString(fmt)) {}
141 : fmt(std::move(that.fmt)), context(that.context),
143 replacements(std::move(that.replacements)) {}
145 void format(llvm::raw_ostream &s)
const;
149 llvm::raw_string_ostream s(result);
156 llvm::raw_svector_ostream s(result);
163 operator std::string()
const {
return str(); }
175 parameters(std::move(params)) {
176 adapters.reserve(std::tuple_size<Tuple>::value);
183 :
FmtObjectBase(std::move(that)), parameters(std::move(that.parameters)) {
184 adapters.reserve(that.
adapters.size());
225 template <
typename... Ts>
228 llvm::detail::build_format_adapter(std::forward<Ts>(vals))...))> {
229 using ParamTuple = decltype(std::make_tuple(
230 llvm::detail::build_format_adapter(std::forward<Ts>(vals))...));
234 llvm::detail::build_format_adapter(std::forward<Ts>(vals))...));
240 #endif // MLIR_TABLEGEN_FORMAT_H_ Type
Definition: Format.h:93
Definition: InferTypeOpInterface.cpp:20
PHKind
Definition: Format.h:43
const FmtContext * context
Definition: Format.h:130
static PHKind getPlaceHolderKind(StringRef str)
Definition: Format.cpp:63
StringRef fmt
Definition: Format.h:129
FmtContext & addSubst(StringRef placeholder, Twine subst)
Definition: Format.cpp:24
FmtContext & withSelf(Twine subst)
Definition: Format.cpp:39
FmtObject(FmtObject &&that)
Definition: Format.h:182
std::vector< FmtReplacement > replacements
Definition: Format.h:132
std::string str() const
Definition: Format.h:147
Definition: StandardTypes.h:62
SmallString< N > sstr() const
Definition: Format.h:154
std::vector< llvm::detail::format_adapter * > operator()(Ts &... items)
Definition: Format.h:124
std::vector< llvm::detail::format_adapter * > adapters
Definition: Format.h:131
auto tgfmt(StringRef fmt, const FmtContext *ctx, Ts &&... vals) -> FmtObject< decltype(std::make_tuple(llvm::detail::build_format_adapter(std::forward< Ts >(vals))...))>
Definition: Format.h:226
FmtReplacement(StringRef literal)
Definition: Format.h:96
FmtReplacement(StringRef spec, FmtContext::PHKind placeholder)
Definition: Format.h:100
FmtObject(StringRef fmt, const FmtContext *ctx, Tuple &¶ms)
Definition: Format.h:173
FmtObjectBase(FmtObjectBase &&that)
Definition: Format.h:140
FmtContext & withBuilder(Twine subst)
Definition: Format.cpp:29
StringRef spec
Definition: Format.h:104
FmtObjectBase(StringRef fmt, const FmtContext *ctx, size_t numParams)
Definition: Format.h:135
Optional< StringRef > getSubstFor(PHKind placeholder) const
Definition: Format.cpp:45
FmtReplacement(StringRef spec, size_t index)
Definition: Format.h:98
FmtContext & withOp(Twine subst)
Definition: Format.cpp:34