HAL  v4.5.0-254-g8f9f6a423
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
gate_type_components.cpp
Go to the documentation of this file.
12 
13 namespace hal
14 {
16  {
17  py::class_<GateTypeComponent, RawPtrWrapper<GateTypeComponent>> py_gate_type_component(m, "GateTypeComponent", R"(
18  A component defining additional functionality of a gate type.
19  )");
20 
21  py::enum_<GateTypeComponent::ComponentType>(py_gate_type_component, "ComponentType", R"(
22  The type of a gate type component.
23  )")
24  .value("lut", GateTypeComponent::ComponentType::lut, R"(LUT component type.)")
25  .value("ff", GateTypeComponent::ComponentType::ff, R"(Flip-flop component type.)")
26  .value("latch", GateTypeComponent::ComponentType::latch, R"(Latch component type.)")
27  .value("ram", GateTypeComponent::ComponentType::ram, R"(RAM component type.)")
28  .value("mac", GateTypeComponent::ComponentType::mac, R"(MAC component type.)")
29  .value("init", GateTypeComponent::ComponentType::init, R"(Initializiation component type.)")
30  .value("state", GateTypeComponent::ComponentType::state, R"(State component type.)")
31  .value("ram_port", GateTypeComponent::ComponentType::ram_port, R"(RAM port component type.)")
32  .export_values();
33 
34  py_gate_type_component.def_property_readonly("type", py::cpp_function(&GateTypeComponent::get_type, py::is_method(py_gate_type_component), borrowed()), R"(
35  The type of the gate type component.
36 
37  :type: hal_py.GateTypeComponent.ComponentType
38  )");
39 
40  py_gate_type_component.def("get_type", &GateTypeComponent::get_type, borrowed(), R"(
41  Get the type of the gate type component.
42 
43  :returns: The type of the gate type component.
44  :rtype: hal_py.GateTypeComponent.ComponentType
45  )");
46 
47  py_gate_type_component.def_property_readonly("components", py::cpp_function(&GateTypeComponent::get_components, py::is_method(py_gate_type_component), borrowed()), R"(
48  All components of the gate type component as a list.
49 
50  :type: list[hal_py.GateTypeComponent]
51  )");
52 
53  py_gate_type_component.def("get_components", &GateTypeComponent::get_components, py::arg("filter") = nullptr, borrowed(), R"(
54  Get all components matching the filter condition (if provided) as a list.
55  Returns an empty list if (i) the gate type does not contain any components or (ii) no component matches the filter condition.
56 
57  :param lambda filter: The filter applied to all candidate components, disabled by default.
58  :returns: The components.
59  :rtype: list[hal_py.GateTypeComponent]
60  )");
61 
62  py_gate_type_component.def("get_component", &GateTypeComponent::get_component, py::arg("filter") = nullptr, borrowed(), R"(
63  Get a single component matching the filter condition (if provided).
64  Returns ``None`` if (i) the gate type does not contain any components, (ii) multiple components match the filter condition, or (iii) no component matches the filter condition.
65 
66  :param lambda filter: The filter applied to all candidate components.
67  :returns: The component or ``None``.
68  :rtype: hal_py.GateTypeComponent or None
69  )");
70 
71  py::class_<LUTComponent, GateTypeComponent, RawPtrWrapper<LUTComponent>> py_lut_component(m, "LUTComponent", R"(
72  A LUT component specifying the LUT gate type's functionality.
73  )");
74 
75  py_lut_component.def_static("is_class_of", &LUTComponent::is_class_of, py::arg("component"), R"(
76  Check whether a component is a LUTComponent.
77 
78  :param hal_py.GateTypeComponent component: The component to check.
79  :returns: ``True`` if component is a LUTComponent, ``False`` otherwise.
80  :rtype: bool
81  )");
82 
83  py::class_<LUTComponent::LUTOutputConfig>(py_lut_component, "LUTOutputConfig", R"(
84  Per-output-pin INIT configuration for a LUT component.
85  )")
86  .def(py::init<std::string, u32, u32, bool, std::vector<std::string>>(),
87  py::arg("init_identifier"),
88  py::arg("bit_offset"),
89  py::arg("bit_count"),
90  py::arg("is_ascending") = true,
91  py::arg("input_pins"))
92  .def_readonly("init_identifier", &LUTComponent::LUTOutputConfig::init_identifier, R"(
93  The data identifier within the INIT category for this output pin.
94 
95  :type: str
96  )")
97  .def_readonly("bit_offset", &LUTComponent::LUTOutputConfig::bit_offset, R"(
98  The first bit (LSB = 0) of the slice within the parsed INIT value.
99 
100  :type: int
101  )")
102  .def_readonly("bit_count", &LUTComponent::LUTOutputConfig::bit_count, R"(
103  The number of bits in the slice. Must be a non-zero power of two.
104 
105  :type: int
106  )")
107  .def_readonly("is_ascending", &LUTComponent::LUTOutputConfig::is_ascending, R"(
108  True if the INIT bits are stored in ascending order (LSB first), False for descending.
109 
110  :type: bool
111  )")
112  .def_readonly("input_pins", &LUTComponent::LUTOutputConfig::input_pins, R"(
113  Ordered list of input pin names used by this output. Must be non-empty; size must equal log2(bit_count).
114 
115  :type: list[str]
116  )");
117 
118  py_lut_component.def(
119  "get_output_pin_config",
120  [](const LUTComponent& self, const std::string& pin_name) -> const LUTComponent::LUTOutputConfig* { return self.get_output_pin_config(pin_name); },
121  py::arg("pin_name"),
122  py::return_value_policy::reference_internal,
123  R"(
124  Get the output configuration for a specific pin, or None if none is set.
125 
126  :param str pin_name: Name of the LUT output pin.
127  :returns: The output configuration or None.
128  :rtype: hal_py.LUTComponent.LUTOutputConfig or None
129  )");
130 
131  py_lut_component.def(
132  "get_output_pin_configs",
133  [](const LUTComponent& self) { return self.get_output_pin_configs(); },
134  R"(
135  Get all per-output-pin configurations.
136 
137  :returns: Dict mapping pin name to LUTOutputConfig.
138  :rtype: dict[str, hal_py.LUTComponent.LUTOutputConfig]
139  )");
140 
141  py_lut_component.def_static(
142  "extract_init_slice",
143  [](const std::string& full_hex, u32 bit_offset, u32 bit_count) -> std::optional<std::string> {
144  auto res = LUTComponent::extract_init_slice(full_hex, bit_offset, bit_count);
145  if (res.is_error())
146  {
147  log_error("python_context", "{}.", res.get_error().get());
148  return std::nullopt;
149  }
150  return res.get();
151  },
152  py::arg("full_hex"),
153  py::arg("bit_offset"),
154  py::arg("bit_count"),
155  R"(
156  Extract a bit slice from a full INIT hex string.
157  Returns the slice as an uppercase hex string padded to ``(bit_count+3)//4`` characters.
158 
159  :param str full_hex: Full INIT value as a hex string; must not be empty and must contain at least ``(bit_offset+bit_count+3)//4`` hex chars.
160  :param int bit_offset: First bit (LSB = 0) of the slice.
161  :param int bit_count: Number of bits in the slice; must be non-zero.
162  :returns: The extracted hex string, or ``None`` if ``full_hex`` is empty, too short, or invalid.
163  :rtype: str or None
164  )");
165 
166  py_lut_component.def_static(
167  "splice_init_slice",
168  [](const std::string& full_hex, const std::string& slice_hex, u32 bit_offset, u32 bit_count) -> std::optional<std::string> {
169  auto res = LUTComponent::splice_init_slice(full_hex, slice_hex, bit_offset, bit_count);
170  if (res.is_error())
171  {
172  log_error("python_context", "{}.", res.get_error().get());
173  return std::nullopt;
174  }
175  return res.get();
176  },
177  py::arg("full_hex"),
178  py::arg("slice_hex"),
179  py::arg("bit_offset"),
180  py::arg("bit_count"),
181  R"(
182  Splice a new slice value into a full INIT hex string at ``[bit_offset, bit_offset+bit_count)``.
183  The output preserves the digit width of ``full_hex``; if ``full_hex`` is empty the minimum width
184  needed to hold the splice is used.
185 
186  :param str full_hex: Current full INIT value as a hex string (may be empty).
187  :param str slice_hex: New value for the bit slice.
188  :param int bit_offset: First bit (LSB = 0) of the slice.
189  :param int bit_count: Number of bits in the slice; must be non-zero.
190  :returns: The updated full hex string, or ``None`` on parse failure.
191  :rtype: str or None
192  )");
193 
194  py_lut_component.def(
195  "get_init_string",
196  [](const LUTComponent& self, Gate* gate, const std::string& pin_name) -> std::optional<std::string> {
197  auto res = self.get_init_string(gate, pin_name);
198  if (res.is_ok())
199  {
200  return res.get();
201  }
202  log_error("python_context", "error getting INIT string: {}", res.get_error().get());
203  return std::nullopt;
204  },
205  py::arg("gate"),
206  py::arg("pin_name"),
207  R"(
208  Get the INIT hex string for a specific LUT output pin on a gate instance.
209 
210  :param hal_py.Gate gate: The gate instance.
211  :param str pin_name: The output pin name.
212  :returns: The hex INIT string (no prefix) on success, ``None`` otherwise.
213  :rtype: str or None
214  )");
215 
216  py_lut_component.def(
217  "get_init_string",
218  [](const LUTComponent& self, Gate* gate, GatePin* pin) -> std::optional<std::string> {
219  auto res = self.get_init_string(gate, pin);
220  if (res.is_ok())
221  {
222  return res.get();
223  }
224  log_error("python_context", "error getting INIT string: {}", res.get_error().get());
225  return std::nullopt;
226  },
227  py::arg("gate"),
228  py::arg("pin"),
229  R"(
230  Get the INIT hex string for a specific LUT output pin on a gate instance.
231 
232  :param hal_py.Gate gate: The gate instance.
233  :param hal_py.GatePin pin: The output pin.
234  :returns: The hex INIT string (no prefix) on success, ``None`` otherwise.
235  :rtype: str or None
236  )");
237 
238  py_lut_component.def(
239  "set_init_string",
240  [](const LUTComponent& self, Gate* gate, const std::string& pin_name, const std::string& hex) -> bool {
241  auto res = self.set_init_string(gate, pin_name, hex);
242  if (res.is_ok())
243  {
244  return true;
245  }
246  log_error("python_context", "error setting INIT string: {}", res.get_error().get());
247  return false;
248  },
249  py::arg("gate"),
250  py::arg("pin_name"),
251  py::arg("hex"),
252  R"(
253  Set the INIT hex string for a specific LUT output pin on a gate instance.
254 
255  :param hal_py.Gate gate: The gate instance.
256  :param str pin_name: The output pin name.
257  :param str hex: Hex string without prefix.
258  :returns: ``True`` on success, ``False`` otherwise.
259  :rtype: bool
260  )");
261 
262  py_lut_component.def(
263  "set_init_string",
264  [](const LUTComponent& self, Gate* gate, GatePin* pin, const std::string& hex) -> bool {
265  auto res = self.set_init_string(gate, pin, hex);
266  if (res.is_ok())
267  {
268  return true;
269  }
270  log_error("python_context", "error setting INIT string: {}", res.get_error().get());
271  return false;
272  },
273  py::arg("gate"),
274  py::arg("pin"),
275  py::arg("hex"),
276  R"(
277  Set the INIT hex string for a specific LUT output pin on a gate instance.
278 
279  :param hal_py.Gate gate: The gate instance.
280  :param hal_py.GatePin pin: The output pin.
281  :param str hex: Hex string without prefix.
282  :returns: ``True`` on success, ``False`` otherwise.
283  :rtype: bool
284  )");
285 
286  py::class_<FFComponent, GateTypeComponent, RawPtrWrapper<FFComponent>> py_ff_component(m, "FFComponent", R"(
287  A FF component specifying the FF gate type's functionality.
288  )");
289 
290  py_ff_component.def_static("is_class_of", &FFComponent::is_class_of, py::arg("component"), R"(
291  Check whether a component is a FFComponent.
292 
293  :param hal_py.GateTypeComponent component: The component to check.
294  :returns: ``True`` if component is a FFComponent, ``False`` otherwise.
295  :rtype: bool
296  )");
297 
298  py_ff_component.def_property("next_state_function", &FFComponent::get_next_state_function, &FFComponent::set_next_state_function, R"(
299  The Boolean function describing the next internal state of the flip-flop.
300  )");
301 
302  py_ff_component.def("get_next_state_function", &FFComponent::get_next_state_function, R"(
303  Get the Boolean function describing the next internal state of the flip-flop.
304 
305  :returns: The function describing the internal state.
306  :rtype: hal_py.BooleanFunction
307  )");
308 
309  py_ff_component.def("set_next_state_function", &FFComponent::set_next_state_function, py::arg("next_state_bf"), R"(
310  Set the Boolean function describing the next internal state of the flip-flop.
311 
312  :param hal_py.BooleanFunction next_state_bf: The function describing the internal state.
313  )");
314 
315  py_ff_component.def_property("clock_function", &FFComponent::get_clock_function, &FFComponent::set_clock_function, R"(
316  The Boolean function describing the clock input of the flip-flop.
317  )");
318 
319  py_ff_component.def("get_clock_function", &FFComponent::get_clock_function, R"(
320  Get the Boolean function describing the clock input of the flip-flop.
321 
322  :returns: The function describing the clock input.
323  :rtype: hal_py.BooleanFunction
324  )");
325 
326  py_ff_component.def("set_clock_function", &FFComponent::set_clock_function, py::arg("clock_bf"), R"(
327  Set the Boolean function describing the clock input of the flip-flop.
328 
329  :param hal_py.BooleanFunction clock_bf: The function describing the clock input.
330  )");
331 
332  py_ff_component.def_property("async_reset_function", &FFComponent::get_async_reset_function, &FFComponent::set_async_reset_function, R"(
333  The Boolean function describing the asynchronous reset behavior of the flip-flop.
334  Is an empty function if asynchronous reset is not supported by the flip-flop.
335  )");
336 
337  py_ff_component.def("get_async_reset_function", &FFComponent::get_async_reset_function, R"(
338  Get the Boolean function describing the asynchronous reset behavior of the flip-flop.
339  Returns an empty function if asynchronous reset is not supported by the flip-flop.
340 
341  :returns: The function describing the asynchronous reset behavior.
342  :rtype: hal_py.BooleanFunction
343  )");
344 
345  py_ff_component.def("set_async_reset_function", &FFComponent::set_async_reset_function, py::arg("async_reset_bf"), R"(
346  Set the Boolean function describing the asynchronous reset behavior of the flip-flop.
347 
348  :param hal_py.BooleanFunction async_reset_bf: The function describing the asynchronous reset behavior.
349  )");
350 
351  py_ff_component.def_property("async_set_function", &FFComponent::get_async_set_function, &FFComponent::set_async_set_function, R"(
352  The Boolean function describing the asynchronous set behavior of the flip-flop.
353  Is an empty function if asynchronous set is not supported by the flip-flop.
354  )");
355 
356  py_ff_component.def("get_async_set_function", &FFComponent::get_async_set_function, R"(
357  Get the Boolean function describing the asynchronous set behavior of the flip-flop.
358  Returns an empty function if asynchronous set is not supported by the flip-flop.
359 
360  :returns: The function describing the asynchronous set behavior.
361  :rtype: hal_py.BooleanFunction
362  )");
363 
364  py_ff_component.def("set_async_set_function", &FFComponent::set_async_set_function, py::arg("async_set_bf"), R"(
365  Set the Boolean function describing the asynchronous set behavior of the flip-flop.
366 
367  :param hal_py.BooleanFunction async_set_bf: The function describing the asynchronous set behavior.
368  )");
369 
370  py_ff_component.def("get_async_set_reset_behavior", &FFComponent::get_async_set_reset_behavior, R"(
371  Get the behavior of the internal state and the negated internal state when both asynchronous set and reset are active at the same time.
372 
373  :returns: The values specifying the behavior for the internal and negated internal state.
374  :rtype: tuple(hal_py.AsyncSetResetBehavior, hal_py.AsyncSetResetBehavior)
375  )");
376 
377  py_ff_component.def("set_async_set_reset_behavior", &FFComponent::set_async_set_reset_behavior, py::arg("behav_state"), py::arg("behav_neg_state"), R"(
378  Set the behavior of the internal state and the negated internal state when both asynchronous set and reset are active at the same time.
379 
380  :param hal_py.AsyncSetResetBehavior behav_state: The behavior of the internal state.
381  :param hal_py.AsyncSetResetBehavior behav_neg_state: The behavior of the negated internal state.
382  )");
383 
384  py::class_<LatchComponent, GateTypeComponent, RawPtrWrapper<LatchComponent>> py_latch_component(m, "LatchComponent", R"(
385  A latch component specifying the latch gate type's functionality.
386  )");
387 
388  py_latch_component.def_static("is_class_of", &LatchComponent::is_class_of, py::arg("component"), R"(
389  Check whether a component is a LatchComponent.
390 
391  :param hal_py.GateTypeComponent component: The component to check.
392  :returns: ``True`` if component is a LatchComponent, ``False`` otherwise.
393  :rtype: bool
394  )");
395 
396  py_latch_component.def_property("data_in_function", &LatchComponent::get_data_in_function, &LatchComponent::set_data_in_function, R"(
397  The Boolean function describing the data input of the latch.
398  )");
399 
400  py_latch_component.def("get_data_in_function", &LatchComponent::get_data_in_function, R"(
401  Get the Boolean function describing the data input of the latch.
402 
403  :returns: The function describing the data input.
404  :rtype: hal_py.BooleanFunction
405  )");
406 
407  py_latch_component.def("set_data_in_function", &LatchComponent::set_data_in_function, py::arg("data_in_bf"), R"(
408  Set the Boolean function describing the data input of the latch.
409 
410  :param hal_py.BooleanFunction data_in_bf: The function describing the data input.
411  )");
412 
413  py_latch_component.def_property("enable_function", &LatchComponent::get_enable_function, &LatchComponent::set_enable_function, R"(
414  The Boolean function describing the enable behavior of the latch.
415  )");
416 
417  py_latch_component.def("get_enable_function", &LatchComponent::get_enable_function, R"(
418  Get the Boolean function describing the enable behavior of the latch.
419 
420  :returns: The function describing the enable behavior.
421  :rtype: hal_py.BooleanFunction
422  )");
423 
424  py_latch_component.def("set_enable_function", &LatchComponent::set_enable_function, py::arg("enable_bf"), R"(
425  Set the Boolean function describing the enable behavior of the latch.
426 
427  :param hal_py.BooleanFunction enable_bf: The function describing the enable behavior.
428  )");
429 
430  py_latch_component.def_property("async_reset_function", &LatchComponent::get_async_reset_function, &LatchComponent::set_async_reset_function, R"(
431  The Boolean function describing the asynchronous reset behavior of the latch.
432  Is an empty function if asynchronous reset is not supported by the latch.
433  )");
434 
435  py_latch_component.def("get_async_reset_function", &LatchComponent::get_async_reset_function, R"(
436  Get the Boolean function describing the asynchronous reset behavior of the latch.
437  Returns an empty function if asynchronous reset is not supported by the latch.
438 
439  :returns: The function describing the asynchronous reset behavior.
440  :rtype: hal_py.BooleanFunction
441  )");
442 
443  py_latch_component.def("set_async_reset_function", &LatchComponent::set_async_reset_function, py::arg("async_reset_bf"), R"(
444  Set the Boolean function describing the asynchronous reset behavior of the latch.
445 
446  :param hal_py.BooleanFunction async_reset_bf: The function describing the asynchronous reset behavior.
447  )");
448 
449  py_latch_component.def_property("async_set_function", &LatchComponent::get_async_set_function, &LatchComponent::set_async_set_function, R"(
450  The Boolean function describing the asynchronous set behavior of the latch.
451  Is an empty function if asynchronous set is not supported by the latch.
452  )");
453 
454  py_latch_component.def("get_async_set_function", &LatchComponent::get_async_set_function, R"(
455  Get the Boolean function describing the asynchronous set behavior of the latch.
456  Returns an empty function if asynchronous set is not supported by the latch.
457 
458  :returns: The function describing the asynchronous set behavior.
459  :rtype: hal_py.BooleanFunction
460  )");
461 
462  py_latch_component.def("set_async_set_function", &LatchComponent::set_async_set_function, py::arg("async_set_bf"), R"(
463  Set the Boolean function describing the asynchronous set behavior of the latch.
464 
465  :param hal_py.BooleanFunction async_set_bf: The function describing the asynchronous set behavior.
466  )");
467 
468  py_latch_component.def("get_async_set_reset_behavior", &LatchComponent::get_async_set_reset_behavior, R"(
469  Get the behavior of the internal state and the negated internal state when both asynchronous set and reset are active at the same time.
470 
471  :returns: The values specifying the behavior for the internal and negated internal state.
472  :rtype: tuple(hal_py.AsyncSetResetBehavior, hal_py.AsyncSetResetBehavior)
473  )");
474 
475  py_latch_component.def("set_async_set_reset_behavior", &LatchComponent::set_async_set_reset_behavior, py::arg("behav_state"), py::arg("behav_neg_state"), R"(
476  Set the behavior of the internal state and the negated internal state when both asynchronous set and reset are active at the same time.
477 
478  :param hal_py.AsyncSetResetBehavior behav_state: The behavior of the internal state.
479  :param hal_py.AsyncSetResetBehavior behav_neg_state: The behavior of the negated internal state.
480  )");
481 
482  py::class_<RAMComponent, GateTypeComponent, RawPtrWrapper<RAMComponent>> py_ram_component(m, "RAMComponent", R"(
483  A RAM component specifying the RAM gate type's functionality.
484  )");
485 
486  py_ram_component.def_static("is_class_of", &RAMComponent::is_class_of, py::arg("component"), R"(
487  Check whether a component is a RAMComponent.
488 
489  :param hal_py.GateTypeComponent component: The component to check.
490  :returns: ``True`` if component is a RAMComponent, ``False`` otherwise.
491  :rtype: bool
492  )");
493 
494  py_ram_component.def_property("bit_size", &RAMComponent::get_bit_size, &RAMComponent::set_bit_size, R"(
495  The size of the RAM in bits.
496 
497  :type: int
498  )");
499 
500  py_ram_component.def("get_bit_size", &RAMComponent::get_bit_size, R"(
501  Get the size of the RAM in bits.
502 
503  :returns: The size of the RAM in bits.
504  :rtype: int
505  )");
506 
507  py_ram_component.def("set_bit_size", &RAMComponent::set_bit_size, py::arg("bit_size"), R"(
508  Set the size of the RAM in bits.
509 
510  :param int bit_size: The size of the RAM in bits.
511  )");
512 
513  py_ram_component.def_property("init_identifiers", &RAMComponent::get_init_identifiers, &RAMComponent::set_init_identifiers, R"(
514  The parameter names used to find initialization data for this RAM.
515 
516  :type: list[str]
517  )");
518 
519  py_ram_component.def("get_init_identifiers", &RAMComponent::get_init_identifiers, R"(
520  Get the parameter names used to find initialization data for this RAM.
521 
522  :returns: The list of init identifier strings.
523  :rtype: list[str]
524  )");
525 
526  py_ram_component.def("set_init_identifiers", &RAMComponent::set_init_identifiers, py::arg("init_identifiers"), R"(
527  Set the parameter names used to find initialization data for this RAM.
528 
529  :param list[str] init_identifiers: The list of init identifier strings.
530  )");
531 
532  py::class_<MACComponent, GateTypeComponent, RawPtrWrapper<MACComponent>> py_mac_component(m, "MACComponent", R"(
533  A MAC component specifying the MAC gate type's functionality.
534  )");
535 
536  py_mac_component.def_static("is_class_of", &MACComponent::is_class_of, py::arg("component"), R"(
537  Check whether a component is a MACComponent.
538 
539  :param hal_py.GateTypeComponent component: The component to check.
540  :returns: ``True`` if component is a MACComponent, ``False`` otherwise.
541  :rtype: bool
542  )");
543 
544  py::class_<InitComponent, GateTypeComponent, RawPtrWrapper<InitComponent>> py_init_component(m, "InitComponent", R"(
545  An initialization component specifying the initialization behavior of a gate type.
546  )");
547 
548  py_init_component.def_static("is_class_of", &InitComponent::is_class_of, py::arg("component"), R"(
549  Check whether a component is an InitComponent.
550 
551  :param hal_py.GateTypeComponent component: The component to check.
552  :returns: ``True`` if component is an InitComponent, ``False`` otherwise.
553  :rtype: bool
554  )");
555 
556  py_init_component.def_property("init_category", &InitComponent::get_init_category, &InitComponent::set_init_category, R"(
557  The category in which to find the initialization data.
558 
559  :type: str
560  )");
561 
562  py_init_component.def("get_init_category", &InitComponent::get_init_category, R"(
563  Get the category in which to find the initialization data.
564 
565  :returns: The data category.
566  :rtype: str
567  )");
568 
569  py_init_component.def("set_init_category", &InitComponent::set_init_category, py::arg("init_category"), R"(
570  Set the category in which to find the initialization data.
571 
572  :param str init_category: The data category.
573  )");
574 
575  py_init_component.def_property("init_identifiers", &InitComponent::get_init_identifiers, &InitComponent::set_init_identifiers, R"(
576  The list of identifiers at which to find initialization data.
577 
578  :type: str
579  )");
580 
581  py_init_component.def("get_init_identifier", &InitComponent::get_init_identifiers, R"(
582  Get the list of identifiers at which to find the initialization data.
583 
584  :returns: The data identifiers.
585  :rtype: list[str]
586  )");
587 
588  py_init_component.def("set_init_identifier", &InitComponent::set_init_identifiers, py::arg("init_identifiers"), R"(
589  Set the list of identifiers at which to find the initialization data.
590 
591  :param list[str] init_identifiers: The data identifiers.
592  )");
593 
594  py::class_<StateComponent, GateTypeComponent, RawPtrWrapper<StateComponent>> py_state_component(m, "StateComponent", R"(
595  A StateComponent with given child component and the internal state identifiers.
596  )");
597 
598  py_state_component.def_static("is_class_of", &StateComponent::is_class_of, py::arg("component"), R"(
599  Check whether a component is a StateComponent.
600 
601  :param hal_py.GateTypeComponent component: The component to check.
602  :returns: ``True`` if component is a StateComponent, ``False`` otherwise.
603  :rtype: bool
604  )");
605 
606  py_state_component.def_property("state_identifier", &StateComponent::get_state_identifier, &StateComponent::set_state_identifier, R"(
607  The identifier of the internal state.
608 
609  :type: str
610  )");
611 
612  py_state_component.def("get_state_identifier", &StateComponent::get_state_identifier, R"(
613  Get the identifier of the internal state.
614 
615  :returns: The identifier of the internal state.
616  :rtype: str
617  )");
618 
619  py_state_component.def("set_state_identifier", &StateComponent::set_state_identifier, py::arg("state_identifier"), R"(
620  Set the identifier of the internal state.
621 
622  :param str state_identifier: The identifier of the internal state.
623  )");
624 
625  py_state_component.def_property("neg_state_identifier", &StateComponent::get_neg_state_identifier, &StateComponent::set_neg_state_identifier, R"(
626  The identifier of the negated internal state.
627 
628  :type: str
629  )");
630 
631  py_state_component.def("get_neg_state_identifier", &StateComponent::get_neg_state_identifier, R"(
632  Get the identifier of the negated internal state.
633 
634  :returns: The identifier of the negated internal state.
635  :rtype: str
636  )");
637 
638  py_state_component.def("set_neg_state_identifier", &StateComponent::set_neg_state_identifier, py::arg("neg_state_identifier"), R"(
639  Set the identifier of the negated internal state.
640 
641  :param str neg_state_identifier: The identifier of the negated internal state.
642  )");
643 
644  py::class_<RAMPortComponent, GateTypeComponent, RawPtrWrapper<RAMPortComponent>> py_ram_port_component(m, "RAMPortComponent", R"(
645  A RAM port component specifying the behavior of a port belonging to a RAM gate type.
646  )");
647 
648  py_ram_port_component.def_static("is_class_of", &RAMPortComponent::is_class_of, py::arg("component"), R"(
649  Check whether a component is a RAMPortComponent.
650 
651  :param hal_py.GateTypeComponent component: The component to check.
652  :returns: ``True`` if component is a RAMPortComponent, ``False`` otherwise.
653  :rtype: bool
654  )");
655 
656  py_ram_port_component.def_property("data_group", &RAMPortComponent::get_data_group, &RAMPortComponent::set_data_group, R"(
657  The name of the read or write data pin group.
658 
659  :type: str
660  )");
661 
662  py_ram_port_component.def("get_data_group", &RAMPortComponent::get_data_group, R"(
663  Get the name of the read or write data pin group.
664 
665  :returns: The name of the pin group.
666  :rtype: str
667  )");
668 
669  py_ram_port_component.def("set_data_group", &RAMPortComponent::set_data_group, py::arg("data_group"), R"(
670  Set the name of the read or write data pin group.
671 
672  :param str data_group: The name of the pin group.
673  )");
674 
675  py_ram_port_component.def_property("address_group", &RAMPortComponent::get_address_group, &RAMPortComponent::set_address_group, R"(
676  The name of the read or write address pin group.
677 
678  :type: str
679  )");
680 
681  py_ram_port_component.def("get_address_group", &RAMPortComponent::get_address_group, R"(
682  Get the name of the read or write address pin group.
683 
684  :returns: The name of the pin group.
685  :rtype: str
686  )");
687 
688  py_ram_port_component.def("set_address_group", &RAMPortComponent::set_address_group, py::arg("addr_group"), R"(
689  Set the name of the read or write address pin group.
690 
691  :param str addr_group: The name of the pin group.
692  )");
693 
694  py_ram_port_component.def_property("clock_function", &RAMPortComponent::get_clock_function, &RAMPortComponent::set_clock_function, R"(
695  The Boolean function determining the read or write clock.
696 
697  :type: hal_py.BooleanFunction
698  )");
699 
700  py_ram_port_component.def("get_clock_function", &RAMPortComponent::get_clock_function, R"(
701  Get the Boolean function determining the read or write clock.
702 
703  :returns: The Boolean function.
704  :rtype: hal_py.BooleanFunction
705  )");
706 
707  py_ram_port_component.def("set_clock_function", &RAMPortComponent::set_clock_function, py::arg("clock_bf"), R"(
708  Set the Boolean function determining the read or write clock.
709 
710  :param hal_py.BooleanFunction clock_bf: The Boolean function.
711  )");
712 
713  py_ram_port_component.def_property("enable_function", &RAMPortComponent::get_enable_function, &RAMPortComponent::set_enable_function, R"(
714  The Boolean function determining the read or write enable.
715 
716  :type: hal_py.BooleanFunction
717  )");
718 
719  py_ram_port_component.def("get_enable_function", &RAMPortComponent::get_enable_function, R"(
720  Get the Boolean function determining the read or write enable.
721 
722  :returns: The Boolean function.
723  :rtype: hal_py.BooleanFunction
724  )");
725 
726  py_ram_port_component.def("set_enable_function", &RAMPortComponent::set_enable_function, py::arg("enable_bf"), R"(
727  Set the Boolean function determining the read or write enable.
728 
729  :param hal_py.BooleanFunction enable_bf: The Boolean function.
730  )");
731 
732  py_ram_port_component.def_property("write_port", &RAMPortComponent::is_write_port, &RAMPortComponent::set_write_port, R"(
733  ``True`` if the port is a write port, ``False`` if it is a read port.
734 
735  :type: bool
736  )");
737 
738  py_ram_port_component.def("is_write_port", &RAMPortComponent::is_write_port, R"(
739  Check whether the port is a write or a read port.
740 
741  :returns: ``True`` if the port is a write port, ``False`` otherwise.
742  :rtype: bool
743  )");
744 
745  py_ram_port_component.def("set_write_port", &RAMPortComponent::set_write_port, py::arg("is_write"), R"(
746  Set the port to be a write or a read port.
747 
748  :param bool is_write: ``True`` to set the port to be a write port, ``False`` to set it to be a read port.
749  )");
750  }
751 } // namespace hal
void set_clock_function(const BooleanFunction &clock_bf)
void set_async_set_reset_behavior(const AsyncSetResetBehavior behav_state, const AsyncSetResetBehavior behav_neg_state)
void set_async_set_function(const BooleanFunction &async_set_bf)
BooleanFunction get_clock_function() const
const std::pair< AsyncSetResetBehavior, AsyncSetResetBehavior > & get_async_set_reset_behavior() const
BooleanFunction get_async_set_function() const
static bool is_class_of(const GateTypeComponent *component)
BooleanFunction get_async_reset_function() const
BooleanFunction get_next_state_function() const
void set_next_state_function(const BooleanFunction &next_state_bf)
void set_async_reset_function(const BooleanFunction &async_reset_bf)
Definition: gate.h:59
virtual std::vector< GateTypeComponent * > get_components(const std::function< bool(const GateTypeComponent *)> &filter=nullptr) const =0
virtual ComponentType get_type() const =0
GateTypeComponent * get_component(const std::function< bool(const GateTypeComponent *)> &filter=nullptr) const
const std::string & get_init_category() const
static bool is_class_of(const GateTypeComponent *component)
void set_init_category(const std::string &init_category)
void set_init_identifiers(const std::vector< std::string > &init_identifiers)
const std::vector< std::string > & get_init_identifiers() const
static Result< std::string > extract_init_slice(const std::string &full_hex, u32 bit_offset, u32 bit_count)
static Result< std::string > splice_init_slice(const std::string &full_hex, const std::string &slice_hex, u32 bit_offset, u32 bit_count)
static bool is_class_of(const GateTypeComponent *component)
BooleanFunction get_async_reset_function() const
void set_async_reset_function(const BooleanFunction &async_reset_bf)
void set_async_set_reset_behavior(AsyncSetResetBehavior behav_state, AsyncSetResetBehavior behav_neg_state)
static bool is_class_of(const GateTypeComponent *component)
const std::pair< AsyncSetResetBehavior, AsyncSetResetBehavior > & get_async_set_reset_behavior() const
void set_enable_function(const BooleanFunction &enable_bf)
void set_async_set_function(const BooleanFunction &async_set_bf)
BooleanFunction get_async_set_function() const
BooleanFunction get_enable_function() const
BooleanFunction get_data_in_function() const
void set_data_in_function(const BooleanFunction &data_in_bf)
static bool is_class_of(const GateTypeComponent *component)
const std::vector< std::string > & get_init_identifiers() const
static bool is_class_of(const GateTypeComponent *component)
u32 get_bit_size() const
void set_init_identifiers(const std::vector< std::string > &init_identifiers)
void set_bit_size(const u32 bit_size)
void set_enable_function(const BooleanFunction &enable_bf)
void set_address_group(const std::string &addr_group)
void set_write_port(bool is_write)
const std::string & get_data_group() const
const BooleanFunction & get_enable_function() const
static bool is_class_of(const GateTypeComponent *component)
const BooleanFunction & get_clock_function() const
const std::string & get_address_group() const
void set_clock_function(const BooleanFunction &clock_bf)
void set_data_group(const std::string &data_group)
const std::string & get_state_identifier() const
void set_state_identifier(const std::string &state_identifier)
static bool is_class_of(const GateTypeComponent *component)
const std::string & get_neg_state_identifier() const
void set_neg_state_identifier(const std::string &neg_state_identifier)
uint32_t u32
Definition: defines.h:41
void gate_type_components_init(py::module &m)
#define log_error(channel,...)
Definition: log.h:78
const Module * module(const Gate *g, const NodeBoxes &boxes)
Definition: defines.h:45
std::vector< std::string > input_pins
Definition: lut_component.h:76