Skip to content

Commit 69c58b8

Browse files
committed
enforce use of module::delete_net
1 parent be060ad commit 69c58b8

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

include/hal_core/netlist/module.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ namespace hal
748748

749749
NetConnectivity check_net_endpoints(const Net* net) const;
750750
bool check_net(Net* net, bool recursive = false);
751-
bool delete_net(Net* net, bool recursive = false);
751+
bool delete_net(Net* net);
752752
bool assign_pin_net(const u32 pin_id, Net* net, PinDirection direction);
753753
bool remove_pin_net(Net* net);
754754
Result<ModulePin*> create_pin_internal(const u32 id, const std::string& name, Net* net, PinDirection direction, PinType type, bool force_name);

src/netlist/module.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ namespace hal
627627
return res;
628628
}
629629

630-
bool Module::delete_net(Net* net, bool recursive)
630+
bool Module::delete_net(Net* net)
631631
{
632632
if (!m_internal_manager->m_net_checks_enabled)
633633
{
@@ -639,16 +639,16 @@ namespace hal
639639
m_input_nets.erase(net);
640640
m_output_nets.erase(net);
641641

642-
if (m_internal_manager->m_net_checks_enabled && recursive && m_parent != nullptr)
642+
if (auto pin = get_pin_by_net(net); pin != nullptr)
643643
{
644-
if (!m_parent->delete_net(net, recursive))
644+
if (!remove_pin_net(net))
645645
{
646+
log_warning("module", "Cannot delete pin ID {} from net ID {}", pin->get_id(), net->get_id());
646647
return false;
647648
}
648649
}
649650

650651
return true;
651-
652652
}
653653

654654
bool Module::check_net(Net* net, bool recursive)

src/netlist/netlist.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "hal_core/netlist/net.h"
88
#include "hal_core/netlist/netlist_internal_manager.h"
99
#include "hal_core/utilities/log.h"
10-
#include <valgrind/callgrind.h>
10+
//#include <valgrind/callgrind.h>
1111

1212
namespace hal
1313
{
@@ -343,11 +343,11 @@ namespace hal
343343

344344
bool Netlist::delete_net(Net* n)
345345
{
346-
CALLGRIND_START_INSTRUMENTATION;
347-
CALLGRIND_TOGGLE_COLLECT;
346+
// CALLGRIND_START_INSTRUMENTATION;
347+
// CALLGRIND_TOGGLE_COLLECT;
348348
return m_manager->delete_net(n);
349-
CALLGRIND_TOGGLE_COLLECT;
350-
CALLGRIND_STOP_INSTRUMENTATION;
349+
// CALLGRIND_TOGGLE_COLLECT;
350+
// CALLGRIND_STOP_INSTRUMENTATION;
351351
}
352352

353353
bool Netlist::is_net_in_netlist(const Net* n) const

src/netlist/netlist_internal_manager.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,12 @@ namespace hal
442442
return false;
443443
}
444444

445+
std::unordered_set<Gate*> gates_to_check;
446+
445447
auto dsts = net->m_destinations_raw;
446448
for (auto dst : dsts)
447449
{
450+
gates_to_check.insert(dst->get_gate());
448451
if (!this->net_remove_destination_internal(net, dst))
449452
{
450453
return false;
@@ -454,12 +457,23 @@ namespace hal
454457
auto srcs = net->m_sources_raw;
455458
for (auto src : srcs)
456459
{
460+
gates_to_check.insert(src->get_gate());
457461
if (!this->net_remove_source_internal(net, src))
458462
{
459463
return false;
460464
}
461465
}
462466

467+
for (const Gate* g : gates_to_check)
468+
{
469+
Module* m = g->get_module();
470+
while (m)
471+
{
472+
m->delete_net(net);
473+
m = m->get_parent_module();
474+
}
475+
}
476+
463477
// remove from grouping
464478
if (Grouping* g = net->get_grouping(); g != nullptr)
465479
{

0 commit comments

Comments
 (0)