3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-23 09:05:32 +00:00

rtlil: Add {from,to}_hdl_index methods to Wire

In the past we had the occasional bug due to some place not handling all
4 combinations of upto/downto and zero/nonzero start_offset correctly.
This commit is contained in:
Jannis Harder 2025-02-12 15:34:51 +01:00
parent a9778e5b5a
commit f1ee9b7928
2 changed files with 106 additions and 1 deletions

View file

@ -1673,6 +1673,19 @@ public:
RTLIL::Cell *driverCell() const { log_assert(driverCell_); return driverCell_; };
RTLIL::IdString driverPort() const { log_assert(driverCell_); return driverPort_; };
int from_hdl_index(int hdl_index) {
int zero_index = hdl_index - start_offset;
int rtlil_index = upto ? width - 1 - zero_index : zero_index;
return rtlil_index >= 0 && rtlil_index < width ? rtlil_index : INT_MIN;
}
int to_hdl_index(int rtlil_index) {
if (rtlil_index < 0 || rtlil_index >= width)
return INT_MIN;
int zero_index = upto ? width - 1 - rtlil_index : rtlil_index;
return zero_index + start_offset;
}
#ifdef WITH_PYTHON
static std::map<unsigned int, RTLIL::Wire*> *get_all_wires(void);
#endif