Merge pull request #2585 from YosysHQ/dave/nexus-dotproduct
[yosys.git] / kernel / rtlil.h
1 /* -*- c++ -*-
2 * yosys -- Yosys Open SYnthesis Suite
3 *
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 */
19
20 #include "kernel/yosys.h"
21
22 #ifndef RTLIL_H
23 #define RTLIL_H
24
25 YOSYS_NAMESPACE_BEGIN
26
27 namespace RTLIL
28 {
29 enum State : unsigned char {
30 S0 = 0,
31 S1 = 1,
32 Sx = 2, // undefined value or conflict
33 Sz = 3, // high-impedance / not-connected
34 Sa = 4, // don't care (used only in cases)
35 Sm = 5 // marker (used internally by some passes)
36 };
37
38 enum SyncType : unsigned char {
39 ST0 = 0, // level sensitive: 0
40 ST1 = 1, // level sensitive: 1
41 STp = 2, // edge sensitive: posedge
42 STn = 3, // edge sensitive: negedge
43 STe = 4, // edge sensitive: both edges
44 STa = 5, // always active
45 STg = 6, // global clock
46 STi = 7 // init
47 };
48
49 enum ConstFlags : unsigned char {
50 CONST_FLAG_NONE = 0,
51 CONST_FLAG_STRING = 1,
52 CONST_FLAG_SIGNED = 2, // only used for parameters
53 CONST_FLAG_REAL = 4 // only used for parameters
54 };
55
56 struct Const;
57 struct AttrObject;
58 struct Selection;
59 struct Monitor;
60 struct Design;
61 struct Module;
62 struct Wire;
63 struct Memory;
64 struct Cell;
65 struct SigChunk;
66 struct SigBit;
67 struct SigSpecIterator;
68 struct SigSpecConstIterator;
69 struct SigSpec;
70 struct CaseRule;
71 struct SwitchRule;
72 struct SyncRule;
73 struct Process;
74
75 typedef std::pair<SigSpec, SigSpec> SigSig;
76
77 struct IdString
78 {
79 #undef YOSYS_XTRACE_GET_PUT
80 #undef YOSYS_SORT_ID_FREE_LIST
81 #undef YOSYS_USE_STICKY_IDS
82 #undef YOSYS_NO_IDS_REFCNT
83
84 // the global id string cache
85
86 static struct destruct_guard_t {
87 bool ok; // POD, will be initialized to zero
88 destruct_guard_t() { ok = true; }
89 ~destruct_guard_t() { ok = false; }
90 } destruct_guard;
91
92 static std::vector<char*> global_id_storage_;
93 static dict<char*, int, hash_cstr_ops> global_id_index_;
94 #ifndef YOSYS_NO_IDS_REFCNT
95 static std::vector<int> global_refcount_storage_;
96 static std::vector<int> global_free_idx_list_;
97 #endif
98
99 #ifdef YOSYS_USE_STICKY_IDS
100 static int last_created_idx_ptr_;
101 static int last_created_idx_[8];
102 #endif
103
104 static inline void xtrace_db_dump()
105 {
106 #ifdef YOSYS_XTRACE_GET_PUT
107 for (int idx = 0; idx < GetSize(global_id_storage_); idx++)
108 {
109 if (global_id_storage_.at(idx) == nullptr)
110 log("#X# DB-DUMP index %d: FREE\n", idx);
111 else
112 log("#X# DB-DUMP index %d: '%s' (ref %d)\n", idx, global_id_storage_.at(idx), global_refcount_storage_.at(idx));
113 }
114 #endif
115 }
116
117 static inline void checkpoint()
118 {
119 #ifdef YOSYS_USE_STICKY_IDS
120 last_created_idx_ptr_ = 0;
121 for (int i = 0; i < 8; i++) {
122 if (last_created_idx_[i])
123 put_reference(last_created_idx_[i]);
124 last_created_idx_[i] = 0;
125 }
126 #endif
127 #ifdef YOSYS_SORT_ID_FREE_LIST
128 std::sort(global_free_idx_list_.begin(), global_free_idx_list_.end(), std::greater<int>());
129 #endif
130 }
131
132 static inline int get_reference(int idx)
133 {
134 if (idx) {
135 #ifndef YOSYS_NO_IDS_REFCNT
136 global_refcount_storage_[idx]++;
137 #endif
138 #ifdef YOSYS_XTRACE_GET_PUT
139 if (yosys_xtrace)
140 log("#X# GET-BY-INDEX '%s' (index %d, refcount %d)\n", global_id_storage_.at(idx), idx, global_refcount_storage_.at(idx));
141 #endif
142 }
143 return idx;
144 }
145
146 static int get_reference(const char *p)
147 {
148 log_assert(destruct_guard.ok);
149
150 if (!p[0])
151 return 0;
152
153 auto it = global_id_index_.find((char*)p);
154 if (it != global_id_index_.end()) {
155 #ifndef YOSYS_NO_IDS_REFCNT
156 global_refcount_storage_.at(it->second)++;
157 #endif
158 #ifdef YOSYS_XTRACE_GET_PUT
159 if (yosys_xtrace)
160 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));
161 #endif
162 return it->second;
163 }
164
165 log_assert(p[0] == '$' || p[0] == '\\');
166 log_assert(p[1] != 0);
167 for (const char *c = p; *c; c++)
168 log_assert((unsigned)*c > (unsigned)' ');
169
170 #ifndef YOSYS_NO_IDS_REFCNT
171 if (global_free_idx_list_.empty()) {
172 if (global_id_storage_.empty()) {
173 global_refcount_storage_.push_back(0);
174 global_id_storage_.push_back((char*)"");
175 global_id_index_[global_id_storage_.back()] = 0;
176 }
177 log_assert(global_id_storage_.size() < 0x40000000);
178 global_free_idx_list_.push_back(global_id_storage_.size());
179 global_id_storage_.push_back(nullptr);
180 global_refcount_storage_.push_back(0);
181 }
182
183 int idx = global_free_idx_list_.back();
184 global_free_idx_list_.pop_back();
185 global_id_storage_.at(idx) = strdup(p);
186 global_id_index_[global_id_storage_.at(idx)] = idx;
187 global_refcount_storage_.at(idx)++;
188 #else
189 if (global_id_storage_.empty()) {
190 global_id_storage_.push_back((char*)"");
191 global_id_index_[global_id_storage_.back()] = 0;
192 }
193 int idx = global_id_storage_.size();
194 global_id_storage_.push_back(strdup(p));
195 global_id_index_[global_id_storage_.back()] = idx;
196 #endif
197
198 if (yosys_xtrace) {
199 log("#X# New IdString '%s' with index %d.\n", p, idx);
200 log_backtrace("-X- ", yosys_xtrace-1);
201 }
202
203 #ifdef YOSYS_XTRACE_GET_PUT
204 if (yosys_xtrace)
205 log("#X# GET-BY-NAME '%s' (index %d, refcount %d)\n", global_id_storage_.at(idx), idx, global_refcount_storage_.at(idx));
206 #endif
207
208 #ifdef YOSYS_USE_STICKY_IDS
209 // Avoid Create->Delete->Create pattern
210 if (last_created_idx_[last_created_idx_ptr_])
211 put_reference(last_created_idx_[last_created_idx_ptr_]);
212 last_created_idx_[last_created_idx_ptr_] = idx;
213 get_reference(last_created_idx_[last_created_idx_ptr_]);
214 last_created_idx_ptr_ = (last_created_idx_ptr_ + 1) & 7;
215 #endif
216
217 return idx;
218 }
219
220 #ifndef YOSYS_NO_IDS_REFCNT
221 static inline void put_reference(int idx)
222 {
223 // put_reference() may be called from destructors after the destructor of
224 // global_refcount_storage_ has been run. in this case we simply do nothing.
225 if (!destruct_guard.ok || !idx)
226 return;
227
228 #ifdef YOSYS_XTRACE_GET_PUT
229 if (yosys_xtrace) {
230 log("#X# PUT '%s' (index %d, refcount %d)\n", global_id_storage_.at(idx), idx, global_refcount_storage_.at(idx));
231 }
232 #endif
233
234 int &refcount = global_refcount_storage_[idx];
235
236 if (--refcount > 0)
237 return;
238
239 log_assert(refcount == 0);
240 free_reference(idx);
241 }
242 static inline void free_reference(int idx)
243 {
244 if (yosys_xtrace) {
245 log("#X# Removed IdString '%s' with index %d.\n", global_id_storage_.at(idx), idx);
246 log_backtrace("-X- ", yosys_xtrace-1);
247 }
248
249 global_id_index_.erase(global_id_storage_.at(idx));
250 free(global_id_storage_.at(idx));
251 global_id_storage_.at(idx) = nullptr;
252 global_free_idx_list_.push_back(idx);
253 }
254 #else
255 static inline void put_reference(int) { }
256 #endif
257
258 // the actual IdString object is just is a single int
259
260 int index_;
261
262 inline IdString() : index_(0) { }
263 inline IdString(const char *str) : index_(get_reference(str)) { }
264 inline IdString(const IdString &str) : index_(get_reference(str.index_)) { }
265 inline IdString(IdString &&str) : index_(str.index_) { str.index_ = 0; }
266 inline IdString(const std::string &str) : index_(get_reference(str.c_str())) { }
267 inline ~IdString() { put_reference(index_); }
268
269 inline void operator=(const IdString &rhs) {
270 put_reference(index_);
271 index_ = get_reference(rhs.index_);
272 }
273
274 inline void operator=(const char *rhs) {
275 IdString id(rhs);
276 *this = id;
277 }
278
279 inline void operator=(const std::string &rhs) {
280 IdString id(rhs);
281 *this = id;
282 }
283
284 inline const char *c_str() const {
285 return global_id_storage_.at(index_);
286 }
287
288 inline std::string str() const {
289 return std::string(global_id_storage_.at(index_));
290 }
291
292 inline bool operator<(const IdString &rhs) const {
293 return index_ < rhs.index_;
294 }
295
296 inline bool operator==(const IdString &rhs) const { return index_ == rhs.index_; }
297 inline bool operator!=(const IdString &rhs) const { return index_ != rhs.index_; }
298
299 // The methods below are just convenience functions for better compatibility with std::string.
300
301 bool operator==(const std::string &rhs) const { return c_str() == rhs; }
302 bool operator!=(const std::string &rhs) const { return c_str() != rhs; }
303
304 bool operator==(const char *rhs) const { return strcmp(c_str(), rhs) == 0; }
305 bool operator!=(const char *rhs) const { return strcmp(c_str(), rhs) != 0; }
306
307 char operator[](size_t i) const {
308 const char *p = c_str();
309 for (; i != 0; i--, p++)
310 log_assert(*p != 0);
311 return *p;
312 }
313
314 std::string substr(size_t pos = 0, size_t len = std::string::npos) const {
315 if (len == std::string::npos || len >= strlen(c_str() + pos))
316 return std::string(c_str() + pos);
317 else
318 return std::string(c_str() + pos, len);
319 }
320
321 int compare(size_t pos, size_t len, const char* s) const {
322 return strncmp(c_str()+pos, s, len);
323 }
324
325 bool begins_with(const char* prefix) const {
326 size_t len = strlen(prefix);
327 if (size() < len) return false;
328 return compare(0, len, prefix) == 0;
329 }
330
331 bool ends_with(const char* suffix) const {
332 size_t len = strlen(suffix);
333 if (size() < len) return false;
334 return compare(size()-len, len, suffix) == 0;
335 }
336
337 bool contains(const char* str) const {
338 return strstr(c_str(), str);
339 }
340
341 size_t size() const {
342 return strlen(c_str());
343 }
344
345 bool empty() const {
346 return c_str()[0] == 0;
347 }
348
349 void clear() {
350 *this = IdString();
351 }
352
353 unsigned int hash() const {
354 return index_;
355 }
356
357 // The following is a helper key_compare class. Instead of for example std::set<Cell*>
358 // use std::set<Cell*, IdString::compare_ptr_by_name<Cell>> if the order of cells in the
359 // set has an influence on the algorithm.
360
361 template<typename T> struct compare_ptr_by_name {
362 bool operator()(const T *a, const T *b) const {
363 return (a == nullptr || b == nullptr) ? (a < b) : (a->name < b->name);
364 }
365 };
366
367 // often one needs to check if a given IdString is part of a list (for example a list
368 // of cell types). the following functions helps with that.
369
370 template<typename... Args>
371 bool in(Args... args) const {
372 // Credit: https://articles.emptycrate.com/2016/05/14/folds_in_cpp11_ish.html
373 bool result = false;
374 (void) std::initializer_list<int>{ (result = result || in(args), 0)... };
375 return result;
376 }
377
378 bool in(const IdString &rhs) const { return *this == rhs; }
379 bool in(const char *rhs) const { return *this == rhs; }
380 bool in(const std::string &rhs) const { return *this == rhs; }
381 bool in(const pool<IdString> &rhs) const { return rhs.count(*this) != 0; }
382
383 bool isPublic() const { return begins_with("\\"); }
384 };
385
386 namespace ID {
387 #define X(_id) extern IdString _id;
388 #include "kernel/constids.inc"
389 #undef X
390 };
391
392 extern dict<std::string, std::string> constpad;
393
394 const pool<IdString> &builtin_ff_cell_types();
395
396 static inline std::string escape_id(const std::string &str) {
397 if (str.size() > 0 && str[0] != '\\' && str[0] != '$')
398 return "\\" + str;
399 return str;
400 }
401
402 static inline std::string unescape_id(const std::string &str) {
403 if (str.size() < 2)
404 return str;
405 if (str[0] != '\\')
406 return str;
407 if (str[1] == '$' || str[1] == '\\')
408 return str;
409 if (str[1] >= '0' && str[1] <= '9')
410 return str;
411 return str.substr(1);
412 }
413
414 static inline std::string unescape_id(RTLIL::IdString str) {
415 return unescape_id(str.str());
416 }
417
418 static inline const char *id2cstr(RTLIL::IdString str) {
419 return log_id(str);
420 }
421
422 template <typename T> struct sort_by_name_id {
423 bool operator()(T *a, T *b) const {
424 return a->name < b->name;
425 }
426 };
427
428 template <typename T> struct sort_by_name_str {
429 bool operator()(T *a, T *b) const {
430 return strcmp(a->name.c_str(), b->name.c_str()) < 0;
431 }
432 };
433
434 struct sort_by_id_str {
435 bool operator()(RTLIL::IdString a, RTLIL::IdString b) const {
436 return strcmp(a.c_str(), b.c_str()) < 0;
437 }
438 };
439
440 // see calc.cc for the implementation of this functions
441 RTLIL::Const const_not (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
442 RTLIL::Const const_and (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
443 RTLIL::Const const_or (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
444 RTLIL::Const const_xor (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
445 RTLIL::Const const_xnor (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
446
447 RTLIL::Const const_reduce_and (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
448 RTLIL::Const const_reduce_or (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
449 RTLIL::Const const_reduce_xor (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
450 RTLIL::Const const_reduce_xnor (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
451 RTLIL::Const const_reduce_bool (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
452
453 RTLIL::Const const_logic_not (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
454 RTLIL::Const const_logic_and (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
455 RTLIL::Const const_logic_or (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
456
457 RTLIL::Const const_shl (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
458 RTLIL::Const const_shr (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
459 RTLIL::Const const_sshl (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
460 RTLIL::Const const_sshr (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
461 RTLIL::Const const_shift (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
462 RTLIL::Const const_shiftx (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
463
464 RTLIL::Const const_lt (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
465 RTLIL::Const const_le (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
466 RTLIL::Const const_eq (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
467 RTLIL::Const const_ne (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
468 RTLIL::Const const_eqx (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
469 RTLIL::Const const_nex (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
470 RTLIL::Const const_ge (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
471 RTLIL::Const const_gt (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
472
473 RTLIL::Const const_add (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
474 RTLIL::Const const_sub (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
475 RTLIL::Const const_mul (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
476 RTLIL::Const const_div (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
477 RTLIL::Const const_divfloor (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
478 RTLIL::Const const_modfloor (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
479 RTLIL::Const const_mod (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
480 RTLIL::Const const_pow (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
481
482 RTLIL::Const const_pos (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
483 RTLIL::Const const_neg (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
484
485
486 // This iterator-range-pair is used for Design::modules(), Module::wires() and Module::cells().
487 // It maintains a reference counter that is used to make sure that the container is not modified while being iterated over.
488
489 template<typename T>
490 struct ObjIterator {
491 using iterator_category = std::forward_iterator_tag;
492 using value_type = T;
493 using difference_type = ptrdiff_t;
494 using pointer = T*;
495 using reference = T&;
496 typename dict<RTLIL::IdString, T>::iterator it;
497 dict<RTLIL::IdString, T> *list_p;
498 int *refcount_p;
499
500 ObjIterator() : list_p(nullptr), refcount_p(nullptr) {
501 }
502
503 ObjIterator(decltype(list_p) list_p, int *refcount_p) : list_p(list_p), refcount_p(refcount_p) {
504 if (list_p->empty()) {
505 this->list_p = nullptr;
506 this->refcount_p = nullptr;
507 } else {
508 it = list_p->begin();
509 (*refcount_p)++;
510 }
511 }
512
513 ObjIterator(const RTLIL::ObjIterator<T> &other) {
514 it = other.it;
515 list_p = other.list_p;
516 refcount_p = other.refcount_p;
517 if (refcount_p)
518 (*refcount_p)++;
519 }
520
521 ObjIterator &operator=(const RTLIL::ObjIterator<T> &other) {
522 if (refcount_p)
523 (*refcount_p)--;
524 it = other.it;
525 list_p = other.list_p;
526 refcount_p = other.refcount_p;
527 if (refcount_p)
528 (*refcount_p)++;
529 return *this;
530 }
531
532 ~ObjIterator() {
533 if (refcount_p)
534 (*refcount_p)--;
535 }
536
537 inline T operator*() const {
538 log_assert(list_p != nullptr);
539 return it->second;
540 }
541
542 inline bool operator!=(const RTLIL::ObjIterator<T> &other) const {
543 if (list_p == nullptr || other.list_p == nullptr)
544 return list_p != other.list_p;
545 return it != other.it;
546 }
547
548
549 inline bool operator==(const RTLIL::ObjIterator<T> &other) const {
550 return !(*this != other);
551 }
552
553 inline ObjIterator<T>& operator++() {
554 log_assert(list_p != nullptr);
555 if (++it == list_p->end()) {
556 (*refcount_p)--;
557 list_p = nullptr;
558 refcount_p = nullptr;
559 }
560 return *this;
561 }
562
563 inline ObjIterator<T>& operator+=(int amt) {
564 log_assert(list_p != nullptr);
565 it += amt;
566 if (it == list_p->end()) {
567 (*refcount_p)--;
568 list_p = nullptr;
569 refcount_p = nullptr;
570 }
571 return *this;
572 }
573
574 inline ObjIterator<T> operator+(int amt) {
575 log_assert(list_p != nullptr);
576 ObjIterator<T> new_obj(*this);
577 new_obj.it += amt;
578 if (new_obj.it == list_p->end()) {
579 (*(new_obj.refcount_p))--;
580 new_obj.list_p = nullptr;
581 new_obj.refcount_p = nullptr;
582 }
583 return new_obj;
584 }
585
586 inline const ObjIterator<T> operator++(int) {
587 ObjIterator<T> result(*this);
588 ++(*this);
589 return result;
590 }
591 };
592
593 template<typename T>
594 struct ObjRange
595 {
596 dict<RTLIL::IdString, T> *list_p;
597 int *refcount_p;
598
599 ObjRange(decltype(list_p) list_p, int *refcount_p) : list_p(list_p), refcount_p(refcount_p) { }
600 RTLIL::ObjIterator<T> begin() { return RTLIL::ObjIterator<T>(list_p, refcount_p); }
601 RTLIL::ObjIterator<T> end() { return RTLIL::ObjIterator<T>(); }
602
603 size_t size() const {
604 return list_p->size();
605 }
606
607 operator pool<T>() const {
608 pool<T> result;
609 for (auto &it : *list_p)
610 result.insert(it.second);
611 return result;
612 }
613
614 operator std::vector<T>() const {
615 std::vector<T> result;
616 result.reserve(list_p->size());
617 for (auto &it : *list_p)
618 result.push_back(it.second);
619 return result;
620 }
621
622 pool<T> to_pool() const { return *this; }
623 std::vector<T> to_vector() const { return *this; }
624 };
625 };
626
627 struct RTLIL::Const
628 {
629 int flags;
630 std::vector<RTLIL::State> bits;
631
632 Const();
633 Const(std::string str);
634 Const(int val, int width = 32);
635 Const(RTLIL::State bit, int width = 1);
636 Const(const std::vector<RTLIL::State> &bits) : bits(bits) { flags = CONST_FLAG_NONE; }
637 Const(const std::vector<bool> &bits);
638 Const(const RTLIL::Const &c);
639 RTLIL::Const &operator =(const RTLIL::Const &other) = default;
640
641 bool operator <(const RTLIL::Const &other) const;
642 bool operator ==(const RTLIL::Const &other) const;
643 bool operator !=(const RTLIL::Const &other) const;
644
645 bool as_bool() const;
646 int as_int(bool is_signed = false) const;
647 std::string as_string() const;
648 static Const from_string(const std::string &str);
649
650 std::string decode_string() const;
651
652 inline int size() const { return bits.size(); }
653 inline bool empty() const { return bits.empty(); }
654 inline RTLIL::State &operator[](int index) { return bits.at(index); }
655 inline const RTLIL::State &operator[](int index) const { return bits.at(index); }
656 inline decltype(bits)::iterator begin() { return bits.begin(); }
657 inline decltype(bits)::iterator end() { return bits.end(); }
658
659 bool is_fully_zero() const;
660 bool is_fully_ones() const;
661 bool is_fully_def() const;
662 bool is_fully_undef() const;
663
664 inline RTLIL::Const extract(int offset, int len = 1, RTLIL::State padding = RTLIL::State::S0) const {
665 RTLIL::Const ret;
666 ret.bits.reserve(len);
667 for (int i = offset; i < offset + len; i++)
668 ret.bits.push_back(i < GetSize(bits) ? bits[i] : padding);
669 return ret;
670 }
671
672 void extu(int width) {
673 bits.resize(width, RTLIL::State::S0);
674 }
675
676 void exts(int width) {
677 bits.resize(width, bits.empty() ? RTLIL::State::Sx : bits.back());
678 }
679
680 inline unsigned int hash() const {
681 unsigned int h = mkhash_init;
682 for (auto b : bits)
683 mkhash(h, b);
684 return h;
685 }
686 };
687
688 struct RTLIL::AttrObject
689 {
690 dict<RTLIL::IdString, RTLIL::Const> attributes;
691
692 bool has_attribute(RTLIL::IdString id) const;
693
694 void set_bool_attribute(RTLIL::IdString id, bool value=true);
695 bool get_bool_attribute(RTLIL::IdString id) const;
696
697 bool get_blackbox_attribute(bool ignore_wb=false) const {
698 return get_bool_attribute(ID::blackbox) || (!ignore_wb && get_bool_attribute(ID::whitebox));
699 }
700
701 void set_string_attribute(RTLIL::IdString id, string value);
702 string get_string_attribute(RTLIL::IdString id) const;
703
704 void set_strpool_attribute(RTLIL::IdString id, const pool<string> &data);
705 void add_strpool_attribute(RTLIL::IdString id, const pool<string> &data);
706 pool<string> get_strpool_attribute(RTLIL::IdString id) const;
707
708 void set_src_attribute(const std::string &src) {
709 set_string_attribute(ID::src, src);
710 }
711 std::string get_src_attribute() const {
712 return get_string_attribute(ID::src);
713 }
714
715 void set_hdlname_attribute(const vector<string> &hierarchy);
716 vector<string> get_hdlname_attribute() const;
717 };
718
719 struct RTLIL::SigChunk
720 {
721 RTLIL::Wire *wire;
722 std::vector<RTLIL::State> data; // only used if wire == NULL, LSB at index 0
723 int width, offset;
724
725 SigChunk();
726 SigChunk(const RTLIL::Const &value);
727 SigChunk(RTLIL::Wire *wire);
728 SigChunk(RTLIL::Wire *wire, int offset, int width = 1);
729 SigChunk(const std::string &str);
730 SigChunk(int val, int width = 32);
731 SigChunk(RTLIL::State bit, int width = 1);
732 SigChunk(const RTLIL::SigBit &bit);
733 SigChunk(const RTLIL::SigChunk &sigchunk);
734 RTLIL::SigChunk &operator =(const RTLIL::SigChunk &other) = default;
735
736 RTLIL::SigChunk extract(int offset, int length) const;
737 inline int size() const { return width; }
738
739 bool operator <(const RTLIL::SigChunk &other) const;
740 bool operator ==(const RTLIL::SigChunk &other) const;
741 bool operator !=(const RTLIL::SigChunk &other) const;
742 };
743
744 struct RTLIL::SigBit
745 {
746 RTLIL::Wire *wire;
747 union {
748 RTLIL::State data; // used if wire == NULL
749 int offset; // used if wire != NULL
750 };
751
752 SigBit();
753 SigBit(RTLIL::State bit);
754 SigBit(bool bit);
755 SigBit(RTLIL::Wire *wire);
756 SigBit(RTLIL::Wire *wire, int offset);
757 SigBit(const RTLIL::SigChunk &chunk);
758 SigBit(const RTLIL::SigChunk &chunk, int index);
759 SigBit(const RTLIL::SigSpec &sig);
760 SigBit(const RTLIL::SigBit &sigbit) = default;
761 RTLIL::SigBit &operator =(const RTLIL::SigBit &other) = default;
762
763 bool operator <(const RTLIL::SigBit &other) const;
764 bool operator ==(const RTLIL::SigBit &other) const;
765 bool operator !=(const RTLIL::SigBit &other) const;
766 unsigned int hash() const;
767 };
768
769 struct RTLIL::SigSpecIterator : public std::iterator<std::input_iterator_tag, RTLIL::SigSpec>
770 {
771 RTLIL::SigSpec *sig_p;
772 int index;
773
774 inline RTLIL::SigBit &operator*() const;
775 inline bool operator!=(const RTLIL::SigSpecIterator &other) const { return index != other.index; }
776 inline bool operator==(const RTLIL::SigSpecIterator &other) const { return index == other.index; }
777 inline void operator++() { index++; }
778 };
779
780 struct RTLIL::SigSpecConstIterator : public std::iterator<std::input_iterator_tag, RTLIL::SigSpec>
781 {
782 const RTLIL::SigSpec *sig_p;
783 int index;
784
785 inline const RTLIL::SigBit &operator*() const;
786 inline bool operator!=(const RTLIL::SigSpecConstIterator &other) const { return index != other.index; }
787 inline bool operator==(const RTLIL::SigSpecIterator &other) const { return index == other.index; }
788 inline void operator++() { index++; }
789 };
790
791 struct RTLIL::SigSpec
792 {
793 private:
794 int width_;
795 unsigned long hash_;
796 std::vector<RTLIL::SigChunk> chunks_; // LSB at index 0
797 std::vector<RTLIL::SigBit> bits_; // LSB at index 0
798
799 void pack() const;
800 void unpack() const;
801 void updhash() const;
802
803 inline bool packed() const {
804 return bits_.empty();
805 }
806
807 inline void inline_unpack() const {
808 if (!chunks_.empty())
809 unpack();
810 }
811
812 // Only used by Module::remove(const pool<Wire*> &wires)
813 // but cannot be more specific as it isn't yet declared
814 friend struct RTLIL::Module;
815
816 public:
817 SigSpec();
818 SigSpec(const RTLIL::SigSpec &other);
819 SigSpec(std::initializer_list<RTLIL::SigSpec> parts);
820 RTLIL::SigSpec &operator=(const RTLIL::SigSpec &other);
821
822 SigSpec(const RTLIL::Const &value);
823 SigSpec(const RTLIL::SigChunk &chunk);
824 SigSpec(RTLIL::Wire *wire);
825 SigSpec(RTLIL::Wire *wire, int offset, int width = 1);
826 SigSpec(const std::string &str);
827 SigSpec(int val, int width = 32);
828 SigSpec(RTLIL::State bit, int width = 1);
829 SigSpec(const RTLIL::SigBit &bit, int width = 1);
830 SigSpec(const std::vector<RTLIL::SigChunk> &chunks);
831 SigSpec(const std::vector<RTLIL::SigBit> &bits);
832 SigSpec(const pool<RTLIL::SigBit> &bits);
833 SigSpec(const std::set<RTLIL::SigBit> &bits);
834 SigSpec(bool bit);
835
836 SigSpec(RTLIL::SigSpec &&other) {
837 width_ = other.width_;
838 hash_ = other.hash_;
839 chunks_ = std::move(other.chunks_);
840 bits_ = std::move(other.bits_);
841 }
842
843 const RTLIL::SigSpec &operator=(RTLIL::SigSpec &&other) {
844 width_ = other.width_;
845 hash_ = other.hash_;
846 chunks_ = std::move(other.chunks_);
847 bits_ = std::move(other.bits_);
848 return *this;
849 }
850
851 size_t get_hash() const {
852 if (!hash_) hash();
853 return hash_;
854 }
855
856 inline const std::vector<RTLIL::SigChunk> &chunks() const { pack(); return chunks_; }
857 inline const std::vector<RTLIL::SigBit> &bits() const { inline_unpack(); return bits_; }
858
859 inline int size() const { return width_; }
860 inline bool empty() const { return width_ == 0; }
861
862 inline RTLIL::SigBit &operator[](int index) { inline_unpack(); return bits_.at(index); }
863 inline const RTLIL::SigBit &operator[](int index) const { inline_unpack(); return bits_.at(index); }
864
865 inline RTLIL::SigSpecIterator begin() { RTLIL::SigSpecIterator it; it.sig_p = this; it.index = 0; return it; }
866 inline RTLIL::SigSpecIterator end() { RTLIL::SigSpecIterator it; it.sig_p = this; it.index = width_; return it; }
867
868 inline RTLIL::SigSpecConstIterator begin() const { RTLIL::SigSpecConstIterator it; it.sig_p = this; it.index = 0; return it; }
869 inline RTLIL::SigSpecConstIterator end() const { RTLIL::SigSpecConstIterator it; it.sig_p = this; it.index = width_; return it; }
870
871 void sort();
872 void sort_and_unify();
873
874 void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with);
875 void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with, RTLIL::SigSpec *other) const;
876
877 void replace(const dict<RTLIL::SigBit, RTLIL::SigBit> &rules);
878 void replace(const dict<RTLIL::SigBit, RTLIL::SigBit> &rules, RTLIL::SigSpec *other) const;
879
880 void replace(const std::map<RTLIL::SigBit, RTLIL::SigBit> &rules);
881 void replace(const std::map<RTLIL::SigBit, RTLIL::SigBit> &rules, RTLIL::SigSpec *other) const;
882
883 void replace(int offset, const RTLIL::SigSpec &with);
884
885 void remove(const RTLIL::SigSpec &pattern);
886 void remove(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other) const;
887 void remove2(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other);
888
889 void remove(const pool<RTLIL::SigBit> &pattern);
890 void remove(const pool<RTLIL::SigBit> &pattern, RTLIL::SigSpec *other) const;
891 void remove2(const pool<RTLIL::SigBit> &pattern, RTLIL::SigSpec *other);
892 void remove2(const std::set<RTLIL::SigBit> &pattern, RTLIL::SigSpec *other);
893
894 void remove(int offset, int length = 1);
895 void remove_const();
896
897 RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other = NULL) const;
898 RTLIL::SigSpec extract(const pool<RTLIL::SigBit> &pattern, const RTLIL::SigSpec *other = NULL) const;
899 RTLIL::SigSpec extract(int offset, int length = 1) const;
900 RTLIL::SigSpec extract_end(int offset) const { return extract(offset, width_ - offset); }
901
902 void append(const RTLIL::SigSpec &signal);
903 inline void append(Wire *wire) { append(RTLIL::SigSpec(wire)); }
904 inline void append(const RTLIL::SigChunk &chunk) { append(RTLIL::SigSpec(chunk)); }
905 inline void append(const RTLIL::Const &const_) { append(RTLIL::SigSpec(const_)); }
906
907 void append(const RTLIL::SigBit &bit);
908 inline void append(RTLIL::State state) { append(RTLIL::SigBit(state)); }
909 inline void append(bool bool_) { append(RTLIL::SigBit(bool_)); }
910
911 void extend_u0(int width, bool is_signed = false);
912
913 RTLIL::SigSpec repeat(int num) const;
914
915 void reverse() { inline_unpack(); std::reverse(bits_.begin(), bits_.end()); }
916
917 bool operator <(const RTLIL::SigSpec &other) const;
918 bool operator ==(const RTLIL::SigSpec &other) const;
919 inline bool operator !=(const RTLIL::SigSpec &other) const { return !(*this == other); }
920
921 bool is_wire() const;
922 bool is_chunk() const;
923 inline bool is_bit() const { return width_ == 1; }
924
925 bool is_fully_const() const;
926 bool is_fully_zero() const;
927 bool is_fully_ones() const;
928 bool is_fully_def() const;
929 bool is_fully_undef() const;
930 bool has_const() const;
931 bool has_marked_bits() const;
932
933 bool as_bool() const;
934 int as_int(bool is_signed = false) const;
935 std::string as_string() const;
936 RTLIL::Const as_const() const;
937 RTLIL::Wire *as_wire() const;
938 RTLIL::SigChunk as_chunk() const;
939 RTLIL::SigBit as_bit() const;
940
941 bool match(const char* pattern) const;
942
943 std::set<RTLIL::SigBit> to_sigbit_set() const;
944 pool<RTLIL::SigBit> to_sigbit_pool() const;
945 std::vector<RTLIL::SigBit> to_sigbit_vector() const;
946 std::map<RTLIL::SigBit, RTLIL::SigBit> to_sigbit_map(const RTLIL::SigSpec &other) const;
947 dict<RTLIL::SigBit, RTLIL::SigBit> to_sigbit_dict(const RTLIL::SigSpec &other) const;
948
949 static bool parse(RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str);
950 static bool parse_sel(RTLIL::SigSpec &sig, RTLIL::Design *design, RTLIL::Module *module, std::string str);
951 static bool parse_rhs(const RTLIL::SigSpec &lhs, RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str);
952
953 operator std::vector<RTLIL::SigChunk>() const { return chunks(); }
954 operator std::vector<RTLIL::SigBit>() const { return bits(); }
955 const RTLIL::SigBit &at(int offset, const RTLIL::SigBit &defval) { return offset < width_ ? (*this)[offset] : defval; }
956
957 unsigned int hash() const { if (!hash_) updhash(); return hash_; };
958
959 #ifndef NDEBUG
960 void check() const;
961 #else
962 void check() const { }
963 #endif
964 };
965
966 struct RTLIL::Selection
967 {
968 bool full_selection;
969 pool<RTLIL::IdString> selected_modules;
970 dict<RTLIL::IdString, pool<RTLIL::IdString>> selected_members;
971
972 Selection(bool full = true) : full_selection(full) { }
973
974 bool selected_module(RTLIL::IdString mod_name) const;
975 bool selected_whole_module(RTLIL::IdString mod_name) const;
976 bool selected_member(RTLIL::IdString mod_name, RTLIL::IdString memb_name) const;
977 void optimize(RTLIL::Design *design);
978
979 template<typename T1> void select(T1 *module) {
980 if (!full_selection && selected_modules.count(module->name) == 0) {
981 selected_modules.insert(module->name);
982 selected_members.erase(module->name);
983 }
984 }
985
986 template<typename T1, typename T2> void select(T1 *module, T2 *member) {
987 if (!full_selection && selected_modules.count(module->name) == 0)
988 selected_members[module->name].insert(member->name);
989 }
990
991 bool empty() const {
992 return !full_selection && selected_modules.empty() && selected_members.empty();
993 }
994 };
995
996 struct RTLIL::Monitor
997 {
998 unsigned int hashidx_;
999 unsigned int hash() const { return hashidx_; }
1000
1001 Monitor() {
1002 static unsigned int hashidx_count = 123456789;
1003 hashidx_count = mkhash_xorshift(hashidx_count);
1004 hashidx_ = hashidx_count;
1005 }
1006
1007 virtual ~Monitor() { }
1008 virtual void notify_module_add(RTLIL::Module*) { }
1009 virtual void notify_module_del(RTLIL::Module*) { }
1010 virtual void notify_connect(RTLIL::Cell*, const RTLIL::IdString&, const RTLIL::SigSpec&, const RTLIL::SigSpec&) { }
1011 virtual void notify_connect(RTLIL::Module*, const RTLIL::SigSig&) { }
1012 virtual void notify_connect(RTLIL::Module*, const std::vector<RTLIL::SigSig>&) { }
1013 virtual void notify_blackout(RTLIL::Module*) { }
1014 };
1015
1016 // Forward declaration; defined in preproc.h.
1017 struct define_map_t;
1018
1019 struct RTLIL::Design
1020 {
1021 unsigned int hashidx_;
1022 unsigned int hash() const { return hashidx_; }
1023
1024 pool<RTLIL::Monitor*> monitors;
1025 dict<std::string, std::string> scratchpad;
1026
1027 int refcount_modules_;
1028 dict<RTLIL::IdString, RTLIL::Module*> modules_;
1029 std::vector<AST::AstNode*> verilog_packages, verilog_globals;
1030 std::unique_ptr<define_map_t> verilog_defines;
1031
1032 std::vector<RTLIL::Selection> selection_stack;
1033 dict<RTLIL::IdString, RTLIL::Selection> selection_vars;
1034 std::string selected_active_module;
1035
1036 Design();
1037 ~Design();
1038
1039 RTLIL::ObjRange<RTLIL::Module*> modules();
1040 RTLIL::Module *module(RTLIL::IdString name);
1041 RTLIL::Module *top_module();
1042
1043 bool has(RTLIL::IdString id) const {
1044 return modules_.count(id) != 0;
1045 }
1046
1047 void add(RTLIL::Module *module);
1048 RTLIL::Module *addModule(RTLIL::IdString name);
1049 void remove(RTLIL::Module *module);
1050 void rename(RTLIL::Module *module, RTLIL::IdString new_name);
1051
1052 void scratchpad_unset(const std::string &varname);
1053
1054 void scratchpad_set_int(const std::string &varname, int value);
1055 void scratchpad_set_bool(const std::string &varname, bool value);
1056 void scratchpad_set_string(const std::string &varname, std::string value);
1057
1058 int scratchpad_get_int(const std::string &varname, int default_value = 0) const;
1059 bool scratchpad_get_bool(const std::string &varname, bool default_value = false) const;
1060 std::string scratchpad_get_string(const std::string &varname, const std::string &default_value = std::string()) const;
1061
1062 void sort();
1063 void check();
1064 void optimize();
1065
1066 bool selected_module(RTLIL::IdString mod_name) const;
1067 bool selected_whole_module(RTLIL::IdString mod_name) const;
1068 bool selected_member(RTLIL::IdString mod_name, RTLIL::IdString memb_name) const;
1069
1070 bool selected_module(RTLIL::Module *mod) const;
1071 bool selected_whole_module(RTLIL::Module *mod) const;
1072
1073 RTLIL::Selection &selection() {
1074 return selection_stack.back();
1075 }
1076
1077 const RTLIL::Selection &selection() const {
1078 return selection_stack.back();
1079 }
1080
1081 bool full_selection() const {
1082 return selection_stack.back().full_selection;
1083 }
1084
1085 template<typename T1> bool selected(T1 *module) const {
1086 return selected_module(module->name);
1087 }
1088
1089 template<typename T1, typename T2> bool selected(T1 *module, T2 *member) const {
1090 return selected_member(module->name, member->name);
1091 }
1092
1093 template<typename T1> void select(T1 *module) {
1094 if (selection_stack.size() > 0) {
1095 RTLIL::Selection &sel = selection_stack.back();
1096 sel.select(module);
1097 }
1098 }
1099
1100 template<typename T1, typename T2> void select(T1 *module, T2 *member) {
1101 if (selection_stack.size() > 0) {
1102 RTLIL::Selection &sel = selection_stack.back();
1103 sel.select(module, member);
1104 }
1105 }
1106
1107
1108 std::vector<RTLIL::Module*> selected_modules() const;
1109 std::vector<RTLIL::Module*> selected_whole_modules() const;
1110 std::vector<RTLIL::Module*> selected_whole_modules_warn() const;
1111 #ifdef WITH_PYTHON
1112 static std::map<unsigned int, RTLIL::Design*> *get_all_designs(void);
1113 #endif
1114 };
1115
1116 struct RTLIL::Module : public RTLIL::AttrObject
1117 {
1118 unsigned int hashidx_;
1119 unsigned int hash() const { return hashidx_; }
1120
1121 protected:
1122 void add(RTLIL::Wire *wire);
1123 void add(RTLIL::Cell *cell);
1124
1125 public:
1126 RTLIL::Design *design;
1127 pool<RTLIL::Monitor*> monitors;
1128
1129 int refcount_wires_;
1130 int refcount_cells_;
1131
1132 dict<RTLIL::IdString, RTLIL::Wire*> wires_;
1133 dict<RTLIL::IdString, RTLIL::Cell*> cells_;
1134 std::vector<RTLIL::SigSig> connections_;
1135
1136 RTLIL::IdString name;
1137 idict<RTLIL::IdString> avail_parameters;
1138 dict<RTLIL::IdString, RTLIL::Const> parameter_default_values;
1139 dict<RTLIL::IdString, RTLIL::Memory*> memories;
1140 dict<RTLIL::IdString, RTLIL::Process*> processes;
1141
1142 Module();
1143 virtual ~Module();
1144 virtual RTLIL::IdString derive(RTLIL::Design *design, const dict<RTLIL::IdString, RTLIL::Const> &parameters, bool mayfail = false);
1145 virtual RTLIL::IdString derive(RTLIL::Design *design, const dict<RTLIL::IdString, RTLIL::Const> &parameters, const dict<RTLIL::IdString, RTLIL::Module*> &interfaces, const dict<RTLIL::IdString, RTLIL::IdString> &modports, bool mayfail = false);
1146 virtual size_t count_id(RTLIL::IdString id);
1147 virtual void reprocess_module(RTLIL::Design *design, const dict<RTLIL::IdString, RTLIL::Module *> &local_interfaces);
1148
1149 virtual void sort();
1150 virtual void check();
1151 virtual void optimize();
1152 virtual void makeblackbox();
1153
1154 void connect(const RTLIL::SigSig &conn);
1155 void connect(const RTLIL::SigSpec &lhs, const RTLIL::SigSpec &rhs);
1156 void new_connections(const std::vector<RTLIL::SigSig> &new_conn);
1157 const std::vector<RTLIL::SigSig> &connections() const;
1158
1159 std::vector<RTLIL::IdString> ports;
1160 void fixup_ports();
1161
1162 template<typename T> void rewrite_sigspecs(T &functor);
1163 template<typename T> void rewrite_sigspecs2(T &functor);
1164 void cloneInto(RTLIL::Module *new_mod) const;
1165 virtual RTLIL::Module *clone() const;
1166
1167 bool has_memories() const;
1168 bool has_processes() const;
1169
1170 bool has_memories_warn() const;
1171 bool has_processes_warn() const;
1172
1173 std::vector<RTLIL::Wire*> selected_wires() const;
1174 std::vector<RTLIL::Cell*> selected_cells() const;
1175
1176 template<typename T> bool selected(T *member) const {
1177 return design->selected_member(name, member->name);
1178 }
1179
1180 RTLIL::Wire* wire(RTLIL::IdString id) {
1181 auto it = wires_.find(id);
1182 return it == wires_.end() ? nullptr : it->second;
1183 }
1184 RTLIL::Cell* cell(RTLIL::IdString id) {
1185 auto it = cells_.find(id);
1186 return it == cells_.end() ? nullptr : it->second;
1187 }
1188
1189 RTLIL::ObjRange<RTLIL::Wire*> wires() { return RTLIL::ObjRange<RTLIL::Wire*>(&wires_, &refcount_wires_); }
1190 RTLIL::ObjRange<RTLIL::Cell*> cells() { return RTLIL::ObjRange<RTLIL::Cell*>(&cells_, &refcount_cells_); }
1191
1192 // Removing wires is expensive. If you have to remove wires, remove them all at once.
1193 void remove(const pool<RTLIL::Wire*> &wires);
1194 void remove(RTLIL::Cell *cell);
1195
1196 void rename(RTLIL::Wire *wire, RTLIL::IdString new_name);
1197 void rename(RTLIL::Cell *cell, RTLIL::IdString new_name);
1198 void rename(RTLIL::IdString old_name, RTLIL::IdString new_name);
1199
1200 void swap_names(RTLIL::Wire *w1, RTLIL::Wire *w2);
1201 void swap_names(RTLIL::Cell *c1, RTLIL::Cell *c2);
1202
1203 RTLIL::IdString uniquify(RTLIL::IdString name);
1204 RTLIL::IdString uniquify(RTLIL::IdString name, int &index);
1205
1206 RTLIL::Wire *addWire(RTLIL::IdString name, int width = 1);
1207 RTLIL::Wire *addWire(RTLIL::IdString name, const RTLIL::Wire *other);
1208
1209 RTLIL::Cell *addCell(RTLIL::IdString name, RTLIL::IdString type);
1210 RTLIL::Cell *addCell(RTLIL::IdString name, const RTLIL::Cell *other);
1211
1212 RTLIL::Memory *addMemory(RTLIL::IdString name, const RTLIL::Memory *other);
1213
1214 RTLIL::Process *addProcess(RTLIL::IdString name, const RTLIL::Process *other);
1215
1216 // The add* methods create a cell and return the created cell. All signals must exist in advance.
1217
1218 RTLIL::Cell* addNot (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1219 RTLIL::Cell* addPos (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1220 RTLIL::Cell* addNeg (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1221
1222 RTLIL::Cell* addAnd (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1223 RTLIL::Cell* addOr (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1224 RTLIL::Cell* addXor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1225 RTLIL::Cell* addXnor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1226
1227 RTLIL::Cell* addReduceAnd (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1228 RTLIL::Cell* addReduceOr (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1229 RTLIL::Cell* addReduceXor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1230 RTLIL::Cell* addReduceXnor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1231 RTLIL::Cell* addReduceBool (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1232
1233 RTLIL::Cell* addShl (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1234 RTLIL::Cell* addShr (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1235 RTLIL::Cell* addSshl (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1236 RTLIL::Cell* addSshr (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1237 RTLIL::Cell* addShift (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1238 RTLIL::Cell* addShiftx (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1239
1240 RTLIL::Cell* addLt (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1241 RTLIL::Cell* addLe (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1242 RTLIL::Cell* addEq (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1243 RTLIL::Cell* addNe (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1244 RTLIL::Cell* addEqx (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1245 RTLIL::Cell* addNex (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1246 RTLIL::Cell* addGe (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1247 RTLIL::Cell* addGt (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1248
1249 RTLIL::Cell* addAdd (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1250 RTLIL::Cell* addSub (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1251 RTLIL::Cell* addMul (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1252 // truncating division
1253 RTLIL::Cell* addDiv (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1254 // truncating modulo
1255 RTLIL::Cell* addMod (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1256 RTLIL::Cell* addDivFloor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1257 RTLIL::Cell* addModFloor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1258 RTLIL::Cell* addPow (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool a_signed = false, bool b_signed = false, const std::string &src = "");
1259
1260 RTLIL::Cell* addLogicNot (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1261 RTLIL::Cell* addLogicAnd (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1262 RTLIL::Cell* addLogicOr (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1263
1264 RTLIL::Cell* addMux (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_s, const RTLIL::SigSpec &sig_y, const std::string &src = "");
1265 RTLIL::Cell* addPmux (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_s, const RTLIL::SigSpec &sig_y, const std::string &src = "");
1266
1267 RTLIL::Cell* addSlice (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, RTLIL::Const offset, const std::string &src = "");
1268 RTLIL::Cell* addConcat (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, const std::string &src = "");
1269 RTLIL::Cell* addLut (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, RTLIL::Const lut, const std::string &src = "");
1270 RTLIL::Cell* addTribuf (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_y, const std::string &src = "");
1271 RTLIL::Cell* addAssert (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_en, const std::string &src = "");
1272 RTLIL::Cell* addAssume (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_en, const std::string &src = "");
1273 RTLIL::Cell* addLive (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_en, const std::string &src = "");
1274 RTLIL::Cell* addFair (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_en, const std::string &src = "");
1275 RTLIL::Cell* addCover (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_en, const std::string &src = "");
1276 RTLIL::Cell* addEquiv (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, const std::string &src = "");
1277
1278 RTLIL::Cell* addSr (RTLIL::IdString name, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr, const RTLIL::SigSpec &sig_q, bool set_polarity = true, bool clr_polarity = true, const std::string &src = "");
1279 RTLIL::Cell* addFf (RTLIL::IdString name, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, const std::string &src = "");
1280 RTLIL::Cell* addDff (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, bool clk_polarity = true, const std::string &src = "");
1281 RTLIL::Cell* addDffe (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, bool clk_polarity = true, bool en_polarity = true, const std::string &src = "");
1282 RTLIL::Cell* addDffsr (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr, RTLIL::SigSpec sig_d, const RTLIL::SigSpec &sig_q, bool clk_polarity = true, bool set_polarity = true, bool clr_polarity = true, const std::string &src = "");
1283 RTLIL::Cell* addDffsre (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr, RTLIL::SigSpec sig_d, const RTLIL::SigSpec &sig_q, bool clk_polarity = true, bool en_polarity = true, bool set_polarity = true, bool clr_polarity = true, const std::string &src = "");
1284 RTLIL::Cell* addAdff (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_arst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, RTLIL::Const arst_value, bool clk_polarity = true, bool arst_polarity = true, const std::string &src = "");
1285 RTLIL::Cell* addAdffe (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_arst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, RTLIL::Const arst_value, bool clk_polarity = true, bool en_polarity = true, bool arst_polarity = true, const std::string &src = "");
1286 RTLIL::Cell* addSdff (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_srst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, RTLIL::Const srst_value, bool clk_polarity = true, bool srst_polarity = true, const std::string &src = "");
1287 RTLIL::Cell* addSdffe (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_srst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, RTLIL::Const srst_value, bool clk_polarity = true, bool en_polarity = true, bool srst_polarity = true, const std::string &src = "");
1288 RTLIL::Cell* addSdffce (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_srst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, RTLIL::Const srst_value, bool clk_polarity = true, bool en_polarity = true, bool srst_polarity = true, const std::string &src = "");
1289 RTLIL::Cell* addDlatch (RTLIL::IdString name, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, bool en_polarity = true, const std::string &src = "");
1290 RTLIL::Cell* addAdlatch (RTLIL::IdString name, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_arst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, RTLIL::Const arst_value, bool en_polarity = true, bool arst_polarity = true, const std::string &src = "");
1291 RTLIL::Cell* addDlatchsr (RTLIL::IdString name, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr, RTLIL::SigSpec sig_d, const RTLIL::SigSpec &sig_q, bool en_polarity = true, bool set_polarity = true, bool clr_polarity = true, const std::string &src = "");
1292
1293 RTLIL::Cell* addBufGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_y, const std::string &src = "");
1294 RTLIL::Cell* addNotGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_y, const std::string &src = "");
1295 RTLIL::Cell* addAndGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_y, const std::string &src = "");
1296 RTLIL::Cell* addNandGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_y, const std::string &src = "");
1297 RTLIL::Cell* addOrGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_y, const std::string &src = "");
1298 RTLIL::Cell* addNorGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_y, const std::string &src = "");
1299 RTLIL::Cell* addXorGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_y, const std::string &src = "");
1300 RTLIL::Cell* addXnorGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_y, const std::string &src = "");
1301 RTLIL::Cell* addAndnotGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_y, const std::string &src = "");
1302 RTLIL::Cell* addOrnotGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_y, const std::string &src = "");
1303 RTLIL::Cell* addMuxGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_s, const RTLIL::SigBit &sig_y, const std::string &src = "");
1304 RTLIL::Cell* addNmuxGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_s, const RTLIL::SigBit &sig_y, const std::string &src = "");
1305 RTLIL::Cell* addAoi3Gate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_c, const RTLIL::SigBit &sig_y, const std::string &src = "");
1306 RTLIL::Cell* addOai3Gate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_c, const RTLIL::SigBit &sig_y, const std::string &src = "");
1307 RTLIL::Cell* addAoi4Gate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_c, const RTLIL::SigBit &sig_d, const RTLIL::SigBit &sig_y, const std::string &src = "");
1308 RTLIL::Cell* addOai4Gate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_c, const RTLIL::SigBit &sig_d, const RTLIL::SigBit &sig_y, const std::string &src = "");
1309
1310 RTLIL::Cell* addSrGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr,
1311 const RTLIL::SigSpec &sig_q, bool set_polarity = true, bool clr_polarity = true, const std::string &src = "");
1312 RTLIL::Cell* addFfGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, const std::string &src = "");
1313 RTLIL::Cell* addDffGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, bool clk_polarity = true, const std::string &src = "");
1314 RTLIL::Cell* addDffeGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, bool clk_polarity = true, bool en_polarity = true, const std::string &src = "");
1315 RTLIL::Cell* addDffsrGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr,
1316 RTLIL::SigSpec sig_d, const RTLIL::SigSpec &sig_q, bool clk_polarity = true, bool set_polarity = true, bool clr_polarity = true, const std::string &src = "");
1317 RTLIL::Cell* addDffsreGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr,
1318 RTLIL::SigSpec sig_d, const RTLIL::SigSpec &sig_q, bool clk_polarity = true, bool en_polarity = true, bool set_polarity = true, bool clr_polarity = true, const std::string &src = "");
1319 RTLIL::Cell* addAdffGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_arst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q,
1320 bool arst_value = false, bool clk_polarity = true, bool arst_polarity = true, const std::string &src = "");
1321 RTLIL::Cell* addAdffeGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_arst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q,
1322 bool arst_value = false, bool clk_polarity = true, bool en_polarity = true, bool arst_polarity = true, const std::string &src = "");
1323 RTLIL::Cell* addSdffGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_srst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q,
1324 bool srst_value = false, bool clk_polarity = true, bool srst_polarity = true, const std::string &src = "");
1325 RTLIL::Cell* addSdffeGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_srst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q,
1326 bool srst_value = false, bool clk_polarity = true, bool en_polarity = true, bool srst_polarity = true, const std::string &src = "");
1327 RTLIL::Cell* addSdffceGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_srst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q,
1328 bool srst_value = false, bool clk_polarity = true, bool en_polarity = true, bool srst_polarity = true, const std::string &src = "");
1329 RTLIL::Cell* addDlatchGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, bool en_polarity = true, const std::string &src = "");
1330 RTLIL::Cell* addAdlatchGate(RTLIL::IdString name, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_arst, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q,
1331 bool arst_value = false, bool en_polarity = true, bool arst_polarity = true, const std::string &src = "");
1332 RTLIL::Cell* addDlatchsrGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr,
1333 RTLIL::SigSpec sig_d, const RTLIL::SigSpec &sig_q, bool en_polarity = true, bool set_polarity = true, bool clr_polarity = true, const std::string &src = "");
1334
1335 // The methods without the add* prefix create a cell and an output signal. They return the newly created output signal.
1336
1337 RTLIL::SigSpec Not (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1338 RTLIL::SigSpec Pos (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1339 RTLIL::SigSpec Bu0 (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1340 RTLIL::SigSpec Neg (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1341
1342 RTLIL::SigSpec And (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1343 RTLIL::SigSpec Or (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1344 RTLIL::SigSpec Xor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1345 RTLIL::SigSpec Xnor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1346
1347 RTLIL::SigSpec ReduceAnd (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1348 RTLIL::SigSpec ReduceOr (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1349 RTLIL::SigSpec ReduceXor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1350 RTLIL::SigSpec ReduceXnor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1351 RTLIL::SigSpec ReduceBool (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1352
1353 RTLIL::SigSpec Shl (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1354 RTLIL::SigSpec Shr (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1355 RTLIL::SigSpec Sshl (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1356 RTLIL::SigSpec Sshr (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1357 RTLIL::SigSpec Shift (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1358 RTLIL::SigSpec Shiftx (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1359
1360 RTLIL::SigSpec Lt (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1361 RTLIL::SigSpec Le (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1362 RTLIL::SigSpec Eq (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1363 RTLIL::SigSpec Ne (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1364 RTLIL::SigSpec Eqx (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1365 RTLIL::SigSpec Nex (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1366 RTLIL::SigSpec Ge (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1367 RTLIL::SigSpec Gt (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1368
1369 RTLIL::SigSpec Add (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1370 RTLIL::SigSpec Sub (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1371 RTLIL::SigSpec Mul (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1372 // truncating division
1373 RTLIL::SigSpec Div (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1374 // truncating modulo
1375 RTLIL::SigSpec Mod (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1376 RTLIL::SigSpec DivFloor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1377 RTLIL::SigSpec ModFloor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1378 RTLIL::SigSpec Pow (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool a_signed = false, bool b_signed = false, const std::string &src = "");
1379
1380 RTLIL::SigSpec LogicNot (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1381 RTLIL::SigSpec LogicAnd (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1382 RTLIL::SigSpec LogicOr (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1383
1384 RTLIL::SigSpec Mux (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_s, const std::string &src = "");
1385 RTLIL::SigSpec Pmux (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_s, const std::string &src = "");
1386
1387 RTLIL::SigBit BufGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const std::string &src = "");
1388 RTLIL::SigBit NotGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const std::string &src = "");
1389 RTLIL::SigBit AndGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const std::string &src = "");
1390 RTLIL::SigBit NandGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const std::string &src = "");
1391 RTLIL::SigBit OrGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const std::string &src = "");
1392 RTLIL::SigBit NorGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const std::string &src = "");
1393 RTLIL::SigBit XorGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const std::string &src = "");
1394 RTLIL::SigBit XnorGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const std::string &src = "");
1395 RTLIL::SigBit AndnotGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const std::string &src = "");
1396 RTLIL::SigBit OrnotGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const std::string &src = "");
1397 RTLIL::SigBit MuxGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_s, const std::string &src = "");
1398 RTLIL::SigBit NmuxGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_s, const std::string &src = "");
1399 RTLIL::SigBit Aoi3Gate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_c, const std::string &src = "");
1400 RTLIL::SigBit Oai3Gate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_c, const std::string &src = "");
1401 RTLIL::SigBit Aoi4Gate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_c, const RTLIL::SigBit &sig_d, const std::string &src = "");
1402 RTLIL::SigBit Oai4Gate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const RTLIL::SigBit &sig_c, const RTLIL::SigBit &sig_d, const std::string &src = "");
1403
1404 RTLIL::SigSpec Anyconst (RTLIL::IdString name, int width = 1, const std::string &src = "");
1405 RTLIL::SigSpec Anyseq (RTLIL::IdString name, int width = 1, const std::string &src = "");
1406 RTLIL::SigSpec Allconst (RTLIL::IdString name, int width = 1, const std::string &src = "");
1407 RTLIL::SigSpec Allseq (RTLIL::IdString name, int width = 1, const std::string &src = "");
1408 RTLIL::SigSpec Initstate (RTLIL::IdString name, const std::string &src = "");
1409
1410 #ifdef WITH_PYTHON
1411 static std::map<unsigned int, RTLIL::Module*> *get_all_modules(void);
1412 #endif
1413 };
1414
1415 struct RTLIL::Wire : public RTLIL::AttrObject
1416 {
1417 unsigned int hashidx_;
1418 unsigned int hash() const { return hashidx_; }
1419
1420 protected:
1421 // use module->addWire() and module->remove() to create or destroy wires
1422 friend struct RTLIL::Module;
1423 Wire();
1424 ~Wire();
1425
1426 public:
1427 // do not simply copy wires
1428 Wire(RTLIL::Wire &other) = delete;
1429 void operator=(RTLIL::Wire &other) = delete;
1430
1431 RTLIL::Module *module;
1432 RTLIL::IdString name;
1433 int width, start_offset, port_id;
1434 bool port_input, port_output, upto, is_signed;
1435
1436 #ifdef WITH_PYTHON
1437 static std::map<unsigned int, RTLIL::Wire*> *get_all_wires(void);
1438 #endif
1439 };
1440
1441 struct RTLIL::Memory : public RTLIL::AttrObject
1442 {
1443 unsigned int hashidx_;
1444 unsigned int hash() const { return hashidx_; }
1445
1446 Memory();
1447
1448 RTLIL::IdString name;
1449 int width, start_offset, size;
1450 #ifdef WITH_PYTHON
1451 ~Memory();
1452 static std::map<unsigned int, RTLIL::Memory*> *get_all_memorys(void);
1453 #endif
1454 };
1455
1456 struct RTLIL::Cell : public RTLIL::AttrObject
1457 {
1458 unsigned int hashidx_;
1459 unsigned int hash() const { return hashidx_; }
1460
1461 protected:
1462 // use module->addCell() and module->remove() to create or destroy cells
1463 friend struct RTLIL::Module;
1464 Cell();
1465 ~Cell();
1466
1467 public:
1468 // do not simply copy cells
1469 Cell(RTLIL::Cell &other) = delete;
1470 void operator=(RTLIL::Cell &other) = delete;
1471
1472 RTLIL::Module *module;
1473 RTLIL::IdString name;
1474 RTLIL::IdString type;
1475 dict<RTLIL::IdString, RTLIL::SigSpec> connections_;
1476 dict<RTLIL::IdString, RTLIL::Const> parameters;
1477
1478 // access cell ports
1479 bool hasPort(RTLIL::IdString portname) const;
1480 void unsetPort(RTLIL::IdString portname);
1481 void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal);
1482 const RTLIL::SigSpec &getPort(RTLIL::IdString portname) const;
1483 const dict<RTLIL::IdString, RTLIL::SigSpec> &connections() const;
1484
1485 // information about cell ports
1486 bool known() const;
1487 bool input(RTLIL::IdString portname) const;
1488 bool output(RTLIL::IdString portname) const;
1489
1490 // access cell parameters
1491 bool hasParam(RTLIL::IdString paramname) const;
1492 void unsetParam(RTLIL::IdString paramname);
1493 void setParam(RTLIL::IdString paramname, RTLIL::Const value);
1494 const RTLIL::Const &getParam(RTLIL::IdString paramname) const;
1495
1496 void sort();
1497 void check();
1498 void fixup_parameters(bool set_a_signed = false, bool set_b_signed = false);
1499
1500 bool has_keep_attr() const {
1501 return get_bool_attribute(ID::keep) || (module && module->design && module->design->module(type) &&
1502 module->design->module(type)->get_bool_attribute(ID::keep));
1503 }
1504
1505 template<typename T> void rewrite_sigspecs(T &functor);
1506 template<typename T> void rewrite_sigspecs2(T &functor);
1507
1508 #ifdef WITH_PYTHON
1509 static std::map<unsigned int, RTLIL::Cell*> *get_all_cells(void);
1510 #endif
1511 };
1512
1513 struct RTLIL::CaseRule : public RTLIL::AttrObject
1514 {
1515 std::vector<RTLIL::SigSpec> compare;
1516 std::vector<RTLIL::SigSig> actions;
1517 std::vector<RTLIL::SwitchRule*> switches;
1518
1519 ~CaseRule();
1520 void optimize();
1521
1522 bool empty() const;
1523
1524 template<typename T> void rewrite_sigspecs(T &functor);
1525 template<typename T> void rewrite_sigspecs2(T &functor);
1526 RTLIL::CaseRule *clone() const;
1527 };
1528
1529 struct RTLIL::SwitchRule : public RTLIL::AttrObject
1530 {
1531 RTLIL::SigSpec signal;
1532 std::vector<RTLIL::CaseRule*> cases;
1533
1534 ~SwitchRule();
1535
1536 bool empty() const;
1537
1538 template<typename T> void rewrite_sigspecs(T &functor);
1539 template<typename T> void rewrite_sigspecs2(T &functor);
1540 RTLIL::SwitchRule *clone() const;
1541 };
1542
1543 struct RTLIL::SyncRule
1544 {
1545 RTLIL::SyncType type;
1546 RTLIL::SigSpec signal;
1547 std::vector<RTLIL::SigSig> actions;
1548
1549 template<typename T> void rewrite_sigspecs(T &functor);
1550 template<typename T> void rewrite_sigspecs2(T &functor);
1551 RTLIL::SyncRule *clone() const;
1552 };
1553
1554 struct RTLIL::Process : public RTLIL::AttrObject
1555 {
1556 RTLIL::IdString name;
1557 RTLIL::CaseRule root_case;
1558 std::vector<RTLIL::SyncRule*> syncs;
1559
1560 ~Process();
1561
1562 template<typename T> void rewrite_sigspecs(T &functor);
1563 template<typename T> void rewrite_sigspecs2(T &functor);
1564 RTLIL::Process *clone() const;
1565 };
1566
1567
1568 inline RTLIL::SigBit::SigBit() : wire(NULL), data(RTLIL::State::S0) { }
1569 inline RTLIL::SigBit::SigBit(RTLIL::State bit) : wire(NULL), data(bit) { }
1570 inline RTLIL::SigBit::SigBit(bool bit) : wire(NULL), data(bit ? State::S1 : State::S0) { }
1571 inline RTLIL::SigBit::SigBit(RTLIL::Wire *wire) : wire(wire), offset(0) { log_assert(wire && wire->width == 1); }
1572 inline RTLIL::SigBit::SigBit(RTLIL::Wire *wire, int offset) : wire(wire), offset(offset) { log_assert(wire != nullptr); }
1573 inline RTLIL::SigBit::SigBit(const RTLIL::SigChunk &chunk) : wire(chunk.wire) { log_assert(chunk.width == 1); if (wire) offset = chunk.offset; else data = chunk.data[0]; }
1574 inline RTLIL::SigBit::SigBit(const RTLIL::SigChunk &chunk, int index) : wire(chunk.wire) { if (wire) offset = chunk.offset + index; else data = chunk.data[index]; }
1575
1576 inline bool RTLIL::SigBit::operator<(const RTLIL::SigBit &other) const {
1577 if (wire == other.wire)
1578 return wire ? (offset < other.offset) : (data < other.data);
1579 if (wire != nullptr && other.wire != nullptr)
1580 return wire->name < other.wire->name;
1581 return (wire != nullptr) < (other.wire != nullptr);
1582 }
1583
1584 inline bool RTLIL::SigBit::operator==(const RTLIL::SigBit &other) const {
1585 return (wire == other.wire) && (wire ? (offset == other.offset) : (data == other.data));
1586 }
1587
1588 inline bool RTLIL::SigBit::operator!=(const RTLIL::SigBit &other) const {
1589 return (wire != other.wire) || (wire ? (offset != other.offset) : (data != other.data));
1590 }
1591
1592 inline unsigned int RTLIL::SigBit::hash() const {
1593 if (wire)
1594 return mkhash_add(wire->name.hash(), offset);
1595 return data;
1596 }
1597
1598 inline RTLIL::SigBit &RTLIL::SigSpecIterator::operator*() const {
1599 return (*sig_p)[index];
1600 }
1601
1602 inline const RTLIL::SigBit &RTLIL::SigSpecConstIterator::operator*() const {
1603 return (*sig_p)[index];
1604 }
1605
1606 inline RTLIL::SigBit::SigBit(const RTLIL::SigSpec &sig) {
1607 log_assert(sig.size() == 1 && sig.chunks().size() == 1);
1608 *this = SigBit(sig.chunks().front());
1609 }
1610
1611 template<typename T>
1612 void RTLIL::Module::rewrite_sigspecs(T &functor)
1613 {
1614 for (auto &it : cells_)
1615 it.second->rewrite_sigspecs(functor);
1616 for (auto &it : processes)
1617 it.second->rewrite_sigspecs(functor);
1618 for (auto &it : connections_) {
1619 functor(it.first);
1620 functor(it.second);
1621 }
1622 }
1623
1624 template<typename T>
1625 void RTLIL::Module::rewrite_sigspecs2(T &functor)
1626 {
1627 for (auto &it : cells_)
1628 it.second->rewrite_sigspecs2(functor);
1629 for (auto &it : processes)
1630 it.second->rewrite_sigspecs2(functor);
1631 for (auto &it : connections_) {
1632 functor(it.first, it.second);
1633 }
1634 }
1635
1636 template<typename T>
1637 void RTLIL::Cell::rewrite_sigspecs(T &functor) {
1638 for (auto &it : connections_)
1639 functor(it.second);
1640 }
1641
1642 template<typename T>
1643 void RTLIL::Cell::rewrite_sigspecs2(T &functor) {
1644 for (auto &it : connections_)
1645 functor(it.second);
1646 }
1647
1648 template<typename T>
1649 void RTLIL::CaseRule::rewrite_sigspecs(T &functor) {
1650 for (auto &it : compare)
1651 functor(it);
1652 for (auto &it : actions) {
1653 functor(it.first);
1654 functor(it.second);
1655 }
1656 for (auto it : switches)
1657 it->rewrite_sigspecs(functor);
1658 }
1659
1660 template<typename T>
1661 void RTLIL::CaseRule::rewrite_sigspecs2(T &functor) {
1662 for (auto &it : compare)
1663 functor(it);
1664 for (auto &it : actions) {
1665 functor(it.first, it.second);
1666 }
1667 for (auto it : switches)
1668 it->rewrite_sigspecs2(functor);
1669 }
1670
1671 template<typename T>
1672 void RTLIL::SwitchRule::rewrite_sigspecs(T &functor)
1673 {
1674 functor(signal);
1675 for (auto it : cases)
1676 it->rewrite_sigspecs(functor);
1677 }
1678
1679 template<typename T>
1680 void RTLIL::SwitchRule::rewrite_sigspecs2(T &functor)
1681 {
1682 functor(signal);
1683 for (auto it : cases)
1684 it->rewrite_sigspecs2(functor);
1685 }
1686
1687 template<typename T>
1688 void RTLIL::SyncRule::rewrite_sigspecs(T &functor)
1689 {
1690 functor(signal);
1691 for (auto &it : actions) {
1692 functor(it.first);
1693 functor(it.second);
1694 }
1695 }
1696
1697 template<typename T>
1698 void RTLIL::SyncRule::rewrite_sigspecs2(T &functor)
1699 {
1700 functor(signal);
1701 for (auto &it : actions) {
1702 functor(it.first, it.second);
1703 }
1704 }
1705
1706 template<typename T>
1707 void RTLIL::Process::rewrite_sigspecs(T &functor)
1708 {
1709 root_case.rewrite_sigspecs(functor);
1710 for (auto it : syncs)
1711 it->rewrite_sigspecs(functor);
1712 }
1713
1714 template<typename T>
1715 void RTLIL::Process::rewrite_sigspecs2(T &functor)
1716 {
1717 root_case.rewrite_sigspecs2(functor);
1718 for (auto it : syncs)
1719 it->rewrite_sigspecs2(functor);
1720 }
1721
1722 YOSYS_NAMESPACE_END
1723
1724 #endif