195
195
{
196
196
functionname = functionname + " _" ;
197
197
}
198
- auto i = functionname.find (' .' );
199
- if (i!=std::string::npos)
200
- {
201
- functionname.replace (i, 1 , " _" ); // replace . with _
202
- }
198
+ // replace all .'s with _'s
199
+ std::replace (functionname.begin (), functionname.end (), ' .' , ' _' );
203
200
204
201
std::string description = " " ;
205
202
if (op.hasDescription ())
208
205
}
209
206
bool inferrable = canInferType (op);
210
207
208
+ bool alreadykeyword = false ; // set to true when first optional argument is encountered. This is used to insert a single semicolon (;) instead of a comma (,) as separator between positional and keyword arguments.
211
209
for (size_t i = 0 ; i < op.getNumOperands (); i++)
212
210
{
213
211
const auto &named_operand = op.getOperand (i);
@@ -229,19 +227,30 @@ end
229
227
type = " Vector{" + type + " }" ;
230
228
}
231
229
230
+ std::string separator = " , " ;
232
231
if (optional)
233
232
{
234
233
optionals += llvm::formatv (R"( ({0} != nothing) && push!(operands, {0}{1})
235
234
)" ,
236
235
operandname, (variadic ? " ..." : " " ));
237
236
type = " Union{Nothing, " + type + " }" ;
238
237
defaultvalue = " =nothing" ;
238
+
239
+ if (!alreadykeyword) {
240
+ alreadykeyword = true ;
241
+ separator = " ; " ;
242
+ }
239
243
}
240
244
else
241
245
{
242
246
operandcontainer += operandname + (variadic ? " ..." : " " ) + " , " ;
247
+ separator = (!alreadykeyword && i == op.getNumOperands () - 1 ) ? " ; " : " , " ;
243
248
}
244
- operandarguments += operandname + defaultvalue + " ::" + type + (i == op.getNumOperands () - 1 ? " " : " , " );
249
+
250
+ operandarguments += operandname + defaultvalue + " ::" + type + separator;
251
+ }
252
+ if (operandarguments == " " ) {
253
+ operandarguments = " ; " ;
245
254
}
246
255
247
256
if (op.getTrait (" ::mlir::OpTrait::AttrSizedOperandSegments" ))
387
396
successorarguments += successorname + defaultvalue + " ::" + type + " , " ;
388
397
}
389
398
390
- std::string arguments = operandarguments + " ; " + resultarguments + attributearguments + regionarguments + successorarguments;
399
+ std::string arguments = operandarguments + resultarguments + attributearguments + regionarguments + successorarguments;
391
400
std::string functionbody = llvm::formatv (functionbodytemplate, resultcontainer, operandcontainer, regioncontainer, successorcontainer, attributecontainer, optionals, opname, resultsexpression, resultinference);
392
401
393
402
modulecontents += llvm::formatv (functiontemplate, functionname, arguments, functionbody, description);
0 commit comments