Skip to content

Commit

Permalink
added option to enforce pin group renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
SJulianS committed Oct 23, 2023
1 parent 6631b70 commit 3082657
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
3 changes: 2 additions & 1 deletion include/hal_core/netlist/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,10 @@ namespace hal
*
* @param[in] pin_group - The pin group.
* @param[in] new_name - The name to be assigned to the pin group.
* @param[in] force - Set `true` to enforce renaming, `false` otherwise. If a pin group with the same name already exists, that existing pin group will be renamed. Defaults to `false`.
* @returns `true` on success, `false` otherwise.
*/
bool set_pin_group_name(PinGroup<ModulePin>* pin_group, const std::string& new_name);
bool set_pin_group_name(PinGroup<ModulePin>* pin_group, const std::string& new_name, const bool force = false);

/**
* Set the type of the given pin group.
Expand Down
31 changes: 21 additions & 10 deletions src/netlist/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ namespace hal
return true;
}

bool Module::set_pin_group_name(PinGroup<ModulePin>* pin_group, const std::string& new_name)
bool Module::set_pin_group_name(PinGroup<ModulePin>* pin_group, const std::string& new_name, const bool force)
{
if (pin_group == nullptr)
{
Expand All @@ -1155,16 +1155,27 @@ namespace hal
return false;
}

if (m_pin_group_names_map.find(new_name) != m_pin_group_names_map.end())
if (const auto pin_group_it = m_pin_group_names_map.find(new_name); pin_group_it != m_pin_group_names_map.end())
{
log_warning("module",
"could not set name for pin group '{}' with ID {} of module '{}' with ID {}: a pin group with name '{}' already exists within the module",
pin_group->get_name(),
pin_group->get_id(),
m_name,
m_id,
new_name);
return false;
if (force)
{
u32 ctr = 2;
while (!this->set_pin_group_name(pin_group_it->second, new_name + "__" + std::to_string(ctr) + "__"))
{
ctr++;
}
}
else
{
log_warning("module",
"could not set name for pin group '{}' with ID {} of module '{}' with ID {}: a pin group with name '{}' already exists within the module",
pin_group->get_name(),
pin_group->get_id(),
m_name,
m_id,
new_name);
return false;
}
}

if (const std::string& old_name = pin_group->get_name(); old_name != new_name)
Expand Down
3 changes: 2 additions & 1 deletion src/python_bindings/bindings/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,11 +643,12 @@ namespace hal
:rtype: bool
)");

py_module.def("set_pin_group_name", &Module::set_pin_group_name, py::arg("pin_group"), py::arg("new_name"), R"(
py_module.def("set_pin_group_name", &Module::set_pin_group_name, py::arg("pin_group"), py::arg("new_name"), py::arg("force") = false, R"(
Set the name of the given pin group.
:param hal_py.ModulePinGroup pin_group: The pin group.
:param str new_name: The name to be assigned to the pin group.
:param bool force: Set ``True`` to enforce renaming, ``False`` otherwise. If a pin group with the same name already exists, that existing pin group will be renamed. Defaults to ``False``.
:returns: ``True`` on success, ``False`` otherwise.
:rtype: bool
)");
Expand Down

0 comments on commit 3082657

Please sign in to comment.