Skip to content

Commit

Permalink
[python] Fix warnigns in walk_with_filter, NFC (#7594)
Browse files Browse the repository at this point in the history
Fix naming conventions etc.
  • Loading branch information
uenoku authored Sep 12, 2024
1 parent 1df22fb commit 008dc9d
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/Bindings/Python/SupportModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,37 @@ void circt::python::populateSupportSubmodule(py::module &m) {
// Walk with filter.
m.def(
"_walk_with_filter",
[](MlirOperation operation, std::vector<std::string> op_names,
[](MlirOperation operation, const std::vector<std::string> &opNames,
std::function<MlirWalkResult(MlirOperation)> callback,
MlirWalkOrder walkOrder) {
struct UserData {
std::function<MlirWalkResult(MlirOperation)> callback;
bool gotException;
std::string exceptionWhat;
py::object exceptionType;
std::vector<MlirIdentifier> op_names;
std::vector<MlirIdentifier> opNames;
};

std::vector<MlirIdentifier> op_names_identifiers;
std::vector<MlirIdentifier> opNamesIdentifiers;
opNamesIdentifiers.reserve(opNames.size());

// Construct MlirIdentifier from string to perform pointer comparison.
for (auto &op_name : op_names)
op_names_identifiers.push_back(mlirIdentifierGet(
for (auto &opName : opNames)
opNamesIdentifiers.push_back(mlirIdentifierGet(
mlirOperationGetContext(operation),
mlirStringRefCreateFromCString(op_name.c_str())));
mlirStringRefCreateFromCString(opName.c_str())));

UserData userData{callback, false, {}, {}, op_names_identifiers};
UserData userData{
std::move(callback), false, {}, {}, opNamesIdentifiers};
MlirOperationWalkCallback walkCallback = [](MlirOperation op,
void *userData) {
UserData *calleeUserData = static_cast<UserData *>(userData);
auto op_name = mlirOperationGetName(op);
auto opName = mlirOperationGetName(op);

// Check if the operation name is in the filter.
bool inFilter = false;
for (auto &op_name_identifier : calleeUserData->op_names) {
if (mlirIdentifierEqual(op_name, op_name_identifier)) {
for (auto &opNamesIdentifier : calleeUserData->opNames) {
if (mlirIdentifierEqual(opName, opNamesIdentifier)) {
inFilter = true;
break;
}
Expand Down

0 comments on commit 008dc9d

Please sign in to comment.