Skip to content

Commit

Permalink
Fix tblgen to julia generation on multiple optional named operands
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing committed Jul 21, 2024
1 parent 796c3a3 commit c72da79
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions deps/tblgen/jl-generators.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ end

if (op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments"))
{
std::string operandsegmentsizes = "";
std::vector<std::string> opseglist;
for (int i = 0; i < op.getNumOperands(); i++)
{
const auto &named_operand = op.getOperand(i);
Expand All @@ -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);
Expand Down

0 comments on commit c72da79

Please sign in to comment.