Skip to content

Commit

Permalink
* fix keyword before positional arguments (#30) (#31)
Browse files Browse the repository at this point in the history
* fix conversion of operations with multiple dots (.) in their name.
  • Loading branch information
jumerckx authored Jan 16, 2024
1 parent a989ea5 commit 72abb74
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions deps/tblgen/jl-generators.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,8 @@ end
{
functionname = functionname + "_";
}
auto i = functionname.find('.');
if (i!=std::string::npos)
{
functionname.replace(i, 1, "_"); // replace . with _
}
// replace all .'s with _'s
std::replace(functionname.begin(), functionname.end(), '.', '_');

std::string description = "";
if (op.hasDescription())
Expand All @@ -213,6 +210,7 @@ end
}
bool inferrable = canInferType(op);

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.
for (size_t i = 0; i < op.getNumOperands(); i++)
{
const auto &named_operand = op.getOperand(i);
Expand All @@ -234,19 +232,30 @@ end
type = "Vector{" + type + "}";
}

std::string separator = ", ";
if (optional)
{
optionals += llvm::formatv(R"(({0} != nothing) && push!(operands, {0}{1})
)",
operandname, (variadic ? "..." : ""));
type = "Union{Nothing, " + type + "}";
defaultvalue = "=nothing";

if (!alreadykeyword) {
alreadykeyword = true;
separator = "; ";
}
}
else
{
operandcontainer += operandname + (variadic ? "..." : "") + ", ";
separator = (!alreadykeyword && i == op.getNumOperands() - 1) ? "; " : ", ";
}
operandarguments += operandname + defaultvalue + "::" + type + (i == op.getNumOperands() - 1 ? "" : ", ");

operandarguments += operandname + defaultvalue + "::" + type + separator;
}
if (operandarguments == "") {
operandarguments = "; ";
}

if (op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments"))
Expand Down Expand Up @@ -392,7 +401,7 @@ end
successorarguments += successorname + defaultvalue + "::" + type + ", ";
}

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

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

0 comments on commit 72abb74

Please sign in to comment.