@@ -28,6 +28,22 @@ YOSYS_NAMESPACE_BEGIN
2828
2929struct ModIndex : public RTLIL ::Monitor
3030{
31+ struct PointerOrderedSigBit : public RTLIL ::SigBit {
32+ PointerOrderedSigBit (SigBit s) {
33+ wire = s.wire ;
34+ if (wire)
35+ offset = s.offset ;
36+ else
37+ data = s.data ;
38+ }
39+ inline bool operator <(const RTLIL ::SigBit &other) const {
40+ if (wire == other.wire )
41+ return wire ? (offset < other.offset ) : (data < other.data );
42+ if (wire != nullptr && other.wire != nullptr )
43+ return wire < other.wire ; // look here
44+ return (wire != nullptr ) < (other.wire != nullptr );
45+ }
46+ };
3147 struct PortInfo {
3248 RTLIL ::Cell* cell;
3349 RTLIL ::IdString port;
@@ -77,7 +93,7 @@ struct ModIndex : public RTLIL::Monitor
7793
7894 SigMap sigmap;
7995 RTLIL ::Module *module ;
80- std::map<RTLIL ::SigBit , SigBitInfo> database;
96+ std::map<PointerOrderedSigBit , SigBitInfo> database;
8197 int auto_reload_counter;
8298 bool auto_reload_module;
8399
@@ -94,8 +110,11 @@ struct ModIndex : public RTLIL::Monitor
94110 {
95111 for (int i = 0 ; i < GetSize (sig); i++) {
96112 RTLIL ::SigBit bit = sigmap (sig[i]);
97- if (bit.wire )
113+ if (bit.wire ) {
98114 database[bit].ports .erase (PortInfo (cell, port, i));
115+ if (!database[bit].is_input && !database[bit].is_output && database[bit].ports .empty ())
116+ database.erase (bit);
117+ }
99118 }
100119 }
101120
@@ -132,11 +151,11 @@ struct ModIndex : public RTLIL::Monitor
132151 }
133152 }
134153
135- void check ()
154+ bool ok ()
136155 {
137156#ifndef NDEBUG
138157 if (auto_reload_module)
139- return ;
158+ return true ;
140159
141160 for (auto it : database)
142161 log_assert (it.first == sigmap (it.first ));
@@ -156,11 +175,17 @@ struct ModIndex : public RTLIL::Monitor
156175 else if (!(it.second == database_bak.at (it.first )))
157176 log (" ModuleIndex::check(): Different content for database[%s].\n " , log_signal (it.first ));
158177
159- log_assert (database == database_bak) ;
178+ return false ;
160179 }
180+ return true ;
161181#endif
162182 }
163183
184+ void check ()
185+ {
186+ log_assert (ok ());
187+ }
188+
164189 void notify_connect (RTLIL ::Cell *cell, RTLIL ::IdString port, const RTLIL ::SigSpec &old_sig, const RTLIL ::SigSpec &sig) override
165190 {
166191 log_assert (module == cell->module );
0 commit comments