17 py::class_<GateTypeComponent, RawPtrWrapper<GateTypeComponent>> py_gate_type_component(m,
"GateTypeComponent", R
"(
18 A component defining additional functionality of a gate type.
21 py::enum_<GateTypeComponent::ComponentType>(py_gate_type_component, "ComponentType", R
"(
22 The type of a gate type component.
35 The type of the gate type component.
37 :type: hal_py.GateTypeComponent.ComponentType
41 Get the type of the gate type component.
43 :returns: The type of the gate type component.
44 :rtype: hal_py.GateTypeComponent.ComponentType
48 All components of the gate type component as a list.
50 :type: list[hal_py.GateTypeComponent]
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.
57 :param lambda filter: The filter applied to all candidate components, disabled by default.
58 :returns: The components.
59 :rtype: list[hal_py.GateTypeComponent]
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.
66 :param lambda filter: The filter applied to all candidate components.
67 :returns: The component or ``None``.
68 :rtype: hal_py.GateTypeComponent or None
71 py::class_<LUTComponent, GateTypeComponent, RawPtrWrapper<LUTComponent>> py_lut_component(m, "LUTComponent", R
"(
72 A LUT component specifying the LUT gate type's functionality.
76 Check whether a component is a LUTComponent.
78 :param hal_py.GateTypeComponent component: The component to check.
79 :returns: ``True`` if component is a LUTComponent, ``False`` otherwise.
83 py::class_<LUTComponent::LUTOutputConfig>(py_lut_component, "LUTOutputConfig", R
"(
84 Per-output-pin INIT configuration for a LUT component.
86 .def(py::init<std::string, u32, u32, bool, std::vector<std::string>>(),
87 py::arg(
"init_identifier"),
88 py::arg(
"bit_offset"),
90 py::arg(
"is_ascending") =
true,
91 py::arg(
"input_pins"))
93 The data identifier within the INIT category for this output pin.
98 The first bit (LSB = 0) of the slice within the parsed INIT value.
103 The number of bits in the slice. Must be a non-zero power of two.
108 True if the INIT bits are stored in ascending order (LSB first), False for descending.
113 Ordered list of input pin names used by this output. Must be non-empty; size must equal log2(bit_count).
118 py_lut_component.def(
119 "get_output_pin_config",
122 py::return_value_policy::reference_internal,
124 Get the output configuration for a specific pin, or None if none is set.
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
131 py_lut_component.def(
132 "get_output_pin_configs",
133 [](
const LUTComponent&
self) {
return self.get_output_pin_configs(); },
135 Get all per-output-pin configurations.
137 :returns: Dict mapping pin name to LUTOutputConfig.
138 :rtype: dict[str, hal_py.LUTComponent.LUTOutputConfig]
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> {
147 log_error(
"python_context",
"{}.", res.get_error().get());
153 py::arg(
"bit_offset"),
154 py::arg(
"bit_count"),
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.
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.
166 py_lut_component.def_static(
168 [](
const std::string& full_hex,
const std::string& slice_hex,
u32 bit_offset,
u32 bit_count) -> std::optional<std::string> {
172 log_error(
"python_context",
"{}.", res.get_error().get());
178 py::arg(
"slice_hex"),
179 py::arg(
"bit_offset"),
180 py::arg(
"bit_count"),
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.
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.
194 py_lut_component.def(
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);
202 log_error(
"python_context",
"error getting INIT string: {}", res.get_error().get());
208 Get the INIT hex string for a specific LUT output pin on a gate instance.
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.
216 py_lut_component.def(
219 auto res =
self.get_init_string(gate, pin);
224 log_error(
"python_context",
"error getting INIT string: {}", res.get_error().get());
230 Get the INIT hex string for a specific LUT output pin on a gate instance.
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.
238 py_lut_component.def(
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);
246 log_error(
"python_context",
"error setting INIT string: {}", res.get_error().get());
253 Set the INIT hex string for a specific LUT output pin on a gate instance.
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.
262 py_lut_component.def(
265 auto res =
self.set_init_string(gate, pin, hex);
270 log_error(
"python_context",
"error setting INIT string: {}", res.get_error().get());
277 Set the INIT hex string for a specific LUT output pin on a gate instance.
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.
286 py::class_<FFComponent, GateTypeComponent, RawPtrWrapper<FFComponent>> py_ff_component(m, "FFComponent", R
"(
287 A FF component specifying the FF gate type's functionality.
291 Check whether a component is a FFComponent.
293 :param hal_py.GateTypeComponent component: The component to check.
294 :returns: ``True`` if component is a FFComponent, ``False`` otherwise.
299 The Boolean function describing the next internal state of the flip-flop.
303 Get the Boolean function describing the next internal state of the flip-flop.
305 :returns: The function describing the internal state.
306 :rtype: hal_py.BooleanFunction
310 Set the Boolean function describing the next internal state of the flip-flop.
312 :param hal_py.BooleanFunction next_state_bf: The function describing the internal state.
316 The Boolean function describing the clock input of the flip-flop.
320 Get the Boolean function describing the clock input of the flip-flop.
322 :returns: The function describing the clock input.
323 :rtype: hal_py.BooleanFunction
327 Set the Boolean function describing the clock input of the flip-flop.
329 :param hal_py.BooleanFunction clock_bf: The function describing the clock input.
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.
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.
341 :returns: The function describing the asynchronous reset behavior.
342 :rtype: hal_py.BooleanFunction
346 Set the Boolean function describing the asynchronous reset behavior of the flip-flop.
348 :param hal_py.BooleanFunction async_reset_bf: The function describing the asynchronous reset behavior.
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.
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.
360 :returns: The function describing the asynchronous set behavior.
361 :rtype: hal_py.BooleanFunction
365 Set the Boolean function describing the asynchronous set behavior of the flip-flop.
367 :param hal_py.BooleanFunction async_set_bf: The function describing the asynchronous set behavior.
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.
373 :returns: The values specifying the behavior for the internal and negated internal state.
374 :rtype: tuple(hal_py.AsyncSetResetBehavior, hal_py.AsyncSetResetBehavior)
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.
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.
384 py::class_<LatchComponent, GateTypeComponent, RawPtrWrapper<LatchComponent>> py_latch_component(m, "LatchComponent", R
"(
385 A latch component specifying the latch gate type's functionality.
389 Check whether a component is a LatchComponent.
391 :param hal_py.GateTypeComponent component: The component to check.
392 :returns: ``True`` if component is a LatchComponent, ``False`` otherwise.
397 The Boolean function describing the data input of the latch.
401 Get the Boolean function describing the data input of the latch.
403 :returns: The function describing the data input.
404 :rtype: hal_py.BooleanFunction
408 Set the Boolean function describing the data input of the latch.
410 :param hal_py.BooleanFunction data_in_bf: The function describing the data input.
414 The Boolean function describing the enable behavior of the latch.
418 Get the Boolean function describing the enable behavior of the latch.
420 :returns: The function describing the enable behavior.
421 :rtype: hal_py.BooleanFunction
425 Set the Boolean function describing the enable behavior of the latch.
427 :param hal_py.BooleanFunction enable_bf: The function describing the enable behavior.
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.
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.
439 :returns: The function describing the asynchronous reset behavior.
440 :rtype: hal_py.BooleanFunction
444 Set the Boolean function describing the asynchronous reset behavior of the latch.
446 :param hal_py.BooleanFunction async_reset_bf: The function describing the asynchronous reset behavior.
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.
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.
458 :returns: The function describing the asynchronous set behavior.
459 :rtype: hal_py.BooleanFunction
463 Set the Boolean function describing the asynchronous set behavior of the latch.
465 :param hal_py.BooleanFunction async_set_bf: The function describing the asynchronous set behavior.
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.
471 :returns: The values specifying the behavior for the internal and negated internal state.
472 :rtype: tuple(hal_py.AsyncSetResetBehavior, hal_py.AsyncSetResetBehavior)
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.
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.
482 py::class_<RAMComponent, GateTypeComponent, RawPtrWrapper<RAMComponent>> py_ram_component(m, "RAMComponent", R
"(
483 A RAM component specifying the RAM gate type's functionality.
487 Check whether a component is a RAMComponent.
489 :param hal_py.GateTypeComponent component: The component to check.
490 :returns: ``True`` if component is a RAMComponent, ``False`` otherwise.
495 The size of the RAM in bits.
501 Get the size of the RAM in bits.
503 :returns: The size of the RAM in bits.
508 Set the size of the RAM in bits.
510 :param int bit_size: The size of the RAM in bits.
514 The parameter names used to find initialization data for this RAM.
520 Get the parameter names used to find initialization data for this RAM.
522 :returns: The list of init identifier strings.
527 Set the parameter names used to find initialization data for this RAM.
529 :param list[str] init_identifiers: The list of init identifier strings.
532 py::class_<MACComponent, GateTypeComponent, RawPtrWrapper<MACComponent>> py_mac_component(m, "MACComponent", R
"(
533 A MAC component specifying the MAC gate type's functionality.
537 Check whether a component is a MACComponent.
539 :param hal_py.GateTypeComponent component: The component to check.
540 :returns: ``True`` if component is a MACComponent, ``False`` otherwise.
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.
549 Check whether a component is an InitComponent.
551 :param hal_py.GateTypeComponent component: The component to check.
552 :returns: ``True`` if component is an InitComponent, ``False`` otherwise.
557 The category in which to find the initialization data.
563 Get the category in which to find the initialization data.
565 :returns: The data category.
570 Set the category in which to find the initialization data.
572 :param str init_category: The data category.
576 The list of identifiers at which to find initialization data.
582 Get the list of identifiers at which to find the initialization data.
584 :returns: The data identifiers.
589 Set the list of identifiers at which to find the initialization data.
591 :param list[str] init_identifiers: The data identifiers.
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.
599 Check whether a component is a StateComponent.
601 :param hal_py.GateTypeComponent component: The component to check.
602 :returns: ``True`` if component is a StateComponent, ``False`` otherwise.
607 The identifier of the internal state.
613 Get the identifier of the internal state.
615 :returns: The identifier of the internal state.
620 Set the identifier of the internal state.
622 :param str state_identifier: The identifier of the internal state.
626 The identifier of the negated internal state.
632 Get the identifier of the negated internal state.
634 :returns: The identifier of the negated internal state.
639 Set the identifier of the negated internal state.
641 :param str neg_state_identifier: The identifier of the negated internal state.
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.
649 Check whether a component is a RAMPortComponent.
651 :param hal_py.GateTypeComponent component: The component to check.
652 :returns: ``True`` if component is a RAMPortComponent, ``False`` otherwise.
657 The name of the read or write data pin group.
663 Get the name of the read or write data pin group.
665 :returns: The name of the pin group.
670 Set the name of the read or write data pin group.
672 :param str data_group: The name of the pin group.
676 The name of the read or write address pin group.
682 Get the name of the read or write address pin group.
684 :returns: The name of the pin group.
689 Set the name of the read or write address pin group.
691 :param str addr_group: The name of the pin group.
695 The Boolean function determining the read or write clock.
697 :type: hal_py.BooleanFunction
701 Get the Boolean function determining the read or write clock.
703 :returns: The Boolean function.
704 :rtype: hal_py.BooleanFunction
708 Set the Boolean function determining the read or write clock.
710 :param hal_py.BooleanFunction clock_bf: The Boolean function.
714 The Boolean function determining the read or write enable.
716 :type: hal_py.BooleanFunction
720 Get the Boolean function determining the read or write enable.
722 :returns: The Boolean function.
723 :rtype: hal_py.BooleanFunction
727 Set the Boolean function determining the read or write enable.
729 :param hal_py.BooleanFunction enable_bf: The Boolean function.
733 ``True`` if the port is a write port, ``False`` if it is a read port.
739 Check whether the port is a write or a read port.
741 :returns: ``True`` if the port is a write port, ``False`` otherwise.
746 Set the port to be a write or a read port.
748 :param bool is_write: ``True`` to set the port to be a write port, ``False`` to set it to be a read port.
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)
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)
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
bool is_write_port() 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)
void gate_type_components_init(py::module &m)
#define log_error(channel,...)
const Module * module(const Gate *g, const NodeBoxes &boxes)
std::vector< std::string > input_pins
std::string init_identifier