@@ -448,7 +448,12 @@ namespace hal
448
448
for (auto dst : dsts)
449
449
{
450
450
gates_to_check.insert (dst->get_gate ());
451
- if (!this ->net_remove_destination_internal (net, dst))
451
+ int inx = net->get_destination_index (dst);
452
+ if (inx < 0 )
453
+ {
454
+ return false ;
455
+ }
456
+ if (!this ->remove_destination_by_index (net, inx))
452
457
{
453
458
return false ;
454
459
}
@@ -458,7 +463,12 @@ namespace hal
458
463
for (auto src : srcs)
459
464
{
460
465
gates_to_check.insert (src->get_gate ());
461
- if (!this ->net_remove_source_internal (net, src))
466
+ int inx = net->get_source_index (src);
467
+ if (inx < 0 )
468
+ {
469
+ return false ;
470
+ }
471
+ if (!this ->remove_source_by_index (net, inx))
462
472
{
463
473
return false ;
464
474
}
@@ -573,6 +583,57 @@ namespace hal
573
583
return new_endpoint_raw;
574
584
}
575
585
586
+ bool NetlistInternalManager::remove_destination_by_index (Net* net, int inx)
587
+ {
588
+ size_t n = net->m_destinations .size ();
589
+ if (inx >= n) return false ;
590
+ auto ep = net->m_destinations_raw .at (inx);
591
+ auto gate = ep->get_gate ();
592
+
593
+ if (!m_netlist->is_gate_in_netlist (gate))
594
+ {
595
+ return false ;
596
+ }
597
+ utils::unordered_vector_erase (gate->m_in_endpoints , ep);
598
+ utils::unordered_vector_erase (gate->m_in_nets , net);
599
+
600
+ if (inx < n-1 )
601
+ {
602
+ net->m_destinations [inx] = std::move (net->m_destinations .back ());
603
+ net->m_destinations_raw [inx] = net->m_destinations_raw .back ();
604
+ }
605
+ net->m_destinations .pop_back ();
606
+ net->m_destinations_raw .pop_back ();
607
+ m_event_handler->notify (NetEvent::event::dst_removed, net, gate->get_id ());
608
+ return true ;
609
+ }
610
+
611
+ bool NetlistInternalManager::remove_source_by_index (Net* net, int inx)
612
+ {
613
+ size_t n = net->m_sources .size ();
614
+ if (inx >= n) return false ;
615
+ auto ep = net->m_sources_raw .at (inx);
616
+ auto gate = ep->get_gate ();
617
+
618
+ if (!m_netlist->is_gate_in_netlist (gate))
619
+ {
620
+ return false ;
621
+ }
622
+ utils::unordered_vector_erase (gate->m_out_endpoints , ep);
623
+ utils::unordered_vector_erase (gate->m_out_nets , net);
624
+
625
+ if (inx < n-1 )
626
+ {
627
+ net->m_sources [inx] = std::move (net->m_sources .back ());
628
+ net->m_sources_raw [inx] = net->m_sources_raw .back ();
629
+ }
630
+ net->m_sources .pop_back ();
631
+ net->m_sources_raw .pop_back ();
632
+ m_event_handler->notify (NetEvent::event::src_removed, net, gate->get_id ());
633
+ return true ;
634
+ }
635
+
636
+ /*
576
637
bool NetlistInternalManager::net_remove_source_internal(Net* net, Endpoint* ep)
577
638
{
578
639
auto gate = ep->get_gate();
@@ -599,17 +660,26 @@ namespace hal
599
660
600
661
return false;
601
662
}
663
+ */
602
664
603
665
bool NetlistInternalManager::net_remove_source (Net* net, Endpoint* ep)
604
666
{
667
+ int inx = net->get_source_index (ep);
668
+ if (inx < 0 )
669
+ {
670
+ log_warning (" net" , " given endpoint is not a source of net '{}' with ID {}." ,
671
+ net->get_name (), net->get_id ());
672
+ return false ;
673
+ }
674
+
605
675
auto gate = ep->get_gate ();
606
676
607
- if (!m_netlist->is_net_in_netlist (net) || !m_netlist->is_gate_in_netlist (gate) || !net-> is_a_source (ep) )
677
+ if (!m_netlist->is_net_in_netlist (net) || !m_netlist->is_gate_in_netlist (gate))
608
678
{
609
679
return false ;
610
680
}
611
681
612
- if (!net_remove_source_internal (net, ep ))
682
+ if (!remove_source_by_index (net, inx ))
613
683
{
614
684
log_warning (" net" ,
615
685
" output pin '{}' of gate '{}' with ID {} is not a source of net '{}' with ID {} in netlist with ID {}" ,
@@ -718,6 +788,7 @@ namespace hal
718
788
return new_endpoint_raw;
719
789
}
720
790
791
+ /*
721
792
bool NetlistInternalManager::net_remove_destination_internal(Net* net, Endpoint* ep)
722
793
{
723
794
auto gate = ep->get_gate();
@@ -744,17 +815,26 @@ namespace hal
744
815
745
816
return false;
746
817
}
818
+ */
747
819
748
820
bool NetlistInternalManager::net_remove_destination (Net* net, Endpoint* ep)
749
821
{
822
+ int inx = net->get_destination_index (ep);
823
+ if (inx < 0 )
824
+ {
825
+ log_warning (" net" , " given endpoint is not a destination of net '{}' with ID {}." ,
826
+ net->get_name (), net->get_id ());
827
+ return false ;
828
+ }
829
+
750
830
auto gate = ep->get_gate ();
751
831
752
- if (!m_netlist->is_net_in_netlist (net) || !m_netlist->is_gate_in_netlist (gate) || !net-> is_a_destination (ep) )
832
+ if (!m_netlist->is_net_in_netlist (net) || !m_netlist->is_gate_in_netlist (gate))
753
833
{
754
834
return false ;
755
835
}
756
836
757
- if (!net_remove_destination_internal (net,ep ))
837
+ if (!remove_destination_by_index (net, inx ))
758
838
{
759
839
log_warning (" net" ,
760
840
" input pin '{}' of gate '{}' with ID {} is not a destination of net '{}' with ID {} in netlist with ID {}" ,
0 commit comments