15 m_event_handler = std::make_unique<EventHandler>();
21 m_next_grouping_id = 1;
22 m_top_module =
nullptr;
35 log_info(
"netlist",
"the netlists with IDs {} and {} are not equal due to an unequal file name, design name, or device name.", m_netlist_id, other.
get_id());
41 log_info(
"netlist",
"the netlists with IDs {} and {} are not equal due to an unequal gate library.", m_netlist_id, other.
get_id());
45 if (m_gates.size() != other.
get_gates().size() || m_nets.size() != other.
get_nets().size() || m_modules.size() != other.
get_modules().size())
47 log_info(
"netlist",
"the netlists with IDs {} and {} are not equal due to an unequal number of gates, nets, or modules.", m_netlist_id, other.
get_id());
53 if (
const auto it = m_nets_map.find(
net->get_id()); it == m_nets_map.end() || *it->second != *
net)
55 log_info(
"netlist",
"the netlists with IDs {} and {} are not equal due to unequal nets.", m_netlist_id, other.
get_id());
63 log_info(
"netlist",
"the netlists with IDs {} and {} are not equal due to unequal modules.", m_netlist_id, other.
get_id());
82 if (
id != m_netlist_id)
84 auto old_id = m_netlist_id;
97 if (input_filename != m_file_name)
99 m_file_name = input_filename;
106 return m_design_name;
111 if (design_name != m_design_name)
113 m_design_name = design_name;
120 return m_device_name;
125 if (device_name != m_device_name)
127 m_device_name = device_name;
134 return m_gate_library;
139 return m_event_handler.get();
144 if (
auto res = m_manager->copy_netlist(
this); res.is_error())
146 return ERR(res.get_error());
162 if (!m_free_gate_ids.empty())
164 return *(m_free_gate_ids.begin());
166 while (m_used_gate_ids.find(m_next_gate_id) != m_used_gate_ids.end())
170 return m_next_gate_id;
175 return m_manager->create_gate(
id, gt,
name, x, y);
185 return m_manager->delete_gate(gate);
190 return gate !=
nullptr && m_gates_set.find(gate) != m_gates_set.end();
195 if (
auto it = m_gates_map.find(gate_id); it != m_gates_map.end())
197 return it->second.get();
200 log_debug(
"netlist",
"there is no gate with ID {} in the netlist with ID {}.", gate_id, m_netlist_id);
215 std::vector<Gate*> res;
216 for (
Gate*
g : m_gates)
236 log_debug(
"netlist",
"gate '{}' with ID {} is already registered as global VCC gate in the netlist with ID {}.", gate->
get_name(), gate->
get_id(), m_netlist_id);
239 m_vcc_gates.push_back(gate);
252 log_debug(
"netlist",
"gate '{}' with ID {} is already registered as global GND gate in the netlist with ID {}.", gate->
get_name(), gate->
get_id(), m_netlist_id);
255 m_gnd_gates.push_back(gate);
266 auto it = std::find(m_vcc_gates.begin(), m_vcc_gates.end(), gate);
267 if (it == m_vcc_gates.end())
269 log_debug(
"netlist",
"gate '{}' with ID {} is not registered as global VCC gate in the netlist with ID {}.", gate->
get_name(), gate->
get_id(), m_netlist_id);
272 m_vcc_gates.erase(it);
283 auto it = std::find(m_gnd_gates.begin(), m_gnd_gates.end(), gate);
284 if (it == m_gnd_gates.end())
286 log_debug(
"netlist",
"gate '{}' with ID {} is not registered as global GND gate in the netlist with ID {}.", gate->
get_name(), gate->
get_id(), m_netlist_id);
289 m_gnd_gates.erase(it);
296 return (std::find(m_vcc_gates.begin(), m_vcc_gates.end(), gate) != m_vcc_gates.end());
301 return (std::find(m_gnd_gates.begin(), m_gnd_gates.end(), gate) != m_gnd_gates.end());
322 if (!m_free_net_ids.empty())
324 return *(m_free_net_ids.begin());
326 while (m_used_net_ids.find(m_next_net_id) != m_used_net_ids.end())
330 return m_next_net_id;
335 return m_manager->create_net(
id,
name);
345 return m_manager->delete_net(
n);
350 return n !=
nullptr && m_nets_set.find(
n) != m_nets_set.end();
355 if (
auto it = m_nets_map.find(net_id); it != m_nets_map.end())
357 return it->second.get();
360 log_debug(
"netlist",
"there is no net with ID {} in the netlist with ID {}.", net_id, m_netlist_id);
375 std::vector<Net*> res;
376 for (
auto net : m_nets)
395 log_debug(
"netlist",
"net '{}' with ID {} is already registered as global input net in the netlist with ID {}.",
n->get_name(),
n->get_id(), m_netlist_id);
398 m_global_input_nets.push_back(
n);
401 if (m_manager->m_net_checks_enabled)
405 m_manager->module_check_net(ep->get_gate()->get_module(),
n,
true);
407 for (
Endpoint* ep :
n->get_destinations())
409 m_manager->module_check_net(ep->get_gate()->get_module(),
n,
true);
425 log_debug(
"netlist",
"net '{}' with ID {} is already registered as global output net in the netlist with ID {}.",
n->get_name(),
n->get_id(), m_netlist_id);
428 m_global_output_nets.push_back(
n);
431 if (m_manager->m_net_checks_enabled)
435 m_manager->module_check_net(ep->get_gate()->get_module(),
n,
true);
437 for (
Endpoint* ep :
n->get_destinations())
439 m_manager->module_check_net(ep->get_gate()->get_module(),
n,
true);
453 auto it = std::find(m_global_input_nets.begin(), m_global_input_nets.end(),
n);
454 if (it == m_global_input_nets.end())
456 log_debug(
"netlist",
"net '{}' with ID {} is not registered as global input net in the netlist with ID {}.",
n->get_name(),
n->get_id(), m_netlist_id);
459 m_global_input_nets.erase(it);
462 if (m_manager->m_net_checks_enabled)
466 m_manager->module_check_net(ep->get_gate()->get_module(),
n,
true);
468 for (
Endpoint* ep :
n->get_destinations())
470 m_manager->module_check_net(ep->get_gate()->get_module(),
n,
true);
484 auto it = std::find(m_global_output_nets.begin(), m_global_output_nets.end(),
n);
485 if (it == m_global_output_nets.end())
487 log_debug(
"netlist",
"net '{}' with ID {} is not registered as global output net in the netlist with ID {}.",
n->get_name(),
n->get_id(), m_netlist_id);
490 m_global_output_nets.erase(it);
493 if (m_manager->m_net_checks_enabled)
497 m_manager->module_check_net(ep->get_gate()->get_module(),
n,
true);
499 for (
Endpoint* ep :
n->get_destinations())
501 m_manager->module_check_net(ep->get_gate()->get_module(),
n,
true);
511 return (std::find(m_global_input_nets.begin(), m_global_input_nets.end(),
n) != m_global_input_nets.end());
516 return (std::find(m_global_output_nets.begin(), m_global_output_nets.end(),
n) != m_global_output_nets.end());
521 return m_global_input_nets;
526 return m_global_output_nets;
531 std::vector<Net*> gnd_nets;
532 for (
const auto& gnd_gate : m_gnd_gates)
534 for (
const auto& o_net : gnd_gate->get_fan_out_nets())
536 if (o_net->is_gnd_net())
538 gnd_nets.push_back(o_net);
548 std::vector<Net*> vcc_nets;
549 for (
const auto& vcc_gate : m_vcc_gates)
551 for (
const auto& o_net : vcc_gate->get_fan_out_nets())
553 if (o_net->is_vcc_net())
555 vcc_nets.push_back(o_net);
565 m_manager->m_net_checks_enabled = enable_checks;
576 if (!m_free_module_ids.empty())
578 return *(m_free_module_ids.begin());
580 while (m_used_module_ids.find(m_next_module_id) != m_used_module_ids.end())
584 return m_next_module_id;
589 auto m = m_manager->create_module(
id, parent,
name);
605 return m_manager->delete_module(
module);
615 if (
auto it = m_modules_map.find(
id); it != m_modules_map.end())
617 return it->second.get();
620 log_debug(
"netlist",
"there is no module with ID {} in the netlist with ID {}.",
id, m_netlist_id);
635 std::vector<Module*> res;
636 for (
auto module : m_modules)
649 return (
module !=
nullptr) && (m_modules_set.find(
module) != m_modules_set.end());
660 if (!m_free_grouping_ids.empty())
662 return *(m_free_grouping_ids.begin());
664 while (m_used_grouping_ids.find(m_next_grouping_id) != m_used_grouping_ids.end())
666 m_next_grouping_id++;
668 return m_next_grouping_id;
673 return m_manager->create_grouping(
id,
name);
683 return m_manager->delete_grouping(
g);
688 return n !=
nullptr && m_groupings_set.find(
n) != m_groupings_set.end();
693 if (
auto it = m_groupings_map.find(grouping_id); it != m_groupings_map.end())
695 return it->second.get();
698 log_debug(
"netlist",
"there is no grouping with ID {} in the netlist with ID {}.", grouping_id, m_netlist_id);
713 std::vector<Grouping*> res;
714 for (
auto grouping : m_groupings)
716 if (!filter(grouping))
720 res.push_back(grouping);
733 return m_next_gate_id;
743 return m_used_gate_ids;
748 m_used_gate_ids = ids;
753 return m_free_gate_ids;
758 m_free_gate_ids = ids;
763 return m_next_net_id;
773 return m_used_net_ids;
778 m_used_net_ids = ids;
783 return m_free_net_ids;
788 m_free_net_ids = ids;
793 return m_next_module_id;
798 m_next_module_id =
id;
803 return m_used_module_ids;
808 m_used_module_ids = ids;
813 return m_free_module_ids;
818 m_free_module_ids = ids;
823 return m_next_grouping_id;
828 m_next_grouping_id =
id;
833 return m_used_grouping_ids;
838 m_used_grouping_ids = ids;
843 return m_free_grouping_ids;
848 m_free_grouping_ids = ids;
859 m_manager->clear_caches();
864 std::string category;
865 std::pair<std::string, std::string> identifiers;
867 if (data_category.empty())
874 category = data_category;
875 identifiers = data_identifiers;
879 for (
Gate* gate : m_gates)
881 if (gate->has_data(category, identifiers.first))
885 i32 x_loc = std::stoi(std::get<1>(gate->get_data(category, identifiers.first)));
886 i32 y_loc = std::stoi(std::get<1>(gate->get_data(category, identifiers.second)));
888 gate->set_location(std::make_pair(x_loc, y_loc));
892 catch (
const std::exception& e)
904 log_warning(
"netlist",
"failed to load locations of {} gates.", failed);
const std::string & get_name() const
const std::pair< std::string, std::string > & get_gate_location_data_identifiers() const
const std::string & get_gate_location_data_category() const
bool assign_gates(const std::vector< Gate * > &gates)
@ marked_global_gnd
associated_data = id of gate
@ unmarked_global_output
associated_data = id of net
@ id_changed
associated_data = old id
@ device_name_changed
no associated_data
@ unmarked_global_gnd
associated_data = id of gate
@ input_filename_changed
no associated_data
@ unmarked_global_vcc
associated_data = id of gate
@ marked_global_vcc
associated_data = id of gate
@ unmarked_global_input
associated_data = id of net
@ design_name_changed
no associated_data
@ marked_global_output
associated_data = id of net
@ marked_global_input
associated_data = id of net
bool operator!=(const Netlist &other) const
void set_input_filename(const std::filesystem::path &path)
Module * get_top_module() const
const std::vector< Gate * > & get_gates() const
std::vector< Net * > get_vcc_nets() const
bool mark_vcc_gate(Gate *gate)
const std::vector< Net * > & get_global_input_nets() const
bool mark_gnd_gate(Gate *gate)
void set_used_gate_ids(const std::set< u32 > ids)
u32 get_unique_grouping_id()
void set_used_net_ids(const std::set< u32 > ids)
Grouping * create_grouping(const u32 grouping_id, const std::string &name="")
bool is_gate_in_netlist(const Gate *gate) const
Gate * get_gate_by_id(const u32 gate_id) const
bool is_module_in_netlist(const Module *module) const
bool delete_grouping(Grouping *grouping)
bool load_gate_locations_from_data(const std::string &data_category="", const std::pair< std::string, std::string > &data_identifiers=std::pair< std::string, std::string >())
void set_free_grouping_ids(const std::set< u32 > ids)
std::set< u32 > get_free_module_ids() const
u32 get_unique_module_id()
bool delete_net(Net *net)
bool is_gnd_gate(const Gate *gate) const
Net * create_net(const u32 net_id, const std::string &name)
std::vector< Net * > get_gnd_nets() const
const std::vector< Gate * > & get_gnd_gates() const
std::set< u32 > get_used_net_ids() const
void set_next_gate_id(const u32 id)
void set_free_module_ids(const std::set< u32 > ids)
void set_design_name(const std::string &name)
std::set< u32 > get_free_gate_ids() const
void enable_automatic_net_checks(bool enable_checks=true)
std::set< u32 > get_used_grouping_ids() const
bool delete_module(Module *module)
const std::vector< Gate * > & get_vcc_gates() const
bool unmark_gnd_gate(Gate *gate)
friend class NetlistInternalManager
bool delete_gate(Gate *gate)
bool is_grouping_in_netlist(const Grouping *grouping) const
u32 get_next_net_id() const
bool operator==(const Netlist &other) const
u32 get_next_module_id() const
Result< std::unique_ptr< Netlist > > copy() const
const std::vector< Module * > & get_modules() const
void set_id(const u32 id)
std::set< u32 > get_used_gate_ids() const
bool unmark_vcc_gate(Gate *gate)
void set_free_net_ids(const std::set< u32 > ids)
const std::string & get_device_name() const
void set_next_module_id(const u32 id)
bool mark_global_input_net(Net *net)
bool is_net_in_netlist(const Net *net) const
std::set< u32 > get_used_module_ids() const
Module * get_module_by_id(u32 module_id) const
bool is_vcc_gate(const Gate *gate) const
Gate * create_gate(const u32 gate_id, GateType *gate_type, const std::string &name="", i32 x=-1, i32 y=-1)
void set_free_gate_ids(const std::set< u32 > ids)
bool mark_global_output_net(Net *net)
void set_next_grouping_id(const u32 id)
Net * get_net_by_id(u32 net_id) const
std::set< u32 > get_free_grouping_ids() const
void set_used_grouping_ids(const std::set< u32 > ids)
const std::string & get_design_name() const
const std::vector< Net * > & get_global_output_nets() const
const std::vector< Net * > & get_nets() const
bool unmark_global_output_net(Net *net)
void set_device_name(const std::string &name)
const std::vector< Grouping * > & get_groupings() const
bool is_global_input_net(const Net *net) const
void set_next_net_id(const u32 id)
void set_used_module_ids(const std::set< u32 > ids)
u32 get_next_grouping_id() const
u32 get_next_gate_id() const
std::filesystem::path get_input_filename() const
const GateLibrary * get_gate_library() const
Netlist(const GateLibrary *gate_library)
Grouping * get_grouping_by_id(u32 grouping_id) const
std::set< u32 > get_free_net_ids() const
EventHandler * get_event_handler() const
bool unmark_global_input_net(Net *net)
bool is_global_output_net(const Net *net) const
Module * create_module(const u32 module_id, const std::string &name, Module *parent, const std::vector< Gate * > &gates={})
#define log_error(channel,...)
#define log_debug(channel,...)
#define log_info(channel,...)
#define log_warning(channel,...)
const Module * module(const Gate *g, const NodeBoxes &boxes)