17 m_event_handler = std::make_unique<EventHandler>();
23 m_next_grouping_id = 1;
24 m_top_module =
nullptr;
37 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());
43 log_info(
"netlist",
"the netlists with IDs {} and {} are not equal due to an unequal gate library.", m_netlist_id, other.
get_id());
47 if (m_gates.size() != other.
get_gates().size() || m_nets.size() != other.
get_nets().size() || m_modules.size() != other.
get_modules().size())
49 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());
55 if (
const auto it = m_nets_map.find(
net->get_id()); it == m_nets_map.end() || *it->second != *
net)
57 log_info(
"netlist",
"the netlists with IDs {} and {} are not equal due to unequal nets.", m_netlist_id, other.
get_id());
65 log_info(
"netlist",
"the netlists with IDs {} and {} are not equal due to unequal modules.", m_netlist_id, other.
get_id());
84 if (
id != m_netlist_id)
86 auto old_id = m_netlist_id;
99 if (input_filename != m_file_name)
101 m_file_name = input_filename;
108 return m_design_name;
113 if (design_name != m_design_name)
115 m_design_name = design_name;
122 return m_device_name;
127 if (device_name != m_device_name)
129 m_device_name = device_name;
136 return m_gate_library.get();
141 return m_event_handler.get();
146 if (
auto res = m_manager->copy_netlist(
this); res.is_error())
148 return ERR(res.get_error());
164 if (!m_free_gate_ids.empty())
166 return *(m_free_gate_ids.begin());
168 while (m_used_gate_ids.find(m_next_gate_id) != m_used_gate_ids.end())
172 return m_next_gate_id;
177 return m_manager->create_gate(
id, gt,
name,
x,
y);
187 return m_manager->delete_gate(gate);
192 return gate !=
nullptr && m_gates_set.find(gate) != m_gates_set.end();
197 if (
auto it = m_gates_map.find(gate_id); it != m_gates_map.end())
199 return it->second.get();
202 log_debug(
"netlist",
"there is no gate with ID {} in the netlist with ID {}.", gate_id, m_netlist_id);
217 std::vector<Gate*> res;
218 for (
Gate* g : m_gates)
238 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);
241 m_vcc_gates.push_back(gate);
254 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);
257 m_gnd_gates.push_back(gate);
268 auto it = std::find(m_vcc_gates.begin(), m_vcc_gates.end(), gate);
269 if (it == m_vcc_gates.end())
271 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);
274 m_vcc_gates.erase(it);
285 auto it = std::find(m_gnd_gates.begin(), m_gnd_gates.end(), gate);
286 if (it == m_gnd_gates.end())
288 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);
291 m_gnd_gates.erase(it);
298 return (std::find(m_vcc_gates.begin(), m_vcc_gates.end(), gate) != m_vcc_gates.end());
303 return (std::find(m_gnd_gates.begin(), m_gnd_gates.end(), gate) != m_gnd_gates.end());
324 if (!m_free_net_ids.empty())
326 return *(m_free_net_ids.begin());
328 while (m_used_net_ids.find(m_next_net_id) != m_used_net_ids.end())
332 return m_next_net_id;
337 return m_manager->create_net(
id,
name);
347 return m_manager->delete_net(n);
352 return n !=
nullptr && m_nets_set.find(n) != m_nets_set.end();
357 if (
auto it = m_nets_map.find(net_id); it != m_nets_map.end())
359 return it->second.get();
362 log_debug(
"netlist",
"there is no net with ID {} in the netlist with ID {}.", net_id, m_netlist_id);
377 std::vector<Net*> res;
378 for (
auto net : m_nets)
397 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);
400 m_global_input_nets.push_back(n);
403 if (m_manager->m_net_checks_enabled)
407 m_manager->module_check_net(ep->get_gate()->get_module(), n,
true);
411 m_manager->module_check_net(ep->get_gate()->get_module(), n,
true);
427 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);
430 m_global_output_nets.push_back(n);
433 if (m_manager->m_net_checks_enabled)
437 m_manager->module_check_net(ep->get_gate()->get_module(), n,
true);
441 m_manager->module_check_net(ep->get_gate()->get_module(), n,
true);
455 auto it = std::find(m_global_input_nets.begin(), m_global_input_nets.end(), n);
456 if (it == m_global_input_nets.end())
458 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);
461 m_global_input_nets.erase(it);
464 if (m_manager->m_net_checks_enabled)
468 m_manager->module_check_net(ep->get_gate()->get_module(), n,
true);
472 m_manager->module_check_net(ep->get_gate()->get_module(), n,
true);
486 auto it = std::find(m_global_output_nets.begin(), m_global_output_nets.end(), n);
487 if (it == m_global_output_nets.end())
489 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);
492 m_global_output_nets.erase(it);
495 if (m_manager->m_net_checks_enabled)
499 m_manager->module_check_net(ep->get_gate()->get_module(), n,
true);
503 m_manager->module_check_net(ep->get_gate()->get_module(), n,
true);
513 return (std::find(m_global_input_nets.begin(), m_global_input_nets.end(), n) != m_global_input_nets.end());
518 return (std::find(m_global_output_nets.begin(), m_global_output_nets.end(), n) != m_global_output_nets.end());
523 return m_global_input_nets;
528 return m_global_output_nets;
533 std::vector<Net*> gnd_nets;
534 for (
const auto& gnd_gate : m_gnd_gates)
536 for (
const auto& o_net : gnd_gate->get_fan_out_nets())
538 if (o_net->is_gnd_net())
540 gnd_nets.push_back(o_net);
550 std::vector<Net*> vcc_nets;
551 for (
const auto& vcc_gate : m_vcc_gates)
553 for (
const auto& o_net : vcc_gate->get_fan_out_nets())
555 if (o_net->is_vcc_net())
557 vcc_nets.push_back(o_net);
567 m_manager->m_net_checks_enabled = enable_checks;
578 if (!m_free_module_ids.empty())
580 return *(m_free_module_ids.begin());
582 while (m_used_module_ids.find(m_next_module_id) != m_used_module_ids.end())
586 return m_next_module_id;
591 auto m = m_manager->create_module(
id, parent,
name);
607 return m_manager->delete_module(
module);
617 if (
auto it = m_modules_map.find(
id); it != m_modules_map.end())
619 return it->second.get();
622 log_debug(
"netlist",
"there is no module with ID {} in the netlist with ID {}.",
id, m_netlist_id);
637 std::vector<Module*> res;
638 for (
auto module : m_modules)
651 return (
module !=
nullptr) && (m_modules_set.find(
module) != m_modules_set.end());
662 if (!m_free_grouping_ids.empty())
664 return *(m_free_grouping_ids.begin());
666 while (m_used_grouping_ids.find(m_next_grouping_id) != m_used_grouping_ids.end())
668 m_next_grouping_id++;
670 return m_next_grouping_id;
675 return m_manager->create_grouping(
id,
name);
685 return m_manager->delete_grouping(g);
690 return n !=
nullptr && m_groupings_set.find(n) != m_groupings_set.end();
695 if (
auto it = m_groupings_map.find(grouping_id); it != m_groupings_map.end())
697 return it->second.get();
700 log_debug(
"netlist",
"there is no grouping with ID {} in the netlist with ID {}.", grouping_id, m_netlist_id);
715 std::vector<Grouping*> res;
716 for (
auto grouping : m_groupings)
718 if (!filter(grouping))
722 res.push_back(grouping);
735 return m_next_gate_id;
745 return m_used_gate_ids;
750 m_used_gate_ids = ids;
755 return m_free_gate_ids;
760 m_free_gate_ids = ids;
765 return m_next_net_id;
775 return m_used_net_ids;
780 m_used_net_ids = ids;
785 return m_free_net_ids;
790 m_free_net_ids = ids;
795 return m_next_module_id;
800 m_next_module_id =
id;
805 return m_used_module_ids;
810 m_used_module_ids = ids;
815 return m_free_module_ids;
820 m_free_module_ids = ids;
825 return m_next_grouping_id;
830 m_next_grouping_id =
id;
835 return m_used_grouping_ids;
840 m_used_grouping_ids = ids;
845 return m_free_grouping_ids;
850 m_free_grouping_ids = ids;
861 m_manager->clear_caches();
866 std::string category;
867 std::pair<std::string, std::string> identifiers;
869 if (data_category.empty())
871 category = m_gate_library->get_gate_location_data_category();
872 identifiers = m_gate_library->get_gate_location_data_identifiers();
876 category = data_category;
877 identifiers = data_identifiers;
881 for (
Gate* gate : m_gates)
883 if (gate->has_data(category, identifiers.first))
887 i32 x_loc = std::stoi(std::get<1>(gate->get_data(category, identifiers.first)));
888 i32 y_loc = std::stoi(std::get<1>(gate->get_data(category, identifiers.second)));
890 gate->set_location(std::make_pair(x_loc, y_loc));
894 catch (
const std::exception& e)
906 log_warning(
"netlist",
"failed to load locations of {} gates.", failed);
const std::string & get_name() const
bool assign_gates(const std::vector< Gate * > &gates)
const std::string & get_name() const
std::vector< Endpoint * > get_destinations(const std::function< bool(Endpoint *ep)> &filter=nullptr) const
std::vector< Endpoint * > get_sources(const std::function< bool(Endpoint *ep)> &filter=nullptr) const
@ 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)
std::shared_ptr< GateLibrary > get_owning(const GateLibrary *gate_lib)
std::unique_ptr< RuntimeLibrary > library