Skip to content

Commit c72da79

Browse files
committed
Fix tblgen to julia generation on multiple optional named operands
1 parent 796c3a3 commit c72da79

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

deps/tblgen/jl-generators.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ end
303303

304304
if (op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments"))
305305
{
306-
std::string operandsegmentsizes = "";
306+
std::vector<std::string> opseglist;
307307
for (int i = 0; i < op.getNumOperands(); i++)
308308
{
309309
const auto &named_operand = op.getOperand(i);
@@ -313,12 +313,15 @@ end
313313
operandname = "operand_" + std::to_string(i);
314314
}
315315
if (named_operand.isOptional())
316-
{
317-
operandsegmentsizes += "(" + operandname + "==nothing) ? 0 : 1";
318-
continue;
319-
}
320-
operandsegmentsizes += named_operand.isVariadic() ? "length(" + operandname + "), " : "1, ";
316+
opseglist.push_back("isnothing(" + operandname + ") ? 0 : 1");
317+
else
318+
opseglist.push_back(named_operand.isVariadic() ? "length(" + operandname + "), " : "1, ");
321319
}
320+
std::string operandsegmentsizes = std::accumulate(std::begin(x), std::end(x), string(),
321+
[](string &ss, string &s)
322+
{
323+
return ss.empty() ? s : ss + "," + s;
324+
});
322325
optionals += llvm::formatv(R"(push!(attributes, operandsegmentsizes([{0}]))
323326
)",
324327
operandsegmentsizes);

0 commit comments

Comments
 (0)