From c72da7916e34536985d74aef5074b66613a775a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20S=C3=A1nchez=20Ram=C3=ADrez?= Date: Sun, 21 Jul 2024 13:23:56 +0200 Subject: [PATCH] Fix tblgen to julia generation on multiple optional named operands --- deps/tblgen/jl-generators.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/deps/tblgen/jl-generators.cc b/deps/tblgen/jl-generators.cc index 4d004e93..235ca080 100644 --- a/deps/tblgen/jl-generators.cc +++ b/deps/tblgen/jl-generators.cc @@ -303,7 +303,7 @@ end if (op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments")) { - std::string operandsegmentsizes = ""; + std::vector opseglist; for (int i = 0; i < op.getNumOperands(); i++) { const auto &named_operand = op.getOperand(i); @@ -313,12 +313,15 @@ end operandname = "operand_" + std::to_string(i); } if (named_operand.isOptional()) - { - operandsegmentsizes += "(" + operandname + "==nothing) ? 0 : 1"; - continue; - } - operandsegmentsizes += named_operand.isVariadic() ? "length(" + operandname + "), " : "1, "; + opseglist.push_back("isnothing(" + operandname + ") ? 0 : 1"); + else + opseglist.push_back(named_operand.isVariadic() ? "length(" + operandname + "), " : "1, "); } + std::string operandsegmentsizes = std::accumulate(std::begin(x), std::end(x), string(), + [](string &ss, string &s) + { + return ss.empty() ? s : ss + "," + s; + }); optionals += llvm::formatv(R"(push!(attributes, operandsegmentsizes([{0}])) )", operandsegmentsizes);