add IdString::isPublic()
[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 size_t size() const {
338 return strlen(c_str());
339 }
340
341 bool empty() const {
342 return c_str()[0] == 0;
343 }
344
345 void clear() {
346 *this = IdString();
347 }
348
349 unsigned int hash() const {
350 return index_;
351 }
352
353 // The following is a helper key_compare class. Instead of for example std::set<Cell*>
354 // use std::set<Cell*, IdString::compare_ptr_by_name<Cell>> if the order of cells in the
355 // set has an influence on the algorithm.
356
357 template<typename T> struct compare_ptr_by_name {
358 bool operator()(const T *a, const T *b) const {
359 return (a == nullptr || b == nullptr) ? (a < b) : (a->name < b->name);
360 }
361 };
362
363 // often one needs to check if a given IdString is part of a list (for example a list
364 // of cell types). the following functions helps with that.
365
366 template<typename... Args>
367 bool in(Args... args) const {
368 // Credit: https://articles.emptycrate.com/2016/05/14/folds_in_cpp11_ish.html
369 bool result = false;
370 (void) std::initializer_list<int>{ (result = result || in(args), 0)... };
371 return result;
372 }
373
374 bool in(const IdString &rhs) const { return *this == rhs; }
375 bool in(const char *rhs) const { return *this == rhs; }
376 bool in(const std::string &rhs) const { return *this == rhs; }
377 bool in(const pool<IdString> &rhs) const { return rhs.count(*this) != 0; }
378
379 bool isPublic() { return begins_with("\\"); }
380 };
381
382 namespace ID {
383 #define X(_id) extern IdString _id;
384 #include "kernel/constids.inc"
385 #undef X
386 };
387
388 extern dict<std::string, std::string> constpad;
389
390 const pool<IdString> &builtin_ff_cell_types();
391
392 static inline std::string escape_id(const std::string &str) {
393 if (str.size() > 0 && str[0] != '\\' && str[0] != '$')
394 return "\\" + str;
395 return str;
396 }
397
398 static inline std::string unescape_id(const std::string &str) {
399 if (str.size() < 2)
400 return str;
401 if (str[0] != '\\')
402 return str;
403 if (str[1] == '$' || str[1] == '\\')
404 return str;
405 if (str[1] >= '0' && str[1] <= '9')
406 return str;
407 return str.substr(1);
408 }
409
410 static inline std::string unescape_id(RTLIL::IdString str) {
411 return unescape_id(str.str());
412 }
413
414 static inline const char *id2cstr(RTLIL::IdString str) {
415 return log_id(str);
416 }
417
418 template <typename T> struct sort_by_name_id {
419 bool operator()(T *a, T *b) const {
420 return a->name < b->name;
421 }
422 };
423
424 template <typename T> struct sort_by_name_str {
425 bool operator()(T *a, T *b) const {
426 return strcmp(a->name.c_str(), b->name.c_str()) < 0;
427 }
428 };
429
430 struct sort_by_id_str {
431 bool operator()(RTLIL::IdString a, RTLIL::IdString b) const {
432 return strcmp(a.c_str(), b.c_str()) < 0;
433 }
434 };
435
436 // see calc.cc for the implementation of this functions
437 RTLIL::Const const_not (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
438 RTLIL::Const const_and (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
439 RTLIL::Const const_or (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
440 RTLIL::Const const_xor (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
441 RTLIL::Const const_xnor (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
442
443 RTLIL::Const const_reduce_and (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
444 RTLIL::Const const_reduce_or (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
445 RTLIL::Const const_reduce_xor (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
446 RTLIL::Const const_reduce_xnor (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
447 RTLIL::Const const_reduce_bool (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
448
449 RTLIL::Const const_logic_not (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
450 RTLIL::Const const_logic_and (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
451 RTLIL::Const const_logic_or (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
452
453 RTLIL::Const const_shl (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
454 RTLIL::Const const_shr (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
455 RTLIL::Const const_sshl (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
456 RTLIL::Const const_sshr (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
457 RTLIL::Const const_shift (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
458 RTLIL::Const const_shiftx (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
459
460 RTLIL::Const const_lt (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
461 RTLIL::Const const_le (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
462 RTLIL::Const const_eq (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
463 RTLIL::Const const_ne (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
464 RTLIL::Const const_eqx (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
465 RTLIL::Const const_nex (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
466 RTLIL::Const const_ge (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
467 RTLIL::Const const_gt (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
468
469 RTLIL::Const const_add (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
470 RTLIL::Const const_sub (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
471 RTLIL::Const const_mul (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
472 RTLIL::Const const_div (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
473 RTLIL::Const const_divfloor (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
474 RTLIL::Const const_modfloor (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
475 RTLIL::Const const_mod (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
476 RTLIL::Const const_pow (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
477
478 RTLIL::Const const_pos (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
479 RTLIL::Const const_neg (const RTLIL::Const &arg1, const RTLIL::Const &arg2, bool signed1, bool signed2, int result_len);
480
481
482 // This iterator-range-pair is used for Design::modules(), Module::wires() and Module::cells().
483 // It maintains a reference counter that is used to make sure that the container is not modified while being iterated over.
484
485 template<typename T>
486 struct ObjIterator {
487 using iterator_category = std::forward_iterator_tag;
488 using value_type = T;
489 using difference_type = ptrdiff_t;
490 using pointer = T*;
491 using reference = T&;
492 typename dict<RTLIL::IdString, T>::iterator it;
493 dict<RTLIL::IdString, T> *list_p;
494 int *refcount_p;
495
496 ObjIterator() : list_p(nullptr), refcount_p(nullptr) {
497 }
498
499 ObjIterator(decltype(list_p) list_p, int *refcount_p) : list_p(list_p), refcount_p(refcount_p) {
500 if (list_p->empty()) {
501 this->list_p = nullptr;
502 this->refcount_p = nullptr;
503 } else {
504 it = list_p->begin();
505 (*refcount_p)++;
506 }
507 }
508
509 ObjIterator(const RTLIL::ObjIterator<T> &other) {
510 it = other.it;
511 list_p = other.list_p;
512 refcount_p = other.refcount_p;
513 if (refcount_p)
514 (*refcount_p)++;
515 }
516
517 ObjIterator &operator=(const RTLIL::ObjIterator<T> &other) {
518 if (refcount_p)
519 (*refcount_p)--;
520 it = other.it;
521 list_p = other.list_p;
522 refcount_p = other.refcount_p;
523 if (refcount_p)
524 (*refcount_p)++;
525 return *this;
526 }
527
528 ~ObjIterator() {
529 if (refcount_p)
530 (*refcount_p)--;
531 }
532
533 inline T operator*() const {
534 log_assert(list_p != nullptr);
535 return it->second;
536 }
537
538 inline bool operator!=(const RTLIL::ObjIterator<T> &other) const {
539 if (list_p == nullptr || other.list_p == nullptr)
540 return list_p != other.list_p;
541 return it != other.it;
542 }
543
544
545 inline bool operator==(const RTLIL::ObjIterator<T> &other) const {
546 return !(*this != other);
547 }
548
549 inline ObjIterator<T>& operator++() {
550 log_assert(list_p != nullptr);
551 if (++it == list_p->end()) {
552 (*refcount_p)--;
553 list_p = nullptr;
554 refcount_p = nullptr;
555 }
556 return *this;
557 }
558
559 inline ObjIterator<T>& operator+=(int amt) {
560 log_assert(list_p != nullptr);
561 it += amt;
562 if (it == list_p->end()) {
563 (*refcount_p)--;
564 list_p = nullptr;
565 refcount_p = nullptr;
566 }
567 return *this;
568 }
569
570 inline ObjIterator<T> operator+(int amt) {
571 log_assert(list_p != nullptr);
572 ObjIterator<T> new_obj(*this);
573 new_obj.it += amt;
574 if (new_obj.it == list_p->end()) {
575 (*(new_obj.refcount_p))--;
576 new_obj.list_p = nullptr;
577 new_obj.refcount_p = nullptr;
578 }
579 return new_obj;
580 }
581
582 inline const ObjIterator<T> operator++(int) {
583 ObjIterator<T> result(*this);
584 ++(*this);
585 return result;
586 }
587 };
588
589 template<typename T>
590 struct ObjRange
591 {
592 dict<RTLIL::IdString, T> *list_p;
593 int *refcount_p;
594
595 ObjRange(decltype(list_p) list_p, int *refcount_p) : list_p(list_p), refcount_p(refcount_p) { }
596 RTLIL::ObjIterator<T> begin() { return RTLIL::ObjIterator<T>(list_p, refcount_p); }
597 RTLIL::ObjIterator<T> end() { return RTLIL::ObjIterator<T>(); }
598
599 size_t size() const {
600 return list_p->size();
601 }
602
603 operator pool<T>() const {
604 pool<T> result;
605 for (auto &it : *list_p)
606 result.insert(it.second);
607 return result;
608 }
609
610 operator std::vector<T>() const {
611 std::vector<T> result;
612 result.reserve(list_p->size());
613 for (auto &it : *list_p)
614 result.push_back(it.second);
615 return result;
616 }
617
618 pool<T> to_pool() const { return *this; }
619 std::vector<T> to_vector() const { return *this; }
620 };
621 };
622
623 struct RTLIL::Const
624 {
625 int flags;
626 std::vector<RTLIL::State> bits;
627
628 Const();
629 Const(std::string str);
630 Const(int val, int width = 32);
631 Const(RTLIL::State bit, int width = 1);
632 Const(const std::vector<RTLIL::State> &bits) : bits(bits) { flags = CONST_FLAG_NONE; }
633 Const(const std::vector<bool> &bits);
634 Const(const RTLIL::Const &c);
635 RTLIL::Const &operator =(const RTLIL::Const &other) = default;
636
637 bool operator <(const RTLIL::Const &other) const;
638 bool operator ==(const RTLIL::Const &other) const;
639 bool operator !=(const RTLIL::Const &other) const;
640
641 bool as_bool() const;
642 int as_int(bool is_signed = false) const;
643 std::string as_string() const;
644 static Const from_string(const std::string &str);
645
646 std::string decode_string() const;
647
648 inline int size() const { return bits.size(); }
649 inline bool empty() const { return bits.empty(); }
650 inline RTLIL::State &operator[](int index) { return bits.at(index); }
651 inline const RTLIL::State &operator[](int index) const { return bits.at(index); }
652 inline decltype(bits)::iterator begin() { return bits.begin(); }
653 inline decltype(bits)::iterator end() { return bits.end(); }
654
655 bool is_fully_zero() const;
656 bool is_fully_ones() const;
657 bool is_fully_def() const;
658 bool is_fully_undef() const;
659
660 inline RTLIL::Const extract(int offset, int len = 1, RTLIL::State padding = RTLIL::State::S0) const {
661 RTLIL::Const ret;
662 ret.bits.reserve(len);
663 for (int i = offset; i < offset + len; i++)
664 ret.bits.push_back(i < GetSize(bits) ? bits[i] : padding);
665 return ret;
666 }
667
668 void extu(int width) {
669 bits.resize(width, RTLIL::State::S0);
670 }
671
672 void exts(int width) {
673 bits.resize(width, bits.empty() ? RTLIL::State::Sx : bits.back());
674 }
675
676 inline unsigned int hash() const {
677 unsigned int h = mkhash_init;
678 for (auto b : bits)
679 mkhash(h, b);
680 return h;
681 }
682 };
683
684 struct RTLIL::AttrObject
685 {
686 dict<RTLIL::IdString, RTLIL::Const> attributes;
687
688 bool has_attribute(RTLIL::IdString id) const;
689
690 void set_bool_attribute(RTLIL::IdString id, bool value=true);
691 bool get_bool_attribute(RTLIL::IdString id) const;
692
693 bool get_blackbox_attribute(bool ignore_wb=false) const {
694 return get_bool_attribute(ID::blackbox) || (!ignore_wb && get_bool_attribute(ID::whitebox));
695 }
696
697 void set_string_attribute(RTLIL::IdString id, string value);
698 string get_string_attribute(RTLIL::IdString id) const;
699
700 void set_strpool_attribute(RTLIL::IdString id, const pool<string> &data);
701 void add_strpool_attribute(RTLIL::IdString id, const pool<string> &data);
702 pool<string> get_strpool_attribute(RTLIL::IdString id) const;
703
704 void set_src_attribute(const std::string &src) {
705 set_string_attribute(ID::src, src);
706 }
707 std::string get_src_attribute() const {
708 return get_string_attribute(ID::src);
709 }
710
711 void set_hdlname_attribute(const vector<string> &hierarchy);
712 vector<string> get_hdlname_attribute() const;
713 };
714
715 struct RTLIL::SigChunk
716 {
717 RTLIL::Wire *wire;
718 std::vector<RTLIL::State> data; // only used if wire == NULL, LSB at index 0
719 int width, offset;
720
721 SigChunk();
722 SigChunk(const RTLIL::Const &value);
723 SigChunk(RTLIL::Wire *wire);
724 SigChunk(RTLIL::Wire *wire, int offset, int width = 1);
725 SigChunk(const std::string &str);
726 SigChunk(int val, int width = 32);
727 SigChunk(RTLIL::State bit, int width = 1);
728 SigChunk(const RTLIL::SigBit &bit);
729 SigChunk(const RTLIL::SigChunk &sigchunk);
730 RTLIL::SigChunk &operator =(const RTLIL::SigChunk &other) = default;
731
732 RTLIL::SigChunk extract(int offset, int length) const;
733 inline int size() const { return width; }
734
735 bool operator <(const RTLIL::SigChunk &other) const;
736 bool operator ==(const RTLIL::SigChunk &other) const;
737 bool operator !=(const RTLIL::SigChunk &other) const;
738 };
739
740 struct RTLIL::SigBit
741 {
742 RTLIL::Wire *wire;
743 union {
744 RTLIL::State data; // used if wire == NULL
745 int offset; // used if wire != NULL
746 };
747
748 SigBit();
749 SigBit(RTLIL::State bit);
750 SigBit(bool bit);
751 SigBit(RTLIL::Wire *wire);
752 SigBit(RTLIL::Wire *wire, int offset);
753 SigBit(const RTLIL::SigChunk &chunk);
754 SigBit(const RTLIL::SigChunk &chunk, int index);
755 SigBit(const RTLIL::SigSpec &sig);
756 SigBit(const RTLIL::SigBit &sigbit) = default;
757 RTLIL::SigBit &operator =(const RTLIL::SigBit &other) = default;
758
759 bool operator <(const RTLIL::SigBit &other) const;
760 bool operator ==(const RTLIL::SigBit &other) const;
761 bool operator !=(const RTLIL::SigBit &other) const;
762 unsigned int hash() const;
763 };
764
765 struct RTLIL::SigSpecIterator : public std::iterator<std::input_iterator_tag, RTLIL::SigSpec>
766 {
767 RTLIL::SigSpec *sig_p;
768 int index;
769
770 inline RTLIL::SigBit &operator*() const;
771 inline bool operator!=(const RTLIL::SigSpecIterator &other) const { return index != other.index; }
772 inline bool operator==(const RTLIL::SigSpecIterator &other) const { return index == other.index; }
773 inline void operator++() { index++; }
774 };
775
776 struct RTLIL::SigSpecConstIterator : public std::iterator<std::input_iterator_tag, RTLIL::SigSpec>
777 {
778 const RTLIL::SigSpec *sig_p;
779 int index;
780
781 inline const RTLIL::SigBit &operator*() const;
782 inline bool operator!=(const RTLIL::SigSpecConstIterator &other) const { return index != other.index; }
783 inline bool operator==(const RTLIL::SigSpecIterator &other) const { return index == other.index; }
784 inline void operator++() { index++; }
785 };
786
787 struct RTLIL::SigSpec
788 {
789 private:
790 int width_;
791 unsigned long hash_;
792 std::vector<RTLIL::SigChunk> chunks_; // LSB at index 0
793 std::vector<RTLIL::SigBit> bits_; // LSB at index 0
794
795 void pack() const;
796 void unpack() const;
797 void updhash() const;
798
799 inline bool packed() const {
800 return bits_.empty();
801 }
802
803 inline void inline_unpack() const {
804 if (!chunks_.empty())
805 unpack();
806 }
807
808 // Only used by Module::remove(const pool<Wire*> &wires)
809 // but cannot be more specific as it isn't yet declared
810 friend struct RTLIL::Module;
811
812 public:
813 SigSpec();
814 SigSpec(const RTLIL::SigSpec &other);
815 SigSpec(std::initializer_list<RTLIL::SigSpec> parts);
816 RTLIL::SigSpec &operator=(const RTLIL::SigSpec &other);
817
818 SigSpec(const RTLIL::Const &value);
819 SigSpec(const RTLIL::SigChunk &chunk);
820 SigSpec(RTLIL::Wire *wire);
821 SigSpec(RTLIL::Wire *wire, int offset, int width = 1);
822 SigSpec(const std::string &str);
823 SigSpec(int val, int width = 32);
824 SigSpec(RTLIL::State bit, int width = 1);
825 SigSpec(const RTLIL::SigBit &bit, int width = 1);
826 SigSpec(const std::vector<RTLIL::SigChunk> &chunks);
827 SigSpec(const std::vector<RTLIL::SigBit> &bits);
828 SigSpec(const pool<RTLIL::SigBit> &bits);
829 SigSpec(const std::set<RTLIL::SigBit> &bits);
830 SigSpec(bool bit);
831
832 SigSpec(RTLIL::SigSpec &&other) {
833 width_ = other.width_;
834 hash_ = other.hash_;
835 chunks_ = std::move(other.chunks_);
836 bits_ = std::move(other.bits_);
837 }
838
839 const RTLIL::SigSpec &operator=(RTLIL::SigSpec &&other) {
840 width_ = other.width_;
841 hash_ = other.hash_;
842 chunks_ = std::move(other.chunks_);
843 bits_ = std::move(other.bits_);
844 return *this;
845 }
846
847 size_t get_hash() const {
848 if (!hash_) hash();
849 return hash_;
850 }
851
852 inline const std::vector<RTLIL::SigChunk> &chunks() const { pack(); return chunks_; }
853 inline const std::vector<RTLIL::SigBit> &bits() const { inline_unpack(); return bits_; }
854
855 inline int size() const { return width_; }
856 inline bool empty() const { return width_ == 0; }
857
858 inline RTLIL::SigBit &operator[](int index) { inline_unpack(); return bits_.at(index); }
859 inline const RTLIL::SigBit &operator[](int index) const { inline_unpack(); return bits_.at(index); }
860
861 inline RTLIL::SigSpecIterator begin() { RTLIL::SigSpecIterator it; it.sig_p = this; it.index = 0; return it; }
862 inline RTLIL::SigSpecIterator end() { RTLIL::SigSpecIterator it; it.sig_p = this; it.index = width_; return it; }
863
864 inline RTLIL::SigSpecConstIterator begin() const { RTLIL::SigSpecConstIterator it; it.sig_p = this; it.index = 0; return it; }
865 inline RTLIL::SigSpecConstIterator end() const { RTLIL::SigSpecConstIterator it; it.sig_p = this; it.index = width_; return it; }
866
867 void sort();
868 void sort_and_unify();
869
870 void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with);
871 void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with, RTLIL::SigSpec *other) const;
872
873 void replace(const dict<RTLIL::SigBit, RTLIL::SigBit> &rules);
874 void replace(const dict<RTLIL::SigBit, RTLIL::SigBit> &rules, RTLIL::SigSpec *other) const;
875
876 void replace(const std::map<RTLIL::SigBit, RTLIL::SigBit> &rules);
877 void replace(const std::map<RTLIL::SigBit, RTLIL::SigBit> &rules, RTLIL::SigSpec *other) const;
878
879 void replace(int offset, const RTLIL::SigSpec &with);
880
881 void remove(const RTLIL::SigSpec &pattern);
882 void remove(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other) const;
883 void remove2(const RTLIL::SigSpec &pattern, RTLIL::SigSpec *other);
884
885 void remove(const pool<RTLIL::SigBit> &pattern);
886 void remove(const pool<RTLIL::SigBit> &pattern, RTLIL::SigSpec *other) const;
887 void remove2(const pool<RTLIL::SigBit> &pattern, RTLIL::SigSpec *other);
888 void remove2(const std::set<RTLIL::SigBit> &pattern, RTLIL::SigSpec *other);
889
890 void remove(int offset, int length = 1);
891 void remove_const();
892
893 RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other = NULL) const;
894 RTLIL::SigSpec extract(const pool<RTLIL::SigBit> &pattern, const RTLIL::SigSpec *other = NULL) const;
895 RTLIL::SigSpec extract(int offset, int length = 1) const;
896 RTLIL::SigSpec extract_end(int offset) const { return extract(offset, width_ - offset); }
897
898 void append(const RTLIL::SigSpec &signal);
899 inline void append(Wire *wire) { append(RTLIL::SigSpec(wire)); }
900 inline void append(const RTLIL::SigChunk &chunk) { append(RTLIL::SigSpec(chunk)); }
901 inline void append(const RTLIL::Const &const_) { append(RTLIL::SigSpec(const_)); }
902
903 void append(const RTLIL::SigBit &bit);
904 inline void append(RTLIL::State state) { append(RTLIL::SigBit(state)); }
905 inline void append(bool bool_) { append(RTLIL::SigBit(bool_)); }
906
907 void extend_u0(int width, bool is_signed = false);
908
909 RTLIL::SigSpec repeat(int num) const;
910
911 void reverse() { inline_unpack(); std::reverse(bits_.begin(), bits_.end()); }
912
913 bool operator <(const RTLIL::SigSpec &other) const;
914 bool operator ==(const RTLIL::SigSpec &other) const;
915 inline bool operator !=(const RTLIL::SigSpec &other) const { return !(*this == other); }
916
917 bool is_wire() const;
918 bool is_chunk() const;
919 inline bool is_bit() const { return width_ == 1; }
920
921 bool is_fully_const() const;
922 bool is_fully_zero() const;
923 bool is_fully_ones() const;
924 bool is_fully_def() const;
925 bool is_fully_undef() const;
926 bool has_const() const;
927 bool has_marked_bits() const;
928
929 bool as_bool() const;
930 int as_int(bool is_signed = false) const;
931 std::string as_string() const;
932 RTLIL::Const as_const() const;
933 RTLIL::Wire *as_wire() const;
934 RTLIL::SigChunk as_chunk() const;
935 RTLIL::SigBit as_bit() const;
936
937 bool match(const char* pattern) const;
938
939 std::set<RTLIL::SigBit> to_sigbit_set() const;
940 pool<RTLIL::SigBit> to_sigbit_pool() const;
941 std::vector<RTLIL::SigBit> to_sigbit_vector() const;
942 std::map<RTLIL::SigBit, RTLIL::SigBit> to_sigbit_map(const RTLIL::SigSpec &other) const;
943 dict<RTLIL::SigBit, RTLIL::SigBit> to_sigbit_dict(const RTLIL::SigSpec &other) const;
944
945 static bool parse(RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str);
946 static bool parse_sel(RTLIL::SigSpec &sig, RTLIL::Design *design, RTLIL::Module *module, std::string str);
947 static bool parse_rhs(const RTLIL::SigSpec &lhs, RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str);
948
949 operator std::vector<RTLIL::SigChunk>() const { return chunks(); }
950 operator std::vector<RTLIL::SigBit>() const { return bits(); }
951 const RTLIL::SigBit &at(int offset, const RTLIL::SigBit &defval) { return offset < width_ ? (*this)[offset] : defval; }
952
953 unsigned int hash() const { if (!hash_) updhash(); return hash_; };
954
955 #ifndef NDEBUG
956 void check() const;
957 #else
958 void check() const { }
959 #endif
960 };
961
962 struct RTLIL::Selection
963 {
964 bool full_selection;
965 pool<RTLIL::IdString> selected_modules;
966 dict<RTLIL::IdString, pool<RTLIL::IdString>> selected_members;
967
968 Selection(bool full = true) : full_selection(full) { }
969
970 bool selected_module(RTLIL::IdString mod_name) const;
971 bool selected_whole_module(RTLIL::IdString mod_name) const;
972 bool selected_member(RTLIL::IdString mod_name, RTLIL::IdString memb_name) const;
973 void optimize(RTLIL::Design *design);
974
975 template<typename T1> void select(T1 *module) {
976 if (!full_selection && selected_modules.count(module->name) == 0) {
977 selected_modules.insert(module->name);
978 selected_members.erase(module->name);
979 }
980 }
981
982 template<typename T1, typename T2> void select(T1 *module, T2 *member) {
983 if (!full_selection && selected_modules.count(module->name) == 0)
984 selected_members[module->name].insert(member->name);
985 }
986
987 bool empty() const {
988 return !full_selection && selected_modules.empty() && selected_members.empty();
989 }
990 };
991
992 struct RTLIL::Monitor
993 {
994 unsigned int hashidx_;
995 unsigned int hash() const { return hashidx_; }
996
997 Monitor() {
998 static unsigned int hashidx_count = 123456789;
999 hashidx_count = mkhash_xorshift(hashidx_count);
1000 hashidx_ = hashidx_count;
1001 }
1002
1003 virtual ~Monitor() { }
1004 virtual void notify_module_add(RTLIL::Module*) { }
1005 virtual void notify_module_del(RTLIL::Module*) { }
1006 virtual void notify_connect(RTLIL::Cell*, const RTLIL::IdString&, const RTLIL::SigSpec&, const RTLIL::SigSpec&) { }
1007 virtual void notify_connect(RTLIL::Module*, const RTLIL::SigSig&) { }
1008 virtual void notify_connect(RTLIL::Module*, const std::vector<RTLIL::SigSig>&) { }
1009 virtual void notify_blackout(RTLIL::Module*) { }
1010 };
1011
1012 // Forward declaration; defined in preproc.h.
1013 struct define_map_t;
1014
1015 struct RTLIL::Design
1016 {
1017 unsigned int hashidx_;
1018 unsigned int hash() const { return hashidx_; }
1019
1020 pool<RTLIL::Monitor*> monitors;
1021 dict<std::string, std::string> scratchpad;
1022
1023 int refcount_modules_;
1024 dict<RTLIL::IdString, RTLIL::Module*> modules_;
1025 std::vector<AST::AstNode*> verilog_packages, verilog_globals;
1026 std::unique_ptr<define_map_t> verilog_defines;
1027
1028 std::vector<RTLIL::Selection> selection_stack;
1029 dict<RTLIL::IdString, RTLIL::Selection> selection_vars;
1030 std::string selected_active_module;
1031
1032 Design();
1033 ~Design();
1034
1035 RTLIL::ObjRange<RTLIL::Module*> modules();
1036 RTLIL::Module *module(RTLIL::IdString name);
1037 RTLIL::Module *top_module();
1038
1039 bool has(RTLIL::IdString id) const {
1040 return modules_.count(id) != 0;
1041 }
1042
1043 void add(RTLIL::Module *module);
1044 RTLIL::Module *addModule(RTLIL::IdString name);
1045 void remove(RTLIL::Module *module);
1046 void rename(RTLIL::Module *module, RTLIL::IdString new_name);
1047
1048 void scratchpad_unset(const std::string &varname);
1049
1050 void scratchpad_set_int(const std::string &varname, int value);
1051 void scratchpad_set_bool(const std::string &varname, bool value);
1052 void scratchpad_set_string(const std::string &varname, std::string value);
1053
1054 int scratchpad_get_int(const std::string &varname, int default_value = 0) const;
1055 bool scratchpad_get_bool(const std::string &varname, bool default_value = false) const;
1056 std::string scratchpad_get_string(const std::string &varname, const std::string &default_value = std::string()) const;
1057
1058 void sort();
1059 void check();
1060 void optimize();
1061
1062 bool selected_module(RTLIL::IdString mod_name) const;
1063 bool selected_whole_module(RTLIL::IdString mod_name) const;
1064 bool selected_member(RTLIL::IdString mod_name, RTLIL::IdString memb_name) const;
1065
1066 bool selected_module(RTLIL::Module *mod) const;
1067 bool selected_whole_module(RTLIL::Module *mod) const;
1068
1069 RTLIL::Selection &selection() {
1070 return selection_stack.back();
1071 }
1072
1073 const RTLIL::Selection &selection() const {
1074 return selection_stack.back();
1075 }
1076
1077 bool full_selection() const {
1078 return selection_stack.back().full_selection;
1079 }
1080
1081 template<typename T1> bool selected(T1 *module) const {
1082 return selected_module(module->name);
1083 }
1084
1085 template<typename T1, typename T2> bool selected(T1 *module, T2 *member) const {
1086 return selected_member(module->name, member->name);
1087 }
1088
1089 template<typename T1> void select(T1 *module) {
1090 if (selection_stack.size() > 0) {
1091 RTLIL::Selection &sel = selection_stack.back();
1092 sel.select(module);
1093 }
1094 }
1095
1096 template<typename T1, typename T2> void select(T1 *module, T2 *member) {
1097 if (selection_stack.size() > 0) {
1098 RTLIL::Selection &sel = selection_stack.back();
1099 sel.select(module, member);
1100 }
1101 }
1102
1103
1104 std::vector<RTLIL::Module*> selected_modules() const;
1105 std::vector<RTLIL::Module*> selected_whole_modules() const;
1106 std::vector<RTLIL::Module*> selected_whole_modules_warn() const;
1107 #ifdef WITH_PYTHON
1108 static std::map<unsigned int, RTLIL::Design*> *get_all_designs(void);
1109 #endif
1110 };
1111
1112 struct RTLIL::Module : public RTLIL::AttrObject
1113 {
1114 unsigned int hashidx_;
1115 unsigned int hash() const { return hashidx_; }
1116
1117 protected:
1118 void add(RTLIL::Wire *wire);
1119 void add(RTLIL::Cell *cell);
1120
1121 public:
1122 RTLIL::Design *design;
1123 pool<RTLIL::Monitor*> monitors;
1124
1125 int refcount_wires_;
1126 int refcount_cells_;
1127
1128 dict<RTLIL::IdString, RTLIL::Wire*> wires_;
1129 dict<RTLIL::IdString, RTLIL::Cell*> cells_;
1130 std::vector<RTLIL::SigSig> connections_;
1131
1132 RTLIL::IdString name;
1133 idict<RTLIL::IdString> avail_parameters;
1134 dict<RTLIL::IdString, RTLIL::Const> parameter_default_values;
1135 dict<RTLIL::IdString, RTLIL::Memory*> memories;
1136 dict<RTLIL::IdString, RTLIL::Process*> processes;
1137
1138 Module();
1139 virtual ~Module();
1140 virtual RTLIL::IdString derive(RTLIL::Design *design, const dict<RTLIL::IdString, RTLIL::Const> &parameters, bool mayfail = false);
1141 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);
1142 virtual size_t count_id(RTLIL::IdString id);
1143 virtual void reprocess_module(RTLIL::Design *design, const dict<RTLIL::IdString, RTLIL::Module *> &local_interfaces);
1144
1145 virtual void sort();
1146 virtual void check();
1147 virtual void optimize();
1148 virtual void makeblackbox();
1149
1150 void connect(const RTLIL::SigSig &conn);
1151 void connect(const RTLIL::SigSpec &lhs, const RTLIL::SigSpec &rhs);
1152 void new_connections(const std::vector<RTLIL::SigSig> &new_conn);
1153 const std::vector<RTLIL::SigSig> &connections() const;
1154
1155 std::vector<RTLIL::IdString> ports;
1156 void fixup_ports();
1157
1158 template<typename T> void rewrite_sigspecs(T &functor);
1159 template<typename T> void rewrite_sigspecs2(T &functor);
1160 void cloneInto(RTLIL::Module *new_mod) const;
1161 virtual RTLIL::Module *clone() const;
1162
1163 bool has_memories() const;
1164 bool has_processes() const;
1165
1166 bool has_memories_warn() const;
1167 bool has_processes_warn() const;
1168
1169 std::vector<RTLIL::Wire*> selected_wires() const;
1170 std::vector<RTLIL::Cell*> selected_cells() const;
1171
1172 template<typename T> bool selected(T *member) const {
1173 return design->selected_member(name, member->name);
1174 }
1175
1176 RTLIL::Wire* wire(RTLIL::IdString id) {
1177 auto it = wires_.find(id);
1178 return it == wires_.end() ? nullptr : it->second;
1179 }
1180 RTLIL::Cell* cell(RTLIL::IdString id) {
1181 auto it = cells_.find(id);
1182 return it == cells_.end() ? nullptr : it->second;
1183 }
1184
1185 RTLIL::ObjRange<RTLIL::Wire*> wires() { return RTLIL::ObjRange<RTLIL::Wire*>(&wires_, &refcount_wires_); }
1186 RTLIL::ObjRange<RTLIL::Cell*> cells() { return RTLIL::ObjRange<RTLIL::Cell*>(&cells_, &refcount_cells_); }
1187
1188 // Removing wires is expensive. If you have to remove wires, remove them all at once.
1189 void remove(const pool<RTLIL::Wire*> &wires);
1190 void remove(RTLIL::Cell *cell);
1191
1192 void rename(RTLIL::Wire *wire, RTLIL::IdString new_name);
1193 void rename(RTLIL::Cell *cell, RTLIL::IdString new_name);
1194 void rename(RTLIL::IdString old_name, RTLIL::IdString new_name);
1195
1196 void swap_names(RTLIL::Wire *w1, RTLIL::Wire *w2);
1197 void swap_names(RTLIL::Cell *c1, RTLIL::Cell *c2);
1198
1199 RTLIL::IdString uniquify(RTLIL::IdString name);
1200 RTLIL::IdString uniquify(RTLIL::IdString name, int &index);
1201
1202 RTLIL::Wire *addWire(RTLIL::IdString name, int width = 1);
1203 RTLIL::Wire *addWire(RTLIL::IdString name, const RTLIL::Wire *other);
1204
1205 RTLIL::Cell *addCell(RTLIL::IdString name, RTLIL::IdString type);
1206 RTLIL::Cell *addCell(RTLIL::IdString name, const RTLIL::Cell *other);
1207
1208 RTLIL::Memory *addMemory(RTLIL::IdString name, const RTLIL::Memory *other);
1209
1210 RTLIL::Process *addProcess(RTLIL::IdString name, const RTLIL::Process *other);
1211
1212 // The add* methods create a cell and return the created cell. All signals must exist in advance.
1213
1214 RTLIL::Cell* addNot (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1215 RTLIL::Cell* addPos (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1216 RTLIL::Cell* addNeg (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1217
1218 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 = "");
1219 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 = "");
1220 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 = "");
1221 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 = "");
1222
1223 RTLIL::Cell* addReduceAnd (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1224 RTLIL::Cell* addReduceOr (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1225 RTLIL::Cell* addReduceXor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1226 RTLIL::Cell* addReduceXnor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1227 RTLIL::Cell* addReduceBool (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1228
1229 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 = "");
1230 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 = "");
1231 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 = "");
1232 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 = "");
1233 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 = "");
1234 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 = "");
1235
1236 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 = "");
1237 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 = "");
1238 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 = "");
1239 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 = "");
1240 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 = "");
1241 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 = "");
1242 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 = "");
1243 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 = "");
1244
1245 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 = "");
1246 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 = "");
1247 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 = "");
1248 // truncating division
1249 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 = "");
1250 // truncating modulo
1251 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 = "");
1252 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 = "");
1253 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 = "");
1254 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 = "");
1255
1256 RTLIL::Cell* addLogicNot (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed = false, const std::string &src = "");
1257 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 = "");
1258 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 = "");
1259
1260 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 = "");
1261 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 = "");
1262
1263 RTLIL::Cell* addSlice (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, RTLIL::Const offset, const std::string &src = "");
1264 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 = "");
1265 RTLIL::Cell* addLut (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, RTLIL::Const lut, const std::string &src = "");
1266 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 = "");
1267 RTLIL::Cell* addAssert (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_en, const std::string &src = "");
1268 RTLIL::Cell* addAssume (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_en, const std::string &src = "");
1269 RTLIL::Cell* addLive (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_en, const std::string &src = "");
1270 RTLIL::Cell* addFair (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_en, const std::string &src = "");
1271 RTLIL::Cell* addCover (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_en, const std::string &src = "");
1272 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 = "");
1273
1274 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 = "");
1275 RTLIL::Cell* addFf (RTLIL::IdString name, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, const std::string &src = "");
1276 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 = "");
1277 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 = "");
1278 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 = "");
1279 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 = "");
1280 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 = "");
1281 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 = "");
1282 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 = "");
1283 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 = "");
1284 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 = "");
1285 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 = "");
1286 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 = "");
1287 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 = "");
1288
1289 RTLIL::Cell* addBufGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_y, const std::string &src = "");
1290 RTLIL::Cell* addNotGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_y, const std::string &src = "");
1291 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 = "");
1292 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 = "");
1293 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 = "");
1294 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 = "");
1295 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 = "");
1296 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 = "");
1297 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 = "");
1298 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 = "");
1299 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 = "");
1300 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 = "");
1301 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 = "");
1302 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 = "");
1303 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 = "");
1304 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 = "");
1305
1306 RTLIL::Cell* addSrGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr,
1307 const RTLIL::SigSpec &sig_q, bool set_polarity = true, bool clr_polarity = true, const std::string &src = "");
1308 RTLIL::Cell* addFfGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_d, const RTLIL::SigSpec &sig_q, const std::string &src = "");
1309 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 = "");
1310 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 = "");
1311 RTLIL::Cell* addDffsrGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_clk, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr,
1312 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 = "");
1313 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,
1314 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 = "");
1315 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,
1316 bool arst_value = false, bool clk_polarity = true, bool arst_polarity = true, const std::string &src = "");
1317 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,
1318 bool arst_value = false, bool clk_polarity = true, bool en_polarity = true, bool arst_polarity = true, const std::string &src = "");
1319 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,
1320 bool srst_value = false, bool clk_polarity = true, bool srst_polarity = true, const std::string &src = "");
1321 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,
1322 bool srst_value = false, bool clk_polarity = true, bool en_polarity = true, bool srst_polarity = true, const std::string &src = "");
1323 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,
1324 bool srst_value = false, bool clk_polarity = true, bool en_polarity = true, bool srst_polarity = true, const std::string &src = "");
1325 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 = "");
1326 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,
1327 bool arst_value = false, bool en_polarity = true, bool arst_polarity = true, const std::string &src = "");
1328 RTLIL::Cell* addDlatchsrGate (RTLIL::IdString name, const RTLIL::SigSpec &sig_en, const RTLIL::SigSpec &sig_set, const RTLIL::SigSpec &sig_clr,
1329 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 = "");
1330
1331 // The methods without the add* prefix create a cell and an output signal. They return the newly created output signal.
1332
1333 RTLIL::SigSpec Not (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1334 RTLIL::SigSpec Pos (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1335 RTLIL::SigSpec Bu0 (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1336 RTLIL::SigSpec Neg (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1337
1338 RTLIL::SigSpec And (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1339 RTLIL::SigSpec Or (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1340 RTLIL::SigSpec Xor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1341 RTLIL::SigSpec Xnor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1342
1343 RTLIL::SigSpec ReduceAnd (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1344 RTLIL::SigSpec ReduceOr (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1345 RTLIL::SigSpec ReduceXor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1346 RTLIL::SigSpec ReduceXnor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1347 RTLIL::SigSpec ReduceBool (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1348
1349 RTLIL::SigSpec Shl (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1350 RTLIL::SigSpec Shr (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1351 RTLIL::SigSpec Sshl (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1352 RTLIL::SigSpec Sshr (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1353 RTLIL::SigSpec Shift (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1354 RTLIL::SigSpec Shiftx (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1355
1356 RTLIL::SigSpec Lt (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1357 RTLIL::SigSpec Le (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1358 RTLIL::SigSpec Eq (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1359 RTLIL::SigSpec Ne (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1360 RTLIL::SigSpec Eqx (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1361 RTLIL::SigSpec Nex (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1362 RTLIL::SigSpec Ge (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1363 RTLIL::SigSpec Gt (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1364
1365 RTLIL::SigSpec Add (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1366 RTLIL::SigSpec Sub (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1367 RTLIL::SigSpec Mul (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1368 // truncating division
1369 RTLIL::SigSpec Div (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1370 // truncating modulo
1371 RTLIL::SigSpec Mod (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1372 RTLIL::SigSpec DivFloor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1373 RTLIL::SigSpec ModFloor (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1374 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 = "");
1375
1376 RTLIL::SigSpec LogicNot (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed = false, const std::string &src = "");
1377 RTLIL::SigSpec LogicAnd (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1378 RTLIL::SigSpec LogicOr (RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed = false, const std::string &src = "");
1379
1380 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 = "");
1381 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 = "");
1382
1383 RTLIL::SigBit BufGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const std::string &src = "");
1384 RTLIL::SigBit NotGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const std::string &src = "");
1385 RTLIL::SigBit AndGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const std::string &src = "");
1386 RTLIL::SigBit NandGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const std::string &src = "");
1387 RTLIL::SigBit OrGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const std::string &src = "");
1388 RTLIL::SigBit NorGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const std::string &src = "");
1389 RTLIL::SigBit XorGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const std::string &src = "");
1390 RTLIL::SigBit XnorGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const std::string &src = "");
1391 RTLIL::SigBit AndnotGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const std::string &src = "");
1392 RTLIL::SigBit OrnotGate (RTLIL::IdString name, const RTLIL::SigBit &sig_a, const RTLIL::SigBit &sig_b, const std::string &src = "");
1393 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 = "");
1394 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 = "");
1395 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 = "");
1396 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 = "");
1397 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 = "");
1398 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 = "");
1399
1400 RTLIL::SigSpec Anyconst (RTLIL::IdString name, int width = 1, const std::string &src = "");
1401 RTLIL::SigSpec Anyseq (RTLIL::IdString name, int width = 1, const std::string &src = "");
1402 RTLIL::SigSpec Allconst (RTLIL::IdString name, int width = 1, const std::string &src = "");
1403 RTLIL::SigSpec Allseq (RTLIL::IdString name, int width = 1, const std::string &src = "");
1404 RTLIL::SigSpec Initstate (RTLIL::IdString name, const std::string &src = "");
1405
1406 #ifdef WITH_PYTHON
1407 static std::map<unsigned int, RTLIL::Module*> *get_all_modules(void);
1408 #endif
1409 };
1410
1411 struct RTLIL::Wire : public RTLIL::AttrObject
1412 {
1413 unsigned int hashidx_;
1414 unsigned int hash() const { return hashidx_; }
1415
1416 protected:
1417 // use module->addWire() and module->remove() to create or destroy wires
1418 friend struct RTLIL::Module;
1419 Wire();
1420 ~Wire();
1421
1422 public:
1423 // do not simply copy wires
1424 Wire(RTLIL::Wire &other) = delete;
1425 void operator=(RTLIL::Wire &other) = delete;
1426
1427 RTLIL::Module *module;
1428 RTLIL::IdString name;
1429 int width, start_offset, port_id;
1430 bool port_input, port_output, upto, is_signed;
1431
1432 #ifdef WITH_PYTHON
1433 static std::map<unsigned int, RTLIL::Wire*> *get_all_wires(void);
1434 #endif
1435 };
1436
1437 struct RTLIL::Memory : public RTLIL::AttrObject
1438 {
1439 unsigned int hashidx_;
1440 unsigned int hash() const { return hashidx_; }
1441
1442 Memory();
1443
1444 RTLIL::IdString name;
1445 int width, start_offset, size;
1446 #ifdef WITH_PYTHON
1447 ~Memory();
1448 static std::map<unsigned int, RTLIL::Memory*> *get_all_memorys(void);
1449 #endif
1450 };
1451
1452 struct RTLIL::Cell : public RTLIL::AttrObject
1453 {
1454 unsigned int hashidx_;
1455 unsigned int hash() const { return hashidx_; }
1456
1457 protected:
1458 // use module->addCell() and module->remove() to create or destroy cells
1459 friend struct RTLIL::Module;
1460 Cell();
1461 ~Cell();
1462
1463 public:
1464 // do not simply copy cells
1465 Cell(RTLIL::Cell &other) = delete;
1466 void operator=(RTLIL::Cell &other) = delete;
1467
1468 RTLIL::Module *module;
1469 RTLIL::IdString name;
1470 RTLIL::IdString type;
1471 dict<RTLIL::IdString, RTLIL::SigSpec> connections_;
1472 dict<RTLIL::IdString, RTLIL::Const> parameters;
1473
1474 // access cell ports
1475 bool hasPort(RTLIL::IdString portname) const;
1476 void unsetPort(RTLIL::IdString portname);
1477 void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal);
1478 const RTLIL::SigSpec &getPort(RTLIL::IdString portname) const;
1479 const dict<RTLIL::IdString, RTLIL::SigSpec> &connections() const;
1480
1481 // information about cell ports
1482 bool known() const;
1483 bool input(RTLIL::IdString portname) const;
1484 bool output(RTLIL::IdString portname) const;
1485
1486 // access cell parameters
1487 bool hasParam(RTLIL::IdString paramname) const;
1488 void unsetParam(RTLIL::IdString paramname);
1489 void setParam(RTLIL::IdString paramname, RTLIL::Const value);
1490 const RTLIL::Const &getParam(RTLIL::IdString paramname) const;
1491
1492 void sort();
1493 void check();
1494 void fixup_parameters(bool set_a_signed = false, bool set_b_signed = false);
1495
1496 bool has_keep_attr() const {
1497 return get_bool_attribute(ID::keep) || (module && module->design && module->design->module(type) &&
1498 module->design->module(type)->get_bool_attribute(ID::keep));
1499 }
1500
1501 template<typename T> void rewrite_sigspecs(T &functor);
1502 template<typename T> void rewrite_sigspecs2(T &functor);
1503
1504 #ifdef WITH_PYTHON
1505 static std::map<unsigned int, RTLIL::Cell*> *get_all_cells(void);
1506 #endif
1507 };
1508
1509 struct RTLIL::CaseRule : public RTLIL::AttrObject
1510 {
1511 std::vector<RTLIL::SigSpec> compare;
1512 std::vector<RTLIL::SigSig> actions;
1513 std::vector<RTLIL::SwitchRule*> switches;
1514
1515 ~CaseRule();
1516 void optimize();
1517
1518 bool empty() const;
1519
1520 template<typename T> void rewrite_sigspecs(T &functor);
1521 template<typename T> void rewrite_sigspecs2(T &functor);
1522 RTLIL::CaseRule *clone() const;
1523 };
1524
1525 struct RTLIL::SwitchRule : public RTLIL::AttrObject
1526 {
1527 RTLIL::SigSpec signal;
1528 std::vector<RTLIL::CaseRule*> cases;
1529
1530 ~SwitchRule();
1531
1532 bool empty() const;
1533
1534 template<typename T> void rewrite_sigspecs(T &functor);
1535 template<typename T> void rewrite_sigspecs2(T &functor);
1536 RTLIL::SwitchRule *clone() const;
1537 };
1538
1539 struct RTLIL::SyncRule
1540 {
1541 RTLIL::SyncType type;
1542 RTLIL::SigSpec signal;
1543 std::vector<RTLIL::SigSig> actions;
1544
1545 template<typename T> void rewrite_sigspecs(T &functor);
1546 template<typename T> void rewrite_sigspecs2(T &functor);
1547 RTLIL::SyncRule *clone() const;
1548 };
1549
1550 struct RTLIL::Process : public RTLIL::AttrObject
1551 {
1552 RTLIL::IdString name;
1553 RTLIL::CaseRule root_case;
1554 std::vector<RTLIL::SyncRule*> syncs;
1555
1556 ~Process();
1557
1558 template<typename T> void rewrite_sigspecs(T &functor);
1559 template<typename T> void rewrite_sigspecs2(T &functor);
1560 RTLIL::Process *clone() const;
1561 };
1562
1563
1564 inline RTLIL::SigBit::SigBit() : wire(NULL), data(RTLIL::State::S0) { }
1565 inline RTLIL::SigBit::SigBit(RTLIL::State bit) : wire(NULL), data(bit) { }
1566 inline RTLIL::SigBit::SigBit(bool bit) : wire(NULL), data(bit ? State::S1 : State::S0) { }
1567 inline RTLIL::SigBit::SigBit(RTLIL::Wire *wire) : wire(wire), offset(0) { log_assert(wire && wire->width == 1); }
1568 inline RTLIL::SigBit::SigBit(RTLIL::Wire *wire, int offset) : wire(wire), offset(offset) { log_assert(wire != nullptr); }
1569 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]; }
1570 inline RTLIL::SigBit::SigBit(const RTLIL::SigChunk &chunk, int index) : wire(chunk.wire) { if (wire) offset = chunk.offset + index; else data = chunk.data[index]; }
1571
1572 inline bool RTLIL::SigBit::operator<(const RTLIL::SigBit &other) const {
1573 if (wire == other.wire)
1574 return wire ? (offset < other.offset) : (data < other.data);
1575 if (wire != nullptr && other.wire != nullptr)
1576 return wire->name < other.wire->name;
1577 return (wire != nullptr) < (other.wire != nullptr);
1578 }
1579
1580 inline bool RTLIL::SigBit::operator==(const RTLIL::SigBit &other) const {
1581 return (wire == other.wire) && (wire ? (offset == other.offset) : (data == other.data));
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 unsigned int RTLIL::SigBit::hash() const {
1589 if (wire)
1590 return mkhash_add(wire->name.hash(), offset);
1591 return data;
1592 }
1593
1594 inline RTLIL::SigBit &RTLIL::SigSpecIterator::operator*() const {
1595 return (*sig_p)[index];
1596 }
1597
1598 inline const RTLIL::SigBit &RTLIL::SigSpecConstIterator::operator*() const {
1599 return (*sig_p)[index];
1600 }
1601
1602 inline RTLIL::SigBit::SigBit(const RTLIL::SigSpec &sig) {
1603 log_assert(sig.size() == 1 && sig.chunks().size() == 1);
1604 *this = SigBit(sig.chunks().front());
1605 }
1606
1607 template<typename T>
1608 void RTLIL::Module::rewrite_sigspecs(T &functor)
1609 {
1610 for (auto &it : cells_)
1611 it.second->rewrite_sigspecs(functor);
1612 for (auto &it : processes)
1613 it.second->rewrite_sigspecs(functor);
1614 for (auto &it : connections_) {
1615 functor(it.first);
1616 functor(it.second);
1617 }
1618 }
1619
1620 template<typename T>
1621 void RTLIL::Module::rewrite_sigspecs2(T &functor)
1622 {
1623 for (auto &it : cells_)
1624 it.second->rewrite_sigspecs2(functor);
1625 for (auto &it : processes)
1626 it.second->rewrite_sigspecs2(functor);
1627 for (auto &it : connections_) {
1628 functor(it.first, it.second);
1629 }
1630 }
1631
1632 template<typename T>
1633 void RTLIL::Cell::rewrite_sigspecs(T &functor) {
1634 for (auto &it : connections_)
1635 functor(it.second);
1636 }
1637
1638 template<typename T>
1639 void RTLIL::Cell::rewrite_sigspecs2(T &functor) {
1640 for (auto &it : connections_)
1641 functor(it.second);
1642 }
1643
1644 template<typename T>
1645 void RTLIL::CaseRule::rewrite_sigspecs(T &functor) {
1646 for (auto &it : compare)
1647 functor(it);
1648 for (auto &it : actions) {
1649 functor(it.first);
1650 functor(it.second);
1651 }
1652 for (auto it : switches)
1653 it->rewrite_sigspecs(functor);
1654 }
1655
1656 template<typename T>
1657 void RTLIL::CaseRule::rewrite_sigspecs2(T &functor) {
1658 for (auto &it : compare)
1659 functor(it);
1660 for (auto &it : actions) {
1661 functor(it.first, it.second);
1662 }
1663 for (auto it : switches)
1664 it->rewrite_sigspecs2(functor);
1665 }
1666
1667 template<typename T>
1668 void RTLIL::SwitchRule::rewrite_sigspecs(T &functor)
1669 {
1670 functor(signal);
1671 for (auto it : cases)
1672 it->rewrite_sigspecs(functor);
1673 }
1674
1675 template<typename T>
1676 void RTLIL::SwitchRule::rewrite_sigspecs2(T &functor)
1677 {
1678 functor(signal);
1679 for (auto it : cases)
1680 it->rewrite_sigspecs2(functor);
1681 }
1682
1683 template<typename T>
1684 void RTLIL::SyncRule::rewrite_sigspecs(T &functor)
1685 {
1686 functor(signal);
1687 for (auto &it : actions) {
1688 functor(it.first);
1689 functor(it.second);
1690 }
1691 }
1692
1693 template<typename T>
1694 void RTLIL::SyncRule::rewrite_sigspecs2(T &functor)
1695 {
1696 functor(signal);
1697 for (auto &it : actions) {
1698 functor(it.first, it.second);
1699 }
1700 }
1701
1702 template<typename T>
1703 void RTLIL::Process::rewrite_sigspecs(T &functor)
1704 {
1705 root_case.rewrite_sigspecs(functor);
1706 for (auto it : syncs)
1707 it->rewrite_sigspecs(functor);
1708 }
1709
1710 template<typename T>
1711 void RTLIL::Process::rewrite_sigspecs2(T &functor)
1712 {
1713 root_case.rewrite_sigspecs2(functor);
1714 for (auto it : syncs)
1715 it->rewrite_sigspecs2(functor);
1716 }
1717
1718 YOSYS_NAMESPACE_END
1719
1720 #endif