2626#pragma once
2727
2828#include " hal_core/netlist/gate_library/gate_type_component/gate_type_component.h"
29+ #include " hal_core/netlist/pins/gate_pin.h"
2930
3031#include < unordered_map>
3132
@@ -36,22 +37,20 @@ namespace hal
3637 public:
3738 /* *
3839 * Maps an output pin to a specific slice of an INIT string.
39- * When bit_count is 0 the full INIT string is used (legacy behaviour).
4040 */
4141 struct LUTOutputConfig
4242 {
4343 std::string init_identifier;
44- u32 bit_offset = 0 ;
45- u32 bit_count = 0 ;
44+ u32 bit_offset;
45+ u32 bit_count;
4646 };
4747
4848 /* *
49- * Construct a new LUTComponent with given child component and bit-order .
49+ * Construct a new LUTComponent.
5050 *
51- * @param[in] component - Another component to be added as a child component.
5251 * @param[in] init_ascending - True if ascending bit-order, false otherwise.
5352 */
54- LUTComponent (std::unique_ptr<GateTypeComponent> component, bool init_ascending);
53+ explicit LUTComponent (bool init_ascending);
5554
5655 /* *
5756 * Get the type of the gate type component.
@@ -92,15 +91,42 @@ namespace hal
9291 void set_init_ascending (bool init_ascending = true );
9392
9493 /* *
95- * Associate an output pin with a specific INIT identifier and an optional bit range.
96- * When bit_count is 0 the full INIT string starting at bit_offset is used .
94+ * Associate an output pin with a specific INIT identifier and a bit range.
95+ * Overwrites any existing configuration for the same pin name .
9796 *
9897 * @param[in] pin_name - Name of the LUT output pin.
9998 * @param[in] init_identifier - The data identifier within the INIT category.
10099 * @param[in] bit_offset - First bit (LSB = 0) of the slice within the parsed INIT value.
101- * @param[in] bit_count - Number of bits in the slice; must be a power of two, or 0 for full string .
100+ * @param[in] bit_count - Number of bits in the slice; must be a non-zero power of two.
102101 */
103- void set_output_pin_config (const std::string& pin_name, const std::string& init_identifier, u32 bit_offset = 0 , u32 bit_count = 0 );
102+ void add_output_pin_config (const std::string& pin_name, const std::string& init_identifier, u32 bit_offset, u32 bit_count);
103+
104+ /* *
105+ * Associate an output pin with a specific INIT identifier and a bit range.
106+ * Overwrites any existing configuration for the same pin.
107+ *
108+ * @param[in] pin - The LUT output pin.
109+ * @param[in] init_identifier - The data identifier within the INIT category.
110+ * @param[in] bit_offset - First bit (LSB = 0) of the slice within the parsed INIT value.
111+ * @param[in] bit_count - Number of bits in the slice; must be a non-zero power of two.
112+ */
113+ void add_output_pin_config (const GatePin* pin, const std::string& init_identifier, u32 bit_offset, u32 bit_count);
114+
115+ /* *
116+ * Remove the output configuration for a specific pin.
117+ *
118+ * @param[in] pin_name - Name of the LUT output pin.
119+ * @returns True if an entry was removed, false if no entry existed for that pin.
120+ */
121+ bool remove_output_pin_config (const std::string& pin_name);
122+
123+ /* *
124+ * Remove the output configuration for a specific pin.
125+ *
126+ * @param[in] pin - The LUT output pin.
127+ * @returns True if an entry was removed, false if no entry existed for that pin.
128+ */
129+ bool remove_output_pin_config (const GatePin* pin);
104130
105131 /* *
106132 * Get the output configuration for a specific pin, or nullptr if none is set.
@@ -119,35 +145,32 @@ namespace hal
119145
120146 /* *
121147 * Extract a bit slice from a full INIT hex string.
122- * Returns the slice as an uppercase hex string padded to (bit_count+3)/4 characters.
123- * If bit_count is 0 or full_hex is empty the string is returned unchanged.
148+ * Returns the slice as an uppercase hex string padded to `(bit_count+3)/4` characters.
124149 *
125- * @param[in] full_hex - Full INIT value as a hex string.
150+ * @param[in] full_hex - Full INIT value as a hex string; must not be empty and must
151+ * contain at least `(bit_offset+bit_count+3)/4` hex chars.
126152 * @param[in] bit_offset - First bit (LSB = 0) of the slice.
127- * @param[in] bit_count - Number of bits in the slice; 0 means full string .
128- * @returns OK with the extracted hex string, or ERR on parse failure .
153+ * @param[in] bit_count - Number of bits in the slice; must be non-zero .
154+ * @returns OK with the extracted hex string on success, an error if `full_hex` is empty, too short, or invalid .
129155 */
130156 static Result<std::string> extract_init_slice (const std::string& full_hex, u32 bit_offset, u32 bit_count);
131157
132158 /* *
133- * Splice a new slice value into a full INIT hex string at [bit_offset, bit_offset+bit_count).
134- * When bit_count is 0 the slice_hex is treated as the full replacement value (uppercased).
135- * The output preserves the digit width of full_hex; if full_hex is empty the minimum width
159+ * Splice a new slice value into a full INIT hex string at `[bit_offset, bit_offset+bit_count)`.
160+ * The output preserves the digit width of `full_hex`; if `full_hex` is empty the minimum width
136161 * needed to hold the splice is used.
137162 *
138163 * @param[in] full_hex - Current full INIT value as a hex string (may be empty).
139- * @param[in] slice_hex - New value for the bit slice (or full replacement when bit_count==0) .
164+ * @param[in] slice_hex - New value for the bit slice.
140165 * @param[in] bit_offset - First bit (LSB = 0) of the slice.
141- * @param[in] bit_count - Number of bits in the slice; 0 means full replacement .
142- * @returns OK with the updated full hex string, or ERR on parse failure.
166+ * @param[in] bit_count - Number of bits in the slice; must be non-zero .
167+ * @returns OK with the updated full hex string on success, an error on parse failure.
143168 */
144169 static Result<std::string> splice_init_slice (const std::string& full_hex, const std::string& slice_hex, u32 bit_offset, u32 bit_count);
145170
146171 private:
147- static constexpr ComponentType m_type = ComponentType::lut;
148- std::unique_ptr<GateTypeComponent> m_component = nullptr ;
149-
150- bool m_init_ascending = true ;
172+ static constexpr ComponentType m_type = ComponentType::lut;
173+ bool m_init_ascending = true ;
151174 std::unordered_map<std::string, LUTOutputConfig> m_output_pin_configs;
152175 };
153176} // namespace hal
0 commit comments