Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tblgen bugfixes (keyword arguments and function names) #31

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading