HAL
event_log.cpp
Go to the documentation of this file.
2 
7 #include "hal_core/netlist/net.h"
10 
11 namespace hal
12 {
13  namespace event_log
14  {
15  namespace
16  {
17  bool mEnableEventLog = false;
18  }
19 
20  void enable_event_log(bool enable)
21  {
22  mEnableEventLog = enable;
23  }
24 
25  void handle_gate_event(GateEvent::event event, Gate* gate, u32 associated_data)
26  {
27  UNUSED(associated_data);
28  if (!mEnableEventLog)
29  return;
30 
31  if (event == GateEvent::event::created)
32  {
33  log_info("event", "created new gate '{}' (type '{}', id {:08x})", gate->get_name(), gate->get_type()->get_name(), gate->get_id());
34  }
35  else if (event == GateEvent::event::removed)
36  {
37  log_info("event", "deleted gate '{}' (type '{}', id {:08x})", gate->get_name(), gate->get_type()->get_name(), gate->get_id());
38  }
39  else if (event == GateEvent::event::name_changed)
40  {
41  log_info("event", "changed name of gate with id {:08x} to '{}'", gate->get_id(), gate->get_name());
42  }
43  else
44  {
45  log_error("event", "unknown gate event");
46  }
47  }
48 
49  void handle_net_event(NetEvent::event event, Net* net, u32 associated_data)
50  {
51  if (!mEnableEventLog)
52  return;
53 
54  if (event == NetEvent::event::created)
55  {
56  log_info("event", "created new net '{}' (id {:08x})", net->get_name(), net->get_id());
57  }
58  else if (event == NetEvent::event::removed)
59  {
60  log_info("event", "deleted net '{}' (id {:08x})", net->get_name(), net->get_id());
61  }
62  else if (event == NetEvent::event::name_changed)
63  {
64  log_info("event", "changed name of net with id {:08x} to '{}'", net->get_id(), net->get_name());
65  }
66  else if (event == NetEvent::event::src_added)
67  {
68  auto gate = net->get_netlist()->get_gate_by_id(associated_data);
69  log_info("event", "added gate '{}' (id {:08x}) as a source for net '{}' (id {:08x})", gate->get_name(), gate->get_id(), net->get_name(), net->get_id());
70  }
71  else if (event == NetEvent::event::src_removed)
72  {
73  auto gate = net->get_netlist()->get_gate_by_id(associated_data);
74  log_info("event", "removed source gate '{}' (id {:08x}) from net '{}' (id {:08x})", gate->get_name(), gate->get_id(), net->get_name(), net->get_id());
75  }
76  else if (event == NetEvent::event::dst_added)
77  {
78  auto gate = net->get_netlist()->get_gate_by_id(associated_data);
79  log_info("event", "added gate '{}' (id {:08x}) as a destination for net '{}' (id {:08x})", gate->get_name(), gate->get_id(), net->get_name(), net->get_id());
80  }
81  else if (event == NetEvent::event::dst_removed)
82  {
83  auto gate = net->get_netlist()->get_gate_by_id(associated_data);
84  log_info("event", "removed destination gate '{}' (id {:08x}) from net '{}' (id {:08x})", gate->get_name(), gate->get_id(), net->get_name(), net->get_id());
85  }
86  else
87  {
88  log_error("event", "unknown net event");
89  }
90  }
91 
93  {
94  if (!mEnableEventLog)
95  return;
96 
98  {
99  log_info("event", "changed netlist id from {:08x} to {:08x}", associated_data, netlist->get_id());
100  }
102  {
103  log_info("event", "changed input filename of netlist with id {:08x} to '{}'", netlist->get_id(), netlist->get_input_filename().string());
104  }
106  {
107  log_info("event", "changed design name of netlist with id {:08x} to '{}'", netlist->get_id(), netlist->get_design_name());
108  }
110  {
111  log_info("event", "changed target device name of netlist with id {:08x} to '{}'", netlist->get_id(), netlist->get_device_name());
112  }
113  else if (event == NetlistEvent::event::marked_global_vcc)
114  {
115  auto gate = netlist->get_gate_by_id(associated_data);
116  log_info("event", "marked gate '{}' (id {:08x}) as a global vcc gate in netlist with id {:08x}", gate->get_name(), gate->get_id(), netlist->get_id());
117  }
118  else if (event == NetlistEvent::event::marked_global_gnd)
119  {
120  auto gate = netlist->get_gate_by_id(associated_data);
121  log_info("event", "marked gate '{}' (id {:08x}) as a global gnd gate in netlist with id {:08x}", gate->get_name(), gate->get_id(), netlist->get_id());
122  }
124  {
125  auto gate = netlist->get_gate_by_id(associated_data);
126  log_info("event", "unmarked gate '{}' (id {:08x}) as a global vcc gate in netlist with id {:08x}", gate->get_name(), gate->get_id(), netlist->get_id());
127  }
129  {
130  auto gate = netlist->get_gate_by_id(associated_data);
131  log_info("event", "unmarked gate '{}' (id {:08x}) as a global gnd gate in netlist with id {:08x}", gate->get_name(), gate->get_id(), netlist->get_id());
132  }
134  {
135  auto net = netlist->get_net_by_id(associated_data);
136  log_info("event", "marked net '{}' (id {:08x}) as a global input net in netlist with id {:08x}", net->get_name(), net->get_id(), netlist->get_id());
137  }
139  {
140  auto net = netlist->get_net_by_id(associated_data);
141  log_info("event", "marked net '{}' (id {:08x}) as a global output net in netlist with id {:08x}", net->get_name(), net->get_id(), netlist->get_id());
142  }
144  {
145  auto net = netlist->get_net_by_id(associated_data);
146  log_info("event", "unmarked net '{}' (id {:08x}) as a global input net in netlist with id {:08x}", net->get_name(), net->get_id(), netlist->get_id());
147  }
149  {
150  auto net = netlist->get_net_by_id(associated_data);
151  log_info("event", "unmarked net '{}' (id {:08x}) as a global output net in netlist with id {:08x}", net->get_name(), net->get_id(), netlist->get_id());
152  }
153  else
154  {
155  log_error("event", "unknown netlist event");
156  }
157  }
158 
159  void handle_grouping_event(GroupingEvent::event event, Grouping* grp, u32 associated_data)
160  {
161  if (!mEnableEventLog)
162  return;
163 
164  if (event == GroupingEvent::event::created)
165  {
166  log_info("event", "created new grouping '{}' (id {:08x})", grp->get_name(), grp->get_id());
167  }
168  else if (event == GroupingEvent::event::removed)
169  {
170  log_info("event", "deleted grouping '{}' (id {:08x})", grp->get_name(), grp->get_id());
171  }
172  else if (event == GroupingEvent::event::name_changed)
173  {
174  log_info("event", "changed name of grouping with id {:08x} to '{}'", grp->get_id(), grp->get_name());
175  }
176  else if (event == GroupingEvent::event::color_changed)
177  {
178  log_info("event", "changed color of grouping with id {:08x} to '{}'", grp->get_id(), grp->get_color().toString());
179  }
180  else if (event == GroupingEvent::event::gate_assigned)
181  {
182  Gate* gate = grp->get_netlist()->get_gate_by_id(associated_data);
183  log_info("event", "added gate '{}' (id {:08x}) to grouping '{}' (id {:08x})", gate->get_name(), gate->get_id(), grp->get_name(), grp->get_id());
184  }
185  else if (event == GroupingEvent::event::gate_removed)
186  {
187  Gate* gate = grp->get_netlist()->get_gate_by_id(associated_data);
188  log_info("event", "removed gate '{}' (id {:08x}) from grouping '{}' (id {:08x})", gate->get_name(), gate->get_id(), grp->get_name(), grp->get_id());
189  }
190  else if (event == GroupingEvent::event::net_assigned)
191  {
192  Net* net = grp->get_netlist()->get_net_by_id(associated_data);
193  log_info("event", "added net '{}' (id {:08x}) to grouping '{}' (id {:08x})", net->get_name(), net->get_id(), grp->get_name(), grp->get_id());
194  }
195  else if (event == GroupingEvent::event::net_removed)
196  {
197  Net* net = grp->get_netlist()->get_net_by_id(associated_data);
198  log_info("event", "removed net '{}' (id {:08x}) from grouping '{}' (id {:08x})", net->get_name(), net->get_id(), grp->get_name(), grp->get_id());
199  }
200  else if (event == GroupingEvent::event::module_assigned)
201  {
202  Module* m = grp->get_netlist()->get_module_by_id(associated_data);
203  log_info("event", "added module '{}' (id {:08x}) to grouping '{}' (id {:08x})", m->get_name(), m->get_id(), grp->get_name(), grp->get_id());
204  }
205  else if (event == GroupingEvent::event::module_removed)
206  {
207  Module* m = grp->get_netlist()->get_module_by_id(associated_data);
208  log_info("event", "removed module '{}' (id {:08x}) from grouping '{}' (id {:08x})", m->get_name(), m->get_id(), grp->get_name(), grp->get_id());
209  }
210  else
211  {
212  log_error("event", "unknown grouping event");
213  }
214  }
215 
216  void handle_module_event(ModuleEvent::event event, Module* module, u32 associated_data)
217  {
218  if (!mEnableEventLog)
219  return;
220 
221  if (event == ModuleEvent::event::created)
222  {
223  log_info("event", "created new submodule '{}' (id {:08x})", module->get_name(), module->get_id());
224  }
225  else if (event == ModuleEvent::event::removed)
226  {
227  log_info("event", "deleted submodule '{}' (id {:08x})", module->get_name(), module->get_id());
228  }
229  else if (event == ModuleEvent::event::name_changed)
230  {
231  log_info("event", "changed name of module '{}' (id {:08x}) to '{}'", module->get_name(), module->get_id(), module->get_name());
232  }
233  else if (event == ModuleEvent::event::type_changed)
234  {
235  log_info("event", "changed type of module '{}' (id {:08x}) to '{}'", module->get_name(), module->get_id(), module->get_type());
236  }
237  else if (event == ModuleEvent::event::parent_changed)
238  {
239  log_info("event",
240  "changed parent of submodule '{}' (id {:08x}) to module '{}' (id {:08x})",
241  module->get_name(),
242  module->get_id(),
245  }
246  else if (event == ModuleEvent::event::submodule_added)
247  {
248  log_info("event",
249  "added submodule '{}' (id {:08x}) to module '{}' (id {:08x})",
250  module->get_netlist()->get_module_by_id(associated_data)->get_name(),
251  associated_data,
252  module->get_name(),
253  module->get_id());
254  }
255  else if (event == ModuleEvent::event::submodule_removed)
256  {
257  log_info("event", "removed submodule with id {:08x} from module '{}' (id {:08x})", associated_data, module->get_name(), module->get_id());
258  }
259  else if (event == ModuleEvent::event::gates_assign_begin)
260  {
261  u32 num_gates = associated_data;
262  log_info("event", "trying to assign {} gates to module '{}' (id {:08x})", num_gates, module->get_name(), module->get_id());
263  }
264  else if (event == ModuleEvent::event::gates_assign_end)
265  {
266  u32 num_gates = associated_data;
267  log_info("event", "successfully assigned {} gates to module '{}' (id {:08x})", num_gates, module->get_name(), module->get_id());
268  }
269  else if (event == ModuleEvent::event::gate_assigned)
270  {
271  auto gate = module->get_netlist()->get_gate_by_id(associated_data);
272  log_info("event", "inserted gate '{}' (id {:08x}) into module '{}' (id {:08x})", gate->get_name(), associated_data, module->get_name(), module->get_id());
273  }
274  else if (event == ModuleEvent::event::gates_remove_begin)
275  {
276  u32 num_gates = associated_data;
277  log_info("event", "trying to remove {} gates to module '{}' (id {:08x})", num_gates, module->get_name(), module->get_id());
278  }
279  else if (event == ModuleEvent::event::gates_remove_end)
280  {
281  u32 num_gates = associated_data;
282  log_info("event", "successfully removed {} gates to module '{}' (id {:08x})", num_gates, module->get_name(), module->get_id());
283  }
284  else if (event == ModuleEvent::event::gate_removed)
285  {
286  log_info("event", "removed gate with id {:08x} from module '{}' (id {:08x})", associated_data, module->get_name(), module->get_id());
287  }
288  else if (event == ModuleEvent::event::pin_changed)
289  {
290  PinEvent pev = (PinEvent) (associated_data&0xF);
291  u32 id = (associated_data >> 4);
292 
293  log_info("event", "module '{}' (id {:08x}) port event '{}' id={}", module->get_name(), module->get_id(), enum_to_string<PinEvent>(pev), id);
294  }
295  else
296  {
297  log_error("event", "unknown module event");
298  }
299  }
300  } // namespace event_log
301 
302  void initialize()
303  {
305  }
306 
307 } // namespace hal
@ removed
no associated_data
@ name_changed
no associated_data
@ created
no associated_data
Definition: gate.h:58
GateType * get_type() const
Definition: gate.cpp:125
const std::string & get_name() const
Definition: gate.cpp:105
u32 get_id() const
Definition: gate.cpp:95
const std::string & get_name() const
Definition: gate_type.cpp:64
@ net_assigned
associated_data = id of inserted net
@ module_removed
associated_data = id of removed module
@ color_changed
no associated_data
@ gate_assigned
associated_data = id of inserted gate
@ module_assigned
associated_data = id of inserted module
@ gate_removed
associated_data = id of removed gate
@ removed
no associated_data
@ net_removed
associated_data = id of removed net
@ name_changed
no associated_data
@ created
no associated_data
utils::Color get_color() const
Definition: grouping.cpp:47
Netlist * get_netlist() const
Definition: grouping.cpp:64
std::string get_name() const
Definition: grouping.cpp:42
u32 get_id() const
Definition: grouping.cpp:22
std::shared_ptr< spdlog::logger > add_channel(const std::string &channel_name, const std::vector< std::shared_ptr< log_sink >> &sinks, const std::string &level="info")
Definition: log.cpp:100
static std::shared_ptr< log_sink > create_gui_sink()
Definition: log.cpp:274
static std::shared_ptr< log_sink > create_file_sink(const std::filesystem::path &file_name="", const bool truncate=false)
Definition: log.cpp:247
static std::shared_ptr< log_sink > create_stdout_sink(const bool colored=true)
Definition: log.cpp:216
static LogManager * get_instance(const std::filesystem::path &file_name="")
Definition: log.cpp:61
@ gates_remove_end
associated_data = number of removed gates
@ gate_assigned
associated_data = id of inserted gate
@ gate_removed
associated_data = id of removed gate
@ pin_changed
associated_data = [4LSB: type of action] [28HSB: id of pin group or pin]
@ submodule_removed
associated_data = id of removed module
@ gates_assign_begin
associated_data = number of gates to assign
@ type_changed
no associated_data
@ gates_assign_end
associated_data = number of assigned gates
@ gates_remove_begin
associated_data = number of gates to remove
@ submodule_added
associated_data = id of added module
@ removed
no associated_data
@ parent_changed
no associated_data
@ name_changed
no associated_data
@ created
no associated_data
Module * get_parent_module() const
Definition: module.cpp:125
std::string get_name() const
Definition: module.cpp:87
Netlist * get_netlist() const
Definition: module.cpp:317
std::string get_type() const
Definition: module.cpp:106
u32 get_id() const
Definition: module.cpp:82
@ src_added
associated_data = id of src gate
@ dst_removed
associated_data = id of dst gate
@ src_removed
associated_data = id of src gate
@ dst_added
associated_data = id of dst gate
@ removed
no associated_data
@ name_changed
no associated_data
@ created
no associated_data
Definition: net.h:58
@ 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
Gate * get_gate_by_id(const u32 gate_id) const
Definition: netlist.cpp:193
Module * get_module_by_id(u32 module_id) const
Definition: netlist.cpp:613
Net * get_net_by_id(u32 net_id) const
Definition: netlist.cpp:353
#define UNUSED(expr)
Definition: defines.h:49
#define log_error(channel,...)
Definition: log.h:78
#define log_info(channel,...)
Definition: log.h:70
const Module * module(const Gate *g, const NodeBoxes &boxes)
void handle_net_event(NetEvent::event event, Net *net, u32 associated_data)
Definition: event_log.cpp:49
void handle_gate_event(GateEvent::event event, Gate *gate, u32 associated_data)
Definition: event_log.cpp:25
void handle_netlist_event(NetlistEvent::event event, Netlist *netlist, u32 associated_data)
Definition: event_log.cpp:92
void handle_grouping_event(GroupingEvent::event event, Grouping *grp, u32 associated_data)
Definition: event_log.cpp:159
void enable_event_log(bool enable)
Definition: event_log.cpp:20
void handle_module_event(ModuleEvent::event event, Module *module, u32 associated_data)
Definition: event_log.cpp:216
void initialize()
Definition: event_log.cpp:302
PinEvent
Definition: pin_event.h:42
quint32 u32
Net * net
std::string toString()
Definition: utils.h:786