Skip to content

Commit a928235

Browse files
committed
removed INIT component from LUTs, fixed INIT handling in gates; some plugins missing
1 parent 69e5193 commit a928235

17 files changed

Lines changed: 1011 additions & 535 deletions

File tree

include/hal_core/netlist/gate.h

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -522,21 +522,54 @@ namespace hal
522522
Endpoint* get_successor(const GatePin* pin) const;
523523

524524
/**
525-
* Get the INIT data of the gate, if available.
526-
* An error is returned in case the gate does not hold any INIT data.
527-
*
528-
* @return The INIT data as a vector on success, an error message otherwise.
525+
* Get the INIT string owned by the given LUT output or internal pin.
526+
* Returns the pin's hex slice, or the full INIT string when no bit range is configured.
527+
* An error is returned when the gate has no LUT component, the pin does not exist,
528+
* its type is not `PinType::lut`, or its direction is neither `output` nor `internal`.
529+
*
530+
* @param[in] pin_name - Name of the LUT pin.
531+
* @returns The INIT string as an uppercase hex string on success, an error otherwise.
529532
*/
530-
Result<std::vector<std::string>> get_init_data() const;
533+
Result<std::string> get_init_string(const std::string& pin_name) const;
531534

532535
/**
533-
* Set the INIT data of the gate, if available.
534-
* An error is returned in case the gate does not hold any INIT data.
535-
*
536-
* @param[in] init_data - The INIT data as a vector.
537-
* @returns Ok on success, an error message otherwise.
536+
* Get the INIT string owned by the given LUT output or internal pin.
537+
* Returns the pin's hex slice, or the full INIT string when no bit range is configured.
538+
* An error is returned when the gate has no LUT component, the pin is nullptr,
539+
* its type is not `PinType::lut`, or its direction is neither `output` nor `internal`.
540+
*
541+
* @param[in] pin - The LUT pin.
542+
* @returns The INIT string as an uppercase hex string on success, an error otherwise.
543+
*/
544+
Result<std::string> get_init_string(const GatePin* pin) const;
545+
546+
/**
547+
* Set the INIT string for the given LUT output or internal pin.
548+
* The hex string must consist only of hex digits (no '0x' prefix). When a bit range
549+
* is configured for the pin its length must equal (bit_count + 3) / 4 characters.
550+
* An error is returned when the gate has no LUT component, the pin does not exist,
551+
* its type is not `PinType::lut`, its direction is neither `output` nor `internal`,
552+
* the pin has no INIT config, or the hex string has an invalid format or length.
553+
*
554+
* @param[in] pin_name - Name of the LUT output or internal pin.
555+
* @param[in] hex - The INIT string as a hex string without '0x' prefix.
556+
* @returns Ok on success, an error otherwise.
557+
*/
558+
Result<std::monostate> set_init_string(const std::string& pin_name, const std::string& hex);
559+
560+
/**
561+
* Set the INIT string for the given LUT output or internal pin.
562+
* The hex string must consist only of hex digits (no '0x' prefix). When a bit range
563+
* is configured for the pin its length must equal (bit_count + 3) / 4 characters.
564+
* An error is returned when the gate has no LUT component, the pin is nullptr,
565+
* its type is not `PinType::lut`, its direction is neither `output` nor `internal`,
566+
* the pin has no INIT config, or the hex string has an invalid format or length.
567+
*
568+
* @param[in] pin - The LUT output or internal pin.
569+
* @param[in] hex - The INIT string as a hex string without '0x' prefix.
570+
* @returns Ok on success, an error otherwise.
538571
*/
539-
Result<std::monostate> set_init_data(const std::vector<std::string>& init_data);
572+
Result<std::monostate> set_init_string(const GatePin* pin, const std::string& hex);
540573

541574
private:
542575
friend class NetlistInternalManager;

include/hal_core/netlist/gate_library/gate_type_component/gate_type_component.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,12 @@ namespace hal
5757
};
5858

5959
/**
60-
* Create a new LUTComponent with given child component and bit-order.
61-
*
62-
* @param[in] component - Another component to be added as a child component.
60+
* Create a new LUTComponent.
61+
*
6362
* @param[in] init_ascending - True if ascending bit-order, false otherwise.
6463
* @returns The LUTComponent.
6564
*/
66-
static std::unique_ptr<GateTypeComponent> create_lut_component(std::unique_ptr<GateTypeComponent> component, bool init_ascending);
65+
static std::unique_ptr<GateTypeComponent> create_lut_component(bool init_ascending);
6766

6867
/**
6968
* Create a new FFComponent with given child component and tzhe Boolean functions describing the next state and the clock signal.

include/hal_core/netlist/gate_library/gate_type_component/lut_component.h

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
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

plugins/gui/src/gatelibrary_management/gatelibrary_pages/lut_wizardpage.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ namespace hal
127127
mPinConfigTable->setCellWidget(row, 2, offsetSpin);
128128

129129
auto* countSpin = new QSpinBox(mPinConfigTable);
130-
countSpin->setRange(0, 1 << 20);
131-
countSpin->setSpecialValueText("full");
132-
countSpin->setValue(static_cast<int>(bitCount));
130+
countSpin->setRange(1, 1 << 20);
131+
countSpin->setValue(static_cast<int>(bitCount > 0 ? bitCount : 1));
133132
mPinConfigTable->setCellWidget(row, 3, countSpin);
134133
}
135134

@@ -149,7 +148,7 @@ namespace hal
149148

150149
void LUTWizardPage::addRow()
151150
{
152-
addTableRow("", "INIT", 0, 0, getOutputPinsFromWizard());
151+
addTableRow("", "INIT", 0, 1, getOutputPinsFromWizard());
153152
}
154153

155154
void LUTWizardPage::removeSelectedRow()

0 commit comments

Comments
 (0)