yowasp-yosys 0.56.0.141.post974.dev0__py3-none-any.whl → 0.58.0.0.post1010__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. yowasp_yosys/share/gowin/cells_sim.v +0 -8
  2. yowasp_yosys/share/gowin/cells_xtra_gw1n.v +7 -0
  3. yowasp_yosys/share/gowin/cells_xtra_gw2a.v +12 -0
  4. yowasp_yosys/share/gowin/cells_xtra_gw5a.v +84 -0
  5. yowasp_yosys/share/include/backends/rtlil/rtlil_backend.h +1 -0
  6. yowasp_yosys/share/include/frontends/ast/ast.h +6 -1
  7. yowasp_yosys/share/include/kernel/bitpattern.h +50 -1
  8. yowasp_yosys/share/include/kernel/celltypes.h +19 -9
  9. yowasp_yosys/share/include/kernel/consteval.h +2 -2
  10. yowasp_yosys/share/include/kernel/constids.inc +859 -137
  11. yowasp_yosys/share/include/kernel/drivertools.h +6 -5
  12. yowasp_yosys/share/include/kernel/ffinit.h +5 -5
  13. yowasp_yosys/share/include/kernel/hashlib.h +88 -38
  14. yowasp_yosys/share/include/kernel/io.h +17 -2
  15. yowasp_yosys/share/include/kernel/log.h +102 -31
  16. yowasp_yosys/share/include/kernel/macc.h +1 -1
  17. yowasp_yosys/share/include/kernel/mem.h +4 -2
  18. yowasp_yosys/share/include/kernel/rtlil.h +268 -61
  19. yowasp_yosys/share/include/kernel/satgen.h +1 -1
  20. yowasp_yosys/share/include/kernel/threading.h +186 -0
  21. yowasp_yosys/share/include/kernel/utils.h +11 -0
  22. yowasp_yosys/share/include/kernel/yosys_common.h +9 -13
  23. yowasp_yosys/share/include/passes/fsm/fsmdata.h +18 -33
  24. yowasp_yosys/share/include/passes/techmap/libparse.h +1 -1
  25. yowasp_yosys/share/lattice/cells_bb_ecp5.v +4 -0
  26. yowasp_yosys/share/python3/sby_engine_abc.py +5 -2
  27. yowasp_yosys/share/simlib.v +34 -0
  28. yowasp_yosys/share/techmap.v +34 -2
  29. yowasp_yosys/smtbmc.py +5 -0
  30. yowasp_yosys/yosys.wasm +0 -0
  31. {yowasp_yosys-0.56.0.141.post974.dev0.dist-info → yowasp_yosys-0.58.0.0.post1010.dist-info}/METADATA +1 -1
  32. {yowasp_yosys-0.56.0.141.post974.dev0.dist-info → yowasp_yosys-0.58.0.0.post1010.dist-info}/RECORD +35 -34
  33. {yowasp_yosys-0.56.0.141.post974.dev0.dist-info → yowasp_yosys-0.58.0.0.post1010.dist-info}/WHEEL +0 -0
  34. {yowasp_yosys-0.56.0.141.post974.dev0.dist-info → yowasp_yosys-0.58.0.0.post1010.dist-info}/entry_points.txt +0 -0
  35. {yowasp_yosys-0.56.0.141.post974.dev0.dist-info → yowasp_yosys-0.58.0.0.post1010.dist-info}/top_level.txt +0 -0
@@ -83,6 +83,21 @@ namespace RTLIL
83
83
  SB_EXCL_BB_CMDERR = 15 // call log_cmd_error on black boxed module
84
84
  };
85
85
 
86
+ enum class StaticId : short {
87
+ STATIC_ID_BEGIN = 0,
88
+ #define X(N) N,
89
+ #include "kernel/constids.inc"
90
+ #undef X
91
+ STATIC_ID_END,
92
+ };
93
+
94
+ enum PortDir : unsigned char {
95
+ PD_UNKNOWN = 0,
96
+ PD_INPUT = 1,
97
+ PD_OUTPUT = 2,
98
+ PD_INOUT = 3
99
+ };
100
+
86
101
  struct Const;
87
102
  struct AttrObject;
88
103
  struct NamedObject;
@@ -105,8 +120,19 @@ namespace RTLIL
105
120
  struct Process;
106
121
  struct Binding;
107
122
  struct IdString;
123
+ struct StaticIdString;
108
124
 
109
125
  typedef std::pair<SigSpec, SigSpec> SigSig;
126
+
127
+ struct StaticIdString {
128
+ constexpr StaticIdString(StaticId id, const IdString &id_str) : id_str(id_str), id(id) {}
129
+ constexpr inline operator const IdString &() const { return id_str; }
130
+ constexpr inline int index() const { return static_cast<short>(id); }
131
+ constexpr inline const IdString &id_string() const { return id_str; }
132
+
133
+ const IdString &id_str;
134
+ const StaticId id;
135
+ };
110
136
  };
111
137
 
112
138
  struct RTLIL::IdString
@@ -127,7 +153,13 @@ struct RTLIL::IdString
127
153
  static std::vector<char*> global_id_storage_;
128
154
  static std::unordered_map<std::string_view, int> global_id_index_;
129
155
  #ifndef YOSYS_NO_IDS_REFCNT
130
- static std::vector<int> global_refcount_storage_;
156
+ // For prepopulated IdStrings, the refcount is meaningless since they
157
+ // are never freed even if the refcount is zero. For code efficiency
158
+ // we increment the refcount of prepopulated IdStrings like any other string,
159
+ // but we never decrement the refcount or check whether it's zero.
160
+ // So, make this unsigned because refcounts of preopulated IdStrings may overflow
161
+ // and overflow of signed integers is undefined behavior.
162
+ static std::vector<uint32_t> global_refcount_storage_;
131
163
  static std::vector<int> global_free_idx_list_;
132
164
  #endif
133
165
 
@@ -144,7 +176,7 @@ struct RTLIL::IdString
144
176
  if (global_id_storage_.at(idx) == nullptr)
145
177
  log("#X# DB-DUMP index %d: FREE\n", idx);
146
178
  else
147
- log("#X# DB-DUMP index %d: '%s' (ref %d)\n", idx, global_id_storage_.at(idx), global_refcount_storage_.at(idx));
179
+ log("#X# DB-DUMP index %d: '%s' (ref %u)\n", idx, global_id_storage_.at(idx), global_refcount_storage_.at(idx));
148
180
  }
149
181
  #endif
150
182
  }
@@ -166,15 +198,13 @@ struct RTLIL::IdString
166
198
 
167
199
  static inline int get_reference(int idx)
168
200
  {
169
- if (idx) {
170
201
  #ifndef YOSYS_NO_IDS_REFCNT
171
- global_refcount_storage_[idx]++;
202
+ global_refcount_storage_[idx]++;
172
203
  #endif
173
204
  #ifdef YOSYS_XTRACE_GET_PUT
174
- if (yosys_xtrace)
175
- log("#X# GET-BY-INDEX '%s' (index %d, refcount %d)\n", global_id_storage_.at(idx), idx, global_refcount_storage_.at(idx));
205
+ if (yosys_xtrace && idx >= static_cast<short>(StaticId::STATIC_ID_END))
206
+ log("#X# GET-BY-INDEX '%s' (index %d, refcount %u)\n", global_id_storage_.at(idx), idx, global_refcount_storage_.at(idx));
176
207
  #endif
177
- }
178
208
  return idx;
179
209
  }
180
210
 
@@ -182,9 +212,6 @@ struct RTLIL::IdString
182
212
  {
183
213
  log_assert(destruct_guard_ok);
184
214
 
185
- if (!p[0])
186
- return 0;
187
-
188
215
  auto it = global_id_index_.find((char*)p);
189
216
  if (it != global_id_index_.end()) {
190
217
  #ifndef YOSYS_NO_IDS_REFCNT
@@ -192,11 +219,16 @@ struct RTLIL::IdString
192
219
  #endif
193
220
  #ifdef YOSYS_XTRACE_GET_PUT
194
221
  if (yosys_xtrace)
195
- log("#X# GET-BY-NAME '%s' (index %d, refcount %d)\n", global_id_storage_.at(it->second), it->second, global_refcount_storage_.at(it->second));
222
+ log("#X# GET-BY-NAME '%s' (index %d, refcount %u)\n", global_id_storage_.at(it->second), it->second, global_refcount_storage_.at(it->second));
196
223
  #endif
197
224
  return it->second;
198
225
  }
199
226
 
227
+ ensure_prepopulated();
228
+
229
+ if (!p[0])
230
+ return 0;
231
+
200
232
  log_assert(p[0] == '$' || p[0] == '\\');
201
233
  log_assert(p[1] != 0);
202
234
  for (const char *c = p; *c; c++)
@@ -205,11 +237,6 @@ struct RTLIL::IdString
205
237
 
206
238
  #ifndef YOSYS_NO_IDS_REFCNT
207
239
  if (global_free_idx_list_.empty()) {
208
- if (global_id_storage_.empty()) {
209
- global_refcount_storage_.push_back(0);
210
- global_id_storage_.push_back((char*)"");
211
- global_id_index_[global_id_storage_.back()] = 0;
212
- }
213
240
  log_assert(global_id_storage_.size() < 0x40000000);
214
241
  global_free_idx_list_.push_back(global_id_storage_.size());
215
242
  global_id_storage_.push_back(nullptr);
@@ -222,10 +249,6 @@ struct RTLIL::IdString
222
249
  global_id_index_[global_id_storage_.at(idx)] = idx;
223
250
  global_refcount_storage_.at(idx)++;
224
251
  #else
225
- if (global_id_storage_.empty()) {
226
- global_id_storage_.push_back((char*)"");
227
- global_id_index_[global_id_storage_.back()] = 0;
228
- }
229
252
  int idx = global_id_storage_.size();
230
253
  global_id_storage_.push_back(strdup(p));
231
254
  global_id_index_[global_id_storage_.back()] = idx;
@@ -238,7 +261,7 @@ struct RTLIL::IdString
238
261
 
239
262
  #ifdef YOSYS_XTRACE_GET_PUT
240
263
  if (yosys_xtrace)
241
- log("#X# GET-BY-NAME '%s' (index %d, refcount %d)\n", global_id_storage_.at(idx), idx, global_refcount_storage_.at(idx));
264
+ log("#X# GET-BY-NAME '%s' (index %d, refcount %u)\n", global_id_storage_.at(idx), idx, global_refcount_storage_.at(idx));
242
265
  #endif
243
266
 
244
267
  #ifdef YOSYS_USE_STICKY_IDS
@@ -258,21 +281,20 @@ struct RTLIL::IdString
258
281
  {
259
282
  // put_reference() may be called from destructors after the destructor of
260
283
  // global_refcount_storage_ has been run. in this case we simply do nothing.
261
- if (!destruct_guard_ok || !idx)
284
+ if (idx < static_cast<short>(StaticId::STATIC_ID_END) || !destruct_guard_ok)
262
285
  return;
263
286
 
264
287
  #ifdef YOSYS_XTRACE_GET_PUT
265
288
  if (yosys_xtrace) {
266
- log("#X# PUT '%s' (index %d, refcount %d)\n", global_id_storage_.at(idx), idx, global_refcount_storage_.at(idx));
289
+ log("#X# PUT '%s' (index %d, refcount %u)\n", global_id_storage_.at(idx), idx, global_refcount_storage_.at(idx));
267
290
  }
268
291
  #endif
269
292
 
270
- int &refcount = global_refcount_storage_[idx];
293
+ uint32_t &refcount = global_refcount_storage_[idx];
271
294
 
272
295
  if (--refcount > 0)
273
296
  return;
274
297
 
275
- log_assert(refcount == 0);
276
298
  free_reference(idx);
277
299
  }
278
300
  static inline void free_reference(int idx)
@@ -281,6 +303,7 @@ struct RTLIL::IdString
281
303
  log("#X# Removed IdString '%s' with index %d.\n", global_id_storage_.at(idx), idx);
282
304
  log_backtrace("-X- ", yosys_xtrace-1);
283
305
  }
306
+ log_assert(idx >= static_cast<short>(StaticId::STATIC_ID_END));
284
307
 
285
308
  global_id_index_.erase(global_id_storage_.at(idx));
286
309
  free(global_id_storage_.at(idx));
@@ -300,6 +323,7 @@ struct RTLIL::IdString
300
323
  inline IdString(const IdString &str) : index_(get_reference(str.index_)) { }
301
324
  inline IdString(IdString &&str) : index_(str.index_) { str.index_ = 0; }
302
325
  inline IdString(const std::string &str) : index_(get_reference(str.c_str())) { }
326
+ inline IdString(StaticId id) : index_(static_cast<short>(id)) {}
303
327
  inline ~IdString() { put_reference(index_); }
304
328
 
305
329
  inline void operator=(const IdString &rhs) {
@@ -317,6 +341,8 @@ struct RTLIL::IdString
317
341
  *this = id;
318
342
  }
319
343
 
344
+ constexpr inline const IdString &id_string() const { return *this; }
345
+
320
346
  inline const char *c_str() const {
321
347
  return global_id_storage_.at(index_);
322
348
  }
@@ -331,6 +357,8 @@ struct RTLIL::IdString
331
357
 
332
358
  inline bool operator==(const IdString &rhs) const { return index_ == rhs.index_; }
333
359
  inline bool operator!=(const IdString &rhs) const { return index_ != rhs.index_; }
360
+ inline bool operator==(const StaticIdString &rhs) const;
361
+ inline bool operator!=(const StaticIdString &rhs) const;
334
362
 
335
363
  // The methods below are just convenience functions for better compatibility with std::string.
336
364
 
@@ -383,7 +411,7 @@ struct RTLIL::IdString
383
411
  }
384
412
 
385
413
  bool empty() const {
386
- return c_str()[0] == 0;
414
+ return index_ == 0;
387
415
  }
388
416
 
389
417
  void clear() {
@@ -411,17 +439,27 @@ struct RTLIL::IdString
411
439
  // often one needs to check if a given IdString is part of a list (for example a list
412
440
  // of cell types). the following functions helps with that.
413
441
  template<typename... Args>
414
- bool in(Args... args) const {
442
+ bool in(const Args &... args) const {
415
443
  return (... || in(args));
416
444
  }
417
445
 
418
446
  bool in(const IdString &rhs) const { return *this == rhs; }
447
+ bool in(const StaticIdString &rhs) const { return *this == rhs; }
419
448
  bool in(const char *rhs) const { return *this == rhs; }
420
449
  bool in(const std::string &rhs) const { return *this == rhs; }
421
450
  inline bool in(const pool<IdString> &rhs) const;
422
451
  inline bool in(const pool<IdString> &&rhs) const;
423
452
 
424
453
  bool isPublic() const { return begins_with("\\"); }
454
+
455
+ private:
456
+ static void prepopulate();
457
+
458
+ public:
459
+ static void ensure_prepopulated() {
460
+ if (global_id_index_.empty())
461
+ prepopulate();
462
+ }
425
463
  };
426
464
 
427
465
  namespace hashlib {
@@ -430,10 +468,10 @@ namespace hashlib {
430
468
  static inline bool cmp(const RTLIL::IdString &a, const RTLIL::IdString &b) {
431
469
  return a == b;
432
470
  }
433
- [[nodiscard]] static inline Hasher hash(const RTLIL::IdString id) {
471
+ [[nodiscard]] static inline Hasher hash(const RTLIL::IdString &id) {
434
472
  return id.hash_top();
435
473
  }
436
- [[nodiscard]] static inline Hasher hash_into(const RTLIL::IdString id, Hasher h) {
474
+ [[nodiscard]] static inline Hasher hash_into(const RTLIL::IdString &id, Hasher h) {
437
475
  return id.hash_into(h);
438
476
  }
439
477
  };
@@ -449,14 +487,88 @@ inline bool RTLIL::IdString::in(const pool<IdString> &rhs) const { return rhs.co
449
487
  [[deprecated]]
450
488
  inline bool RTLIL::IdString::in(const pool<IdString> &&rhs) const { return rhs.count(*this) != 0; }
451
489
 
490
+ inline bool RTLIL::IdString::operator==(const RTLIL::StaticIdString &rhs) const {
491
+ return index_ == rhs.index();
492
+ }
493
+ inline bool RTLIL::IdString::operator!=(const RTLIL::StaticIdString &rhs) const {
494
+ return index_ != rhs.index();
495
+ }
496
+
452
497
  namespace RTLIL {
498
+ namespace IDInternal {
499
+ #define X(_id) extern const IdString _id;
500
+ #include "kernel/constids.inc"
501
+ #undef X
502
+ }
453
503
  namespace ID {
454
- #define X(_id) extern IdString _id;
504
+ #define X(_id) constexpr StaticIdString _id(StaticId::_id, IDInternal::_id);
455
505
  #include "kernel/constids.inc"
456
506
  #undef X
457
- };
507
+ }
508
+ }
509
+
510
+ struct IdTableEntry {
511
+ const std::string_view name;
512
+ const RTLIL::StaticIdString static_id;
513
+ };
514
+
515
+ constexpr IdTableEntry IdTable[] = {
516
+ #define X(_id) {#_id, ID::_id},
517
+ #include "kernel/constids.inc"
518
+ #undef X
519
+ };
520
+
521
+ constexpr int lookup_well_known_id(std::string_view name)
522
+ {
523
+ int low = 0;
524
+ int high = sizeof(IdTable) / sizeof(IdTable[0]);
525
+ while (high - low >= 2) {
526
+ int mid = (low + high) / 2;
527
+ if (name < IdTable[mid].name)
528
+ high = mid;
529
+ else
530
+ low = mid;
531
+ }
532
+ if (IdTable[low].name == name)
533
+ return low;
534
+ return -1;
535
+ }
536
+
537
+ // Create a statically allocated IdString object, using for example ID::A or ID($add).
538
+ //
539
+ // Recipe for Converting old code that is using conversion of strings like ID::A and
540
+ // "$add" for creating IdStrings: Run below SED command on the .cc file and then use for
541
+ // example "meld foo.cc foo.cc.orig" to manually compile errors, if necessary.
542
+ //
543
+ // sed -i.orig -r 's/"\\\\([a-zA-Z0-9_]+)"/ID(\1)/g; s/"(\$[a-zA-Z0-9_]+)"/ID(\1)/g;' <filename>
544
+ //
545
+ typedef const RTLIL::IdString &IDMacroHelperFunc();
546
+
547
+ template <int IdTableIndex> struct IDMacroHelper {
548
+ static constexpr RTLIL::StaticIdString eval(IDMacroHelperFunc) {
549
+ return IdTable[IdTableIndex].static_id;
550
+ }
551
+ };
552
+ template <> struct IDMacroHelper<-1> {
553
+ static constexpr const RTLIL::IdString &eval(IDMacroHelperFunc func) {
554
+ return func();
555
+ }
556
+ };
557
+
558
+ #define ID(_id) \
559
+ YOSYS_NAMESPACE_PREFIX IDMacroHelper< \
560
+ YOSYS_NAMESPACE_PREFIX lookup_well_known_id(#_id) \
561
+ >::eval([]() \
562
+ -> const YOSYS_NAMESPACE_PREFIX RTLIL::IdString & { \
563
+ const char *p = "\\" #_id, *q = p[1] == '$' ? p+1 : p; \
564
+ static const YOSYS_NAMESPACE_PREFIX RTLIL::IdString id(q); \
565
+ return id; \
566
+ })
567
+
568
+ namespace RTLIL {
458
569
  extern dict<std::string, std::string> constpad;
459
570
 
571
+ [[deprecated("Call cell->is_builtin_ff() instead")]]
460
572
  const pool<IdString> &builtin_ff_cell_types();
461
573
 
462
574
  static inline std::string escape_id(const std::string &str) {
@@ -723,38 +835,61 @@ private:
723
835
  using bitvectype = std::vector<RTLIL::State>;
724
836
  enum class backing_tag: bool { bits, string };
725
837
  // Do not access the union or tag even in Const methods unless necessary
726
- mutable backing_tag tag;
838
+ backing_tag tag;
727
839
  union {
728
- mutable bitvectype bits_;
729
- mutable std::string str_;
840
+ bitvectype bits_;
841
+ std::string str_;
730
842
  };
731
843
 
732
844
  // Use these private utilities instead
733
845
  bool is_bits() const { return tag == backing_tag::bits; }
734
846
  bool is_str() const { return tag == backing_tag::string; }
735
847
 
736
- bitvectype* get_if_bits() const { return is_bits() ? &bits_ : NULL; }
737
- std::string* get_if_str() const { return is_str() ? &str_ : NULL; }
848
+ bitvectype* get_if_bits() { return is_bits() ? &bits_ : NULL; }
849
+ std::string* get_if_str() { return is_str() ? &str_ : NULL; }
850
+ const bitvectype* get_if_bits() const { return is_bits() ? &bits_ : NULL; }
851
+ const std::string* get_if_str() const { return is_str() ? &str_ : NULL; }
852
+
853
+ bitvectype& get_bits();
854
+ std::string& get_str();
855
+ const bitvectype& get_bits() const;
856
+ const std::string& get_str() const;
857
+ std::vector<RTLIL::State>& bits_internal();
858
+ void bitvectorize_internal();
738
859
 
739
- bitvectype& get_bits() const;
740
- std::string& get_str() const;
741
860
  public:
742
861
  Const() : flags(RTLIL::CONST_FLAG_NONE), tag(backing_tag::bits), bits_(std::vector<RTLIL::State>()) {}
743
862
  Const(const std::string &str);
744
- Const(long long val, int width = 32);
863
+ Const(long long val); // default width is 32
864
+ Const(long long val, int width);
745
865
  Const(RTLIL::State bit, int width = 1);
746
- Const(const std::vector<RTLIL::State> &bits) : flags(RTLIL::CONST_FLAG_NONE), tag(backing_tag::bits), bits_(bits) {}
866
+ Const(std::vector<RTLIL::State> bits) : flags(RTLIL::CONST_FLAG_NONE), tag(backing_tag::bits), bits_(std::move(bits)) {}
747
867
  Const(const std::vector<bool> &bits);
748
868
  Const(const RTLIL::Const &other);
749
869
  Const(RTLIL::Const &&other);
750
870
  RTLIL::Const &operator =(const RTLIL::Const &other);
751
871
  ~Const();
752
872
 
873
+ struct Builder
874
+ {
875
+ Builder() {}
876
+ Builder(int expected_width) { bits.reserve(expected_width); }
877
+ void push_back(RTLIL::State b) { bits.push_back(b); }
878
+ int size() const { return static_cast<int>(bits.size()); }
879
+ Const build() { return Const(std::move(bits)); }
880
+ private:
881
+ std::vector<RTLIL::State> bits;
882
+ };
883
+
753
884
  bool operator <(const RTLIL::Const &other) const;
754
885
  bool operator ==(const RTLIL::Const &other) const;
755
886
  bool operator !=(const RTLIL::Const &other) const;
756
887
 
757
- std::vector<RTLIL::State>& bits();
888
+ [[deprecated("Don't use direct access to the internal std::vector<State>, that's an implementation detail.")]]
889
+ std::vector<RTLIL::State>& bits() { return bits_internal(); }
890
+ [[deprecated("Don't call bitvectorize() directly, it's an implementation detail.")]]
891
+ void bitvectorize() const { const_cast<Const*>(this)->bitvectorize_internal(); }
892
+
758
893
  bool as_bool() const;
759
894
 
760
895
  // Convert the constant value to a C++ int.
@@ -783,37 +918,42 @@ public:
783
918
  std::string decode_string() const;
784
919
  int size() const;
785
920
  bool empty() const;
786
- void bitvectorize() const;
787
921
 
788
922
  void append(const RTLIL::Const &other);
923
+ void set(int i, RTLIL::State state) {
924
+ bits_internal()[i] = state;
925
+ }
926
+ void resize(int size, RTLIL::State fill) {
927
+ bits_internal().resize(size, fill);
928
+ }
789
929
 
790
930
  class const_iterator {
791
931
  private:
792
- const Const& parent;
932
+ const Const* parent;
793
933
  size_t idx;
794
934
 
795
935
  public:
796
- using iterator_category = std::input_iterator_tag;
936
+ using iterator_category = std::bidirectional_iterator_tag;
797
937
  using value_type = State;
798
938
  using difference_type = std::ptrdiff_t;
799
939
  using pointer = const State*;
800
940
  using reference = const State&;
801
941
 
802
- const_iterator(const Const& c, size_t i) : parent(c), idx(i) {}
942
+ const_iterator(const Const& c, size_t i) : parent(&c), idx(i) {}
803
943
 
804
944
  State operator*() const;
805
945
 
806
946
  const_iterator& operator++() { ++idx; return *this; }
807
947
  const_iterator& operator--() { --idx; return *this; }
808
- const_iterator& operator++(int) { ++idx; return *this; }
809
- const_iterator& operator--(int) { --idx; return *this; }
948
+ const_iterator operator++(int) { const_iterator result(*this); ++idx; return result; }
949
+ const_iterator operator--(int) { const_iterator result(*this); --idx; return result; }
810
950
  const_iterator& operator+=(int i) { idx += i; return *this; }
811
951
 
812
952
  const_iterator operator+(int add) {
813
- return const_iterator(parent, idx + add);
953
+ return const_iterator(*parent, idx + add);
814
954
  }
815
955
  const_iterator operator-(int sub) {
816
- return const_iterator(parent, idx - sub);
956
+ return const_iterator(*parent, idx - sub);
817
957
  }
818
958
  int operator-(const const_iterator& other) {
819
959
  return idx - other.idx;
@@ -828,12 +968,69 @@ public:
828
968
  }
829
969
  };
830
970
 
971
+ class iterator {
972
+ private:
973
+ Const* parent;
974
+ size_t idx;
975
+
976
+ public:
977
+ class proxy {
978
+ private:
979
+ Const* parent;
980
+ size_t idx;
981
+ public:
982
+ proxy(Const* parent, size_t idx) : parent(parent), idx(idx) {}
983
+ operator State() const { return (*parent)[idx]; }
984
+ proxy& operator=(State s) { parent->set(idx, s); return *this; }
985
+ proxy& operator=(const proxy& other) { parent->set(idx, (*other.parent)[other.idx]); return *this; }
986
+ };
987
+
988
+ using iterator_category = std::bidirectional_iterator_tag;
989
+ using value_type = State;
990
+ using difference_type = std::ptrdiff_t;
991
+ using pointer = proxy*;
992
+ using reference = proxy;
993
+
994
+ iterator(Const& c, size_t i) : parent(&c), idx(i) {}
995
+
996
+ proxy operator*() const { return proxy(parent, idx); }
997
+ iterator& operator++() { ++idx; return *this; }
998
+ iterator& operator--() { --idx; return *this; }
999
+ iterator operator++(int) { iterator result(*this); ++idx; return result; }
1000
+ iterator operator--(int) { iterator result(*this); --idx; return result; }
1001
+ iterator& operator+=(int i) { idx += i; return *this; }
1002
+
1003
+ iterator operator+(int add) {
1004
+ return iterator(*parent, idx + add);
1005
+ }
1006
+ iterator operator-(int sub) {
1007
+ return iterator(*parent, idx - sub);
1008
+ }
1009
+ int operator-(const iterator& other) {
1010
+ return idx - other.idx;
1011
+ }
1012
+
1013
+ bool operator==(const iterator& other) const {
1014
+ return idx == other.idx;
1015
+ }
1016
+
1017
+ bool operator!=(const iterator& other) const {
1018
+ return !(*this == other);
1019
+ }
1020
+ };
1021
+
831
1022
  const_iterator begin() const {
832
1023
  return const_iterator(*this, 0);
833
1024
  }
834
1025
  const_iterator end() const {
835
1026
  return const_iterator(*this, size());
836
1027
  }
1028
+ iterator begin() {
1029
+ return iterator(*this, 0);
1030
+ }
1031
+ iterator end() {
1032
+ return iterator(*this, size());
1033
+ }
837
1034
  State back() const {
838
1035
  return *(end() - 1);
839
1036
  }
@@ -865,20 +1062,14 @@ public:
865
1062
  std::optional<int> as_int_compress(bool is_signed) const;
866
1063
 
867
1064
  void extu(int width) {
868
- bits().resize(width, RTLIL::State::S0);
1065
+ resize(width, RTLIL::State::S0);
869
1066
  }
870
1067
 
871
1068
  void exts(int width) {
872
- bitvectype& bv = bits();
873
- bv.resize(width, bv.empty() ? RTLIL::State::Sx : bv.back());
1069
+ resize(width, empty() ? RTLIL::State::Sx : back());
874
1070
  }
875
1071
 
876
- [[nodiscard]] Hasher hash_into(Hasher h) const {
877
- h.eat(size());
878
- for (auto b : *this)
879
- h.eat(b);
880
- return h;
881
- }
1072
+ [[nodiscard]] Hasher hash_into(Hasher h) const;
882
1073
  };
883
1074
 
884
1075
  struct RTLIL::AttrObject
@@ -933,7 +1124,8 @@ struct RTLIL::SigChunk
933
1124
  SigChunk(RTLIL::Wire *wire) : wire(wire), width(GetSize(wire)), offset(0) {}
934
1125
  SigChunk(RTLIL::Wire *wire, int offset, int width = 1) : wire(wire), width(width), offset(offset) {}
935
1126
  SigChunk(const std::string &str) : SigChunk(RTLIL::Const(str)) {}
936
- SigChunk(int val, int width = 32) : SigChunk(RTLIL::Const(val, width)) {}
1127
+ SigChunk(int val) /*default width 32*/ : SigChunk(RTLIL::Const(val)) {}
1128
+ SigChunk(int val, int width) : SigChunk(RTLIL::Const(val, width)) {}
937
1129
  SigChunk(RTLIL::State bit, int width = 1) : SigChunk(RTLIL::Const(bit, width)) {}
938
1130
  SigChunk(const RTLIL::SigBit &bit);
939
1131
 
@@ -1052,7 +1244,8 @@ private:
1052
1244
  public:
1053
1245
  SigSpec() : width_(0), hash_(0) {}
1054
1246
  SigSpec(std::initializer_list<RTLIL::SigSpec> parts);
1055
-
1247
+ SigSpec(const SigSpec &value) = default;
1248
+ SigSpec(SigSpec &&value) = default;
1056
1249
  SigSpec(const RTLIL::Const &value);
1057
1250
  SigSpec(RTLIL::Const &&value);
1058
1251
  SigSpec(const RTLIL::SigChunk &chunk);
@@ -1069,6 +1262,9 @@ public:
1069
1262
  SigSpec(const std::set<RTLIL::SigBit> &bits);
1070
1263
  explicit SigSpec(bool bit);
1071
1264
 
1265
+ SigSpec &operator=(const SigSpec &rhs) = default;
1266
+ SigSpec &operator=(SigSpec &&rhs) = default;
1267
+
1072
1268
  inline const std::vector<RTLIL::SigChunk> &chunks() const { pack(); return chunks_; }
1073
1269
  inline const std::vector<RTLIL::SigBit> &bits() const { inline_unpack(); return bits_; }
1074
1270
 
@@ -1142,12 +1338,15 @@ public:
1142
1338
  bool is_chunk() const;
1143
1339
  inline bool is_bit() const { return width_ == 1; }
1144
1340
 
1341
+ bool known_driver() const;
1342
+
1145
1343
  bool is_fully_const() const;
1146
1344
  bool is_fully_zero() const;
1147
1345
  bool is_fully_ones() const;
1148
1346
  bool is_fully_def() const;
1149
1347
  bool is_fully_undef() const;
1150
1348
  bool has_const() const;
1349
+ bool has_const(State state) const;
1151
1350
  bool has_marked_bits() const;
1152
1351
  bool is_onehot(int *pos = nullptr) const;
1153
1352
 
@@ -1539,7 +1738,11 @@ public:
1539
1738
  std::vector<RTLIL::IdString> ports;
1540
1739
  void fixup_ports();
1541
1740
 
1542
- pool<pair<RTLIL::Cell*, RTLIL::IdString>> bufNormQueue;
1741
+ pool<RTLIL::Cell *> buf_norm_cell_queue;
1742
+ pool<pair<RTLIL::Cell *, RTLIL::IdString>> buf_norm_cell_port_queue;
1743
+ pool<RTLIL::Wire *> buf_norm_wire_queue;
1744
+ pool<RTLIL::Cell *> pending_deleted_cells;
1745
+ dict<RTLIL::Wire *, pool<RTLIL::Cell *>> buf_norm_connect_index;
1543
1746
  void bufNormalize();
1544
1747
 
1545
1748
  template<typename T> void rewrite_sigspecs(T &functor);
@@ -1872,6 +2075,8 @@ public:
1872
2075
  int width, start_offset, port_id;
1873
2076
  bool port_input, port_output, upto, is_signed;
1874
2077
 
2078
+ bool known_driver() const { return driverCell_ != nullptr; }
2079
+
1875
2080
  RTLIL::Cell *driverCell() const { log_assert(driverCell_); return driverCell_; };
1876
2081
  RTLIL::IdString driverPort() const { log_assert(driverCell_); return driverPort_; };
1877
2082
 
@@ -1943,6 +2148,7 @@ public:
1943
2148
  bool known() const;
1944
2149
  bool input(const RTLIL::IdString &portname) const;
1945
2150
  bool output(const RTLIL::IdString &portname) const;
2151
+ PortDir port_dir(const RTLIL::IdString &portname) const;
1946
2152
 
1947
2153
  // access cell parameters
1948
2154
  bool hasParam(const RTLIL::IdString &paramname) const;
@@ -1968,6 +2174,7 @@ public:
1968
2174
 
1969
2175
  bool has_memid() const;
1970
2176
  bool is_mem_cell() const;
2177
+ bool is_builtin_ff() const;
1971
2178
  };
1972
2179
 
1973
2180
  struct RTLIL::CaseRule : public RTLIL::AttrObject
@@ -103,7 +103,7 @@ struct SatGen
103
103
  } else {
104
104
  std::string wire_name = RTLIL::unescape_id(bit.wire->name);
105
105
  std::string name = pf +
106
- (bit.wire->width == 1 ? wire_name : stringf("%s [%d]", wire_name.c_str(), bit.offset));
106
+ (bit.wire->width == 1 ? wire_name : stringf("%s [%d]", wire_name, bit.offset));
107
107
  vec.push_back(ez->frozen_literal(name));
108
108
  imported_signals[pf][bit] = vec.back();
109
109
  }