Skip to content

Commit e8417c3

Browse files
committed
* fix keyword before positional arguments (#30)
* fix conversion of operations with multiple dots (.) in their name.
1 parent baced91 commit e8417c3

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

deps/tblgen/jl-generators.cc

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,8 @@ end
195195
{
196196
functionname = functionname + "_";
197197
}
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(), '.', '_');
203200

204201
std::string description = "";
205202
if (op.hasDescription())
@@ -208,6 +205,7 @@ end
208205
}
209206
bool inferrable = canInferType(op);
210207

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.
211209
for (size_t i = 0; i < op.getNumOperands(); i++)
212210
{
213211
const auto &named_operand = op.getOperand(i);
@@ -229,19 +227,30 @@ end
229227
type = "Vector{" + type + "}";
230228
}
231229

230+
std::string separator = ", ";
232231
if (optional)
233232
{
234233
optionals += llvm::formatv(R"(({0} != nothing) && push!(operands, {0}{1})
235234
)",
236235
operandname, (variadic ? "..." : ""));
237236
type = "Union{Nothing, " + type + "}";
238237
defaultvalue = "=nothing";
238+
239+
if (!alreadykeyword) {
240+
alreadykeyword = true;
241+
separator = "; ";
242+
}
239243
}
240244
else
241245
{
242246
operandcontainer += operandname + (variadic ? "..." : "") + ", ";
247+
separator = (!alreadykeyword && i == op.getNumOperands() - 1) ? "; " : ", ";
243248
}
244-
operandarguments += operandname + defaultvalue + "::" + type + (i == op.getNumOperands() - 1 ? "" : ", ");
249+
250+
operandarguments += operandname + defaultvalue + "::" + type + separator;
251+
}
252+
if (operandarguments == "") {
253+
operandarguments = "; ";
245254
}
246255

247256
if (op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments"))
@@ -387,7 +396,7 @@ end
387396
successorarguments += successorname + defaultvalue + "::" + type + ", ";
388397
}
389398

390-
std::string arguments = operandarguments + "; " + resultarguments + attributearguments + regionarguments + successorarguments;
399+
std::string arguments = operandarguments + resultarguments + attributearguments + regionarguments + successorarguments;
391400
std::string functionbody = llvm::formatv(functionbodytemplate, resultcontainer, operandcontainer, regioncontainer, successorcontainer, attributecontainer, optionals, opname, resultsexpression, resultinference);
392401

393402
modulecontents += llvm::formatv(functiontemplate, functionname, arguments, functionbody, description);

0 commit comments

Comments
 (0)