2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2012 Claire Xenia Wolf <claire@yosyshq.com>
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.
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.
20 #include "kernel/yosys.h"
29 enum State
: unsigned char {
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)
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
49 enum ConstFlags
: unsigned char {
51 CONST_FLAG_STRING
= 1,
52 CONST_FLAG_SIGNED
= 2, // only used for parameters
53 CONST_FLAG_REAL
= 4 // only used for parameters
67 struct SigSpecIterator
;
68 struct SigSpecConstIterator
;
72 struct MemWriteAction
;
77 typedef std::pair
<SigSpec
, SigSpec
> SigSig
;
81 #undef YOSYS_XTRACE_GET_PUT
82 #undef YOSYS_SORT_ID_FREE_LIST
83 #undef YOSYS_USE_STICKY_IDS
84 #undef YOSYS_NO_IDS_REFCNT
86 // the global id string cache
88 static struct destruct_guard_t
{
89 bool ok
; // POD, will be initialized to zero
90 destruct_guard_t() { ok
= true; }
91 ~destruct_guard_t() { ok
= false; }
94 static std::vector
<char*> global_id_storage_
;
95 static dict
<char*, int, hash_cstr_ops
> global_id_index_
;
96 #ifndef YOSYS_NO_IDS_REFCNT
97 static std::vector
<int> global_refcount_storage_
;
98 static std::vector
<int> global_free_idx_list_
;
101 #ifdef YOSYS_USE_STICKY_IDS
102 static int last_created_idx_ptr_
;
103 static int last_created_idx_
[8];
106 static inline void xtrace_db_dump()
108 #ifdef YOSYS_XTRACE_GET_PUT
109 for (int idx
= 0; idx
< GetSize(global_id_storage_
); idx
++)
111 if (global_id_storage_
.at(idx
) == nullptr)
112 log("#X# DB-DUMP index %d: FREE\n", idx
);
114 log("#X# DB-DUMP index %d: '%s' (ref %d)\n", idx
, global_id_storage_
.at(idx
), global_refcount_storage_
.at(idx
));
119 static inline void checkpoint()
121 #ifdef YOSYS_USE_STICKY_IDS
122 last_created_idx_ptr_
= 0;
123 for (int i
= 0; i
< 8; i
++) {
124 if (last_created_idx_
[i
])
125 put_reference(last_created_idx_
[i
]);
126 last_created_idx_
[i
] = 0;
129 #ifdef YOSYS_SORT_ID_FREE_LIST
130 std::sort(global_free_idx_list_
.begin(), global_free_idx_list_
.end(), std::greater
<int>());
134 static inline int get_reference(int idx
)
137 #ifndef YOSYS_NO_IDS_REFCNT
138 global_refcount_storage_
[idx
]++;
140 #ifdef YOSYS_XTRACE_GET_PUT
142 log("#X# GET-BY-INDEX '%s' (index %d, refcount %d)\n", global_id_storage_
.at(idx
), idx
, global_refcount_storage_
.at(idx
));
148 static int get_reference(const char *p
)
150 log_assert(destruct_guard
.ok
);
155 auto it
= global_id_index_
.find((char*)p
);
156 if (it
!= global_id_index_
.end()) {
157 #ifndef YOSYS_NO_IDS_REFCNT
158 global_refcount_storage_
.at(it
->second
)++;
160 #ifdef YOSYS_XTRACE_GET_PUT
162 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
));
167 log_assert(p
[0] == '$' || p
[0] == '\\');
168 log_assert(p
[1] != 0);
169 for (const char *c
= p
; *c
; c
++)
170 if ((unsigned)*c
<= (unsigned)' ')
171 log_error("Found control character or space (0x%02hhx) in string '%s' which is not allowed in RTLIL identifiers\n", *c
, p
);
173 #ifndef YOSYS_NO_IDS_REFCNT
174 if (global_free_idx_list_
.empty()) {
175 if (global_id_storage_
.empty()) {
176 global_refcount_storage_
.push_back(0);
177 global_id_storage_
.push_back((char*)"");
178 global_id_index_
[global_id_storage_
.back()] = 0;
180 log_assert(global_id_storage_
.size() < 0x40000000);
181 global_free_idx_list_
.push_back(global_id_storage_
.size());
182 global_id_storage_
.push_back(nullptr);
183 global_refcount_storage_
.push_back(0);
186 int idx
= global_free_idx_list_
.back();
187 global_free_idx_list_
.pop_back();
188 global_id_storage_
.at(idx
) = strdup(p
);
189 global_id_index_
[global_id_storage_
.at(idx
)] = idx
;
190 global_refcount_storage_
.at(idx
)++;
192 if (global_id_storage_
.empty()) {
193 global_id_storage_
.push_back((char*)"");
194 global_id_index_
[global_id_storage_
.back()] = 0;
196 int idx
= global_id_storage_
.size();
197 global_id_storage_
.push_back(strdup(p
));
198 global_id_index_
[global_id_storage_
.back()] = idx
;
202 log("#X# New IdString '%s' with index %d.\n", p
, idx
);
203 log_backtrace("-X- ", yosys_xtrace
-1);
206 #ifdef YOSYS_XTRACE_GET_PUT
208 log("#X# GET-BY-NAME '%s' (index %d, refcount %d)\n", global_id_storage_
.at(idx
), idx
, global_refcount_storage_
.at(idx
));
211 #ifdef YOSYS_USE_STICKY_IDS
212 // Avoid Create->Delete->Create pattern
213 if (last_created_idx_
[last_created_idx_ptr_
])
214 put_reference(last_created_idx_
[last_created_idx_ptr_
]);
215 last_created_idx_
[last_created_idx_ptr_
] = idx
;
216 get_reference(last_created_idx_
[last_created_idx_ptr_
]);
217 last_created_idx_ptr_
= (last_created_idx_ptr_
+ 1) & 7;
223 #ifndef YOSYS_NO_IDS_REFCNT
224 static inline void put_reference(int idx
)
226 // put_reference() may be called from destructors after the destructor of
227 // global_refcount_storage_ has been run. in this case we simply do nothing.
228 if (!destruct_guard
.ok
|| !idx
)
231 #ifdef YOSYS_XTRACE_GET_PUT
233 log("#X# PUT '%s' (index %d, refcount %d)\n", global_id_storage_
.at(idx
), idx
, global_refcount_storage_
.at(idx
));
237 int &refcount
= global_refcount_storage_
[idx
];
242 log_assert(refcount
== 0);
245 static inline void free_reference(int idx
)
248 log("#X# Removed IdString '%s' with index %d.\n", global_id_storage_
.at(idx
), idx
);
249 log_backtrace("-X- ", yosys_xtrace
-1);
252 global_id_index_
.erase(global_id_storage_
.at(idx
));
253 free(global_id_storage_
.at(idx
));
254 global_id_storage_
.at(idx
) = nullptr;
255 global_free_idx_list_
.push_back(idx
);
258 static inline void put_reference(int) { }
261 // the actual IdString object is just is a single int
265 inline IdString() : index_(0) { }
266 inline IdString(const char *str
) : index_(get_reference(str
)) { }
267 inline IdString(const IdString
&str
) : index_(get_reference(str
.index_
)) { }
268 inline IdString(IdString
&&str
) : index_(str
.index_
) { str
.index_
= 0; }
269 inline IdString(const std::string
&str
) : index_(get_reference(str
.c_str())) { }
270 inline ~IdString() { put_reference(index_
); }
272 inline void operator=(const IdString
&rhs
) {
273 put_reference(index_
);
274 index_
= get_reference(rhs
.index_
);
277 inline void operator=(const char *rhs
) {
282 inline void operator=(const std::string
&rhs
) {
287 inline const char *c_str() const {
288 return global_id_storage_
.at(index_
);
291 inline std::string
str() const {
292 return std::string(global_id_storage_
.at(index_
));
295 inline bool operator<(const IdString
&rhs
) const {
296 return index_
< rhs
.index_
;
299 inline bool operator==(const IdString
&rhs
) const { return index_
== rhs
.index_
; }
300 inline bool operator!=(const IdString
&rhs
) const { return index_
!= rhs
.index_
; }
302 // The methods below are just convenience functions for better compatibility with std::string.
304 bool operator==(const std::string
&rhs
) const { return c_str() == rhs
; }
305 bool operator!=(const std::string
&rhs
) const { return c_str() != rhs
; }
307 bool operator==(const char *rhs
) const { return strcmp(c_str(), rhs
) == 0; }
308 bool operator!=(const char *rhs
) const { return strcmp(c_str(), rhs
) != 0; }
310 char operator[](size_t i
) const {
311 const char *p
= c_str();
312 for (; i
!= 0; i
--, p
++)
317 std::string
substr(size_t pos
= 0, size_t len
= std::string::npos
) const {
318 if (len
== std::string::npos
|| len
>= strlen(c_str() + pos
))
319 return std::string(c_str() + pos
);
321 return std::string(c_str() + pos
, len
);
324 int compare(size_t pos
, size_t len
, const char* s
) const {
325 return strncmp(c_str()+pos
, s
, len
);
328 bool begins_with(const char* prefix
) const {
329 size_t len
= strlen(prefix
);
330 if (size() < len
) return false;
331 return compare(0, len
, prefix
) == 0;
334 bool ends_with(const char* suffix
) const {
335 size_t len
= strlen(suffix
);
336 if (size() < len
) return false;
337 return compare(size()-len
, len
, suffix
) == 0;
340 bool contains(const char* str
) const {
341 return strstr(c_str(), str
);
344 size_t size() const {
345 return strlen(c_str());
349 return c_str()[0] == 0;
356 unsigned int hash() const {
360 // The following is a helper key_compare class. Instead of for example std::set<Cell*>
361 // use std::set<Cell*, IdString::compare_ptr_by_name<Cell>> if the order of cells in the
362 // set has an influence on the algorithm.
364 template<typename T
> struct compare_ptr_by_name
{
365 bool operator()(const T
*a
, const T
*b
) const {
366 return (a
== nullptr || b
== nullptr) ? (a
< b
) : (a
->name
< b
->name
);
370 // often one needs to check if a given IdString is part of a list (for example a list
371 // of cell types). the following functions helps with that.
373 template<typename
... Args
>
374 bool in(Args
... args
) const {
375 // Credit: https://articles.emptycrate.com/2016/05/14/folds_in_cpp11_ish.html
377 (void) std::initializer_list
<int>{ (result
= result
|| in(args
), 0)... };
381 bool in(const IdString
&rhs
) const { return *this == rhs
; }
382 bool in(const char *rhs
) const { return *this == rhs
; }
383 bool in(const std::string
&rhs
) const { return *this == rhs
; }
384 bool in(const pool
<IdString
> &rhs
) const { return rhs
.count(*this) != 0; }
386 bool isPublic() const { return begins_with("\\"); }
390 #define X(_id) extern IdString _id;
391 #include "kernel/constids.inc"
395 extern dict
<std::string
, std::string
> constpad
;
397 const pool
<IdString
> &builtin_ff_cell_types();
399 static inline std::string
escape_id(const std::string
&str
) {
400 if (str
.size() > 0 && str
[0] != '\\' && str
[0] != '$')
405 static inline std::string
unescape_id(const std::string
&str
) {
410 if (str
[1] == '$' || str
[1] == '\\')
412 if (str
[1] >= '0' && str
[1] <= '9')
414 return str
.substr(1);
417 static inline std::string
unescape_id(RTLIL::IdString str
) {
418 return unescape_id(str
.str());
421 static inline const char *id2cstr(RTLIL::IdString str
) {
425 template <typename T
> struct sort_by_name_id
{
426 bool operator()(T
*a
, T
*b
) const {
427 return a
->name
< b
->name
;
431 template <typename T
> struct sort_by_name_str
{
432 bool operator()(T
*a
, T
*b
) const {
433 return strcmp(a
->name
.c_str(), b
->name
.c_str()) < 0;
437 struct sort_by_id_str
{
438 bool operator()(RTLIL::IdString a
, RTLIL::IdString b
) const {
439 return strcmp(a
.c_str(), b
.c_str()) < 0;
443 // see calc.cc for the implementation of this functions
444 RTLIL::Const
const_not (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
445 RTLIL::Const
const_and (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
446 RTLIL::Const
const_or (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
447 RTLIL::Const
const_xor (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
448 RTLIL::Const
const_xnor (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
450 RTLIL::Const
const_reduce_and (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
451 RTLIL::Const
const_reduce_or (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
452 RTLIL::Const
const_reduce_xor (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
453 RTLIL::Const
const_reduce_xnor (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
454 RTLIL::Const
const_reduce_bool (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
456 RTLIL::Const
const_logic_not (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
457 RTLIL::Const
const_logic_and (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
458 RTLIL::Const
const_logic_or (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
460 RTLIL::Const
const_shl (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
461 RTLIL::Const
const_shr (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
462 RTLIL::Const
const_sshl (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
463 RTLIL::Const
const_sshr (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
464 RTLIL::Const
const_shift (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
465 RTLIL::Const
const_shiftx (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
467 RTLIL::Const
const_lt (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
468 RTLIL::Const
const_le (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
469 RTLIL::Const
const_eq (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
470 RTLIL::Const
const_ne (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
471 RTLIL::Const
const_eqx (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
472 RTLIL::Const
const_nex (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
473 RTLIL::Const
const_ge (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
474 RTLIL::Const
const_gt (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
476 RTLIL::Const
const_add (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
477 RTLIL::Const
const_sub (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
478 RTLIL::Const
const_mul (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
479 RTLIL::Const
const_div (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
480 RTLIL::Const
const_divfloor (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
481 RTLIL::Const
const_modfloor (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
482 RTLIL::Const
const_mod (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
483 RTLIL::Const
const_pow (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
485 RTLIL::Const
const_pos (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
486 RTLIL::Const
const_neg (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
489 // This iterator-range-pair is used for Design::modules(), Module::wires() and Module::cells().
490 // It maintains a reference counter that is used to make sure that the container is not modified while being iterated over.
494 using iterator_category
= std::forward_iterator_tag
;
495 using value_type
= T
;
496 using difference_type
= ptrdiff_t;
498 using reference
= T
&;
499 typename dict
<RTLIL::IdString
, T
>::iterator it
;
500 dict
<RTLIL::IdString
, T
> *list_p
;
503 ObjIterator() : list_p(nullptr), refcount_p(nullptr) {
506 ObjIterator(decltype(list_p
) list_p
, int *refcount_p
) : list_p(list_p
), refcount_p(refcount_p
) {
507 if (list_p
->empty()) {
508 this->list_p
= nullptr;
509 this->refcount_p
= nullptr;
511 it
= list_p
->begin();
516 ObjIterator(const RTLIL::ObjIterator
<T
> &other
) {
518 list_p
= other
.list_p
;
519 refcount_p
= other
.refcount_p
;
524 ObjIterator
&operator=(const RTLIL::ObjIterator
<T
> &other
) {
528 list_p
= other
.list_p
;
529 refcount_p
= other
.refcount_p
;
540 inline T
operator*() const {
541 log_assert(list_p
!= nullptr);
545 inline bool operator!=(const RTLIL::ObjIterator
<T
> &other
) const {
546 if (list_p
== nullptr || other
.list_p
== nullptr)
547 return list_p
!= other
.list_p
;
548 return it
!= other
.it
;
552 inline bool operator==(const RTLIL::ObjIterator
<T
> &other
) const {
553 return !(*this != other
);
556 inline ObjIterator
<T
>& operator++() {
557 log_assert(list_p
!= nullptr);
558 if (++it
== list_p
->end()) {
561 refcount_p
= nullptr;
566 inline ObjIterator
<T
>& operator+=(int amt
) {
567 log_assert(list_p
!= nullptr);
569 if (it
== list_p
->end()) {
572 refcount_p
= nullptr;
577 inline ObjIterator
<T
> operator+(int amt
) {
578 log_assert(list_p
!= nullptr);
579 ObjIterator
<T
> new_obj(*this);
581 if (new_obj
.it
== list_p
->end()) {
582 (*(new_obj
.refcount_p
))--;
583 new_obj
.list_p
= nullptr;
584 new_obj
.refcount_p
= nullptr;
589 inline const ObjIterator
<T
> operator++(int) {
590 ObjIterator
<T
> result(*this);
599 dict
<RTLIL::IdString
, T
> *list_p
;
602 ObjRange(decltype(list_p
) list_p
, int *refcount_p
) : list_p(list_p
), refcount_p(refcount_p
) { }
603 RTLIL::ObjIterator
<T
> begin() { return RTLIL::ObjIterator
<T
>(list_p
, refcount_p
); }
604 RTLIL::ObjIterator
<T
> end() { return RTLIL::ObjIterator
<T
>(); }
606 size_t size() const {
607 return list_p
->size();
610 operator pool
<T
>() const {
612 for (auto &it
: *list_p
)
613 result
.insert(it
.second
);
617 operator std::vector
<T
>() const {
618 std::vector
<T
> result
;
619 result
.reserve(list_p
->size());
620 for (auto &it
: *list_p
)
621 result
.push_back(it
.second
);
625 pool
<T
> to_pool() const { return *this; }
626 std::vector
<T
> to_vector() const { return *this; }
633 std::vector
<RTLIL::State
> bits
;
636 Const(std::string str
);
637 Const(int val
, int width
= 32);
638 Const(RTLIL::State bit
, int width
= 1);
639 Const(const std::vector
<RTLIL::State
> &bits
) : bits(bits
) { flags
= CONST_FLAG_NONE
; }
640 Const(const std::vector
<bool> &bits
);
641 Const(const RTLIL::Const
&c
);
642 RTLIL::Const
&operator =(const RTLIL::Const
&other
) = default;
644 bool operator <(const RTLIL::Const
&other
) const;
645 bool operator ==(const RTLIL::Const
&other
) const;
646 bool operator !=(const RTLIL::Const
&other
) const;
648 bool as_bool() const;
649 int as_int(bool is_signed
= false) const;
650 std::string
as_string() const;
651 static Const
from_string(const std::string
&str
);
653 std::string
decode_string() const;
655 inline int size() const { return bits
.size(); }
656 inline bool empty() const { return bits
.empty(); }
657 inline RTLIL::State
&operator[](int index
) { return bits
.at(index
); }
658 inline const RTLIL::State
&operator[](int index
) const { return bits
.at(index
); }
659 inline decltype(bits
)::iterator
begin() { return bits
.begin(); }
660 inline decltype(bits
)::iterator
end() { return bits
.end(); }
662 bool is_fully_zero() const;
663 bool is_fully_ones() const;
664 bool is_fully_def() const;
665 bool is_fully_undef() const;
666 bool is_onehot(int *pos
= nullptr) const;
668 inline RTLIL::Const
extract(int offset
, int len
= 1, RTLIL::State padding
= RTLIL::State::S0
) const {
670 ret
.bits
.reserve(len
);
671 for (int i
= offset
; i
< offset
+ len
; i
++)
672 ret
.bits
.push_back(i
< GetSize(bits
) ? bits
[i
] : padding
);
676 void extu(int width
) {
677 bits
.resize(width
, RTLIL::State::S0
);
680 void exts(int width
) {
681 bits
.resize(width
, bits
.empty() ? RTLIL::State::Sx
: bits
.back());
684 inline unsigned int hash() const {
685 unsigned int h
= mkhash_init
;
692 struct RTLIL::AttrObject
694 dict
<RTLIL::IdString
, RTLIL::Const
> attributes
;
696 bool has_attribute(RTLIL::IdString id
) const;
698 void set_bool_attribute(RTLIL::IdString id
, bool value
=true);
699 bool get_bool_attribute(RTLIL::IdString id
) const;
701 bool get_blackbox_attribute(bool ignore_wb
=false) const {
702 return get_bool_attribute(ID::blackbox
) || (!ignore_wb
&& get_bool_attribute(ID::whitebox
));
705 void set_string_attribute(RTLIL::IdString id
, string value
);
706 string
get_string_attribute(RTLIL::IdString id
) const;
708 void set_strpool_attribute(RTLIL::IdString id
, const pool
<string
> &data
);
709 void add_strpool_attribute(RTLIL::IdString id
, const pool
<string
> &data
);
710 pool
<string
> get_strpool_attribute(RTLIL::IdString id
) const;
712 void set_src_attribute(const std::string
&src
) {
713 set_string_attribute(ID::src
, src
);
715 std::string
get_src_attribute() const {
716 return get_string_attribute(ID::src
);
719 void set_hdlname_attribute(const vector
<string
> &hierarchy
);
720 vector
<string
> get_hdlname_attribute() const;
723 struct RTLIL::SigChunk
726 std::vector
<RTLIL::State
> data
; // only used if wire == NULL, LSB at index 0
730 SigChunk(const RTLIL::Const
&value
);
731 SigChunk(RTLIL::Wire
*wire
);
732 SigChunk(RTLIL::Wire
*wire
, int offset
, int width
= 1);
733 SigChunk(const std::string
&str
);
734 SigChunk(int val
, int width
= 32);
735 SigChunk(RTLIL::State bit
, int width
= 1);
736 SigChunk(const RTLIL::SigBit
&bit
);
737 SigChunk(const RTLIL::SigChunk
&sigchunk
);
738 RTLIL::SigChunk
&operator =(const RTLIL::SigChunk
&other
) = default;
740 RTLIL::SigChunk
extract(int offset
, int length
) const;
741 inline int size() const { return width
; }
742 inline bool is_wire() const { return wire
!= NULL
; }
744 bool operator <(const RTLIL::SigChunk
&other
) const;
745 bool operator ==(const RTLIL::SigChunk
&other
) const;
746 bool operator !=(const RTLIL::SigChunk
&other
) const;
753 RTLIL::State data
; // used if wire == NULL
754 int offset
; // used if wire != NULL
758 SigBit(RTLIL::State bit
);
759 explicit SigBit(bool bit
);
760 SigBit(RTLIL::Wire
*wire
);
761 SigBit(RTLIL::Wire
*wire
, int offset
);
762 SigBit(const RTLIL::SigChunk
&chunk
);
763 SigBit(const RTLIL::SigChunk
&chunk
, int index
);
764 SigBit(const RTLIL::SigSpec
&sig
);
765 SigBit(const RTLIL::SigBit
&sigbit
) = default;
766 RTLIL::SigBit
&operator =(const RTLIL::SigBit
&other
) = default;
768 inline bool is_wire() const { return wire
!= NULL
; }
770 bool operator <(const RTLIL::SigBit
&other
) const;
771 bool operator ==(const RTLIL::SigBit
&other
) const;
772 bool operator !=(const RTLIL::SigBit
&other
) const;
773 unsigned int hash() const;
776 struct RTLIL::SigSpecIterator
: public std::iterator
<std::input_iterator_tag
, RTLIL::SigSpec
>
778 RTLIL::SigSpec
*sig_p
;
781 inline RTLIL::SigBit
&operator*() const;
782 inline bool operator!=(const RTLIL::SigSpecIterator
&other
) const { return index
!= other
.index
; }
783 inline bool operator==(const RTLIL::SigSpecIterator
&other
) const { return index
== other
.index
; }
784 inline void operator++() { index
++; }
787 struct RTLIL::SigSpecConstIterator
: public std::iterator
<std::input_iterator_tag
, RTLIL::SigSpec
>
789 const RTLIL::SigSpec
*sig_p
;
792 inline const RTLIL::SigBit
&operator*() const;
793 inline bool operator!=(const RTLIL::SigSpecConstIterator
&other
) const { return index
!= other
.index
; }
794 inline bool operator==(const RTLIL::SigSpecIterator
&other
) const { return index
== other
.index
; }
795 inline void operator++() { index
++; }
798 struct RTLIL::SigSpec
803 std::vector
<RTLIL::SigChunk
> chunks_
; // LSB at index 0
804 std::vector
<RTLIL::SigBit
> bits_
; // LSB at index 0
808 void updhash() const;
810 inline bool packed() const {
811 return bits_
.empty();
814 inline void inline_unpack() const {
815 if (!chunks_
.empty())
819 // Only used by Module::remove(const pool<Wire*> &wires)
820 // but cannot be more specific as it isn't yet declared
821 friend struct RTLIL::Module
;
825 SigSpec(const RTLIL::SigSpec
&other
);
826 SigSpec(std::initializer_list
<RTLIL::SigSpec
> parts
);
827 RTLIL::SigSpec
&operator=(const RTLIL::SigSpec
&other
);
829 SigSpec(const RTLIL::Const
&value
);
830 SigSpec(const RTLIL::SigChunk
&chunk
);
831 SigSpec(RTLIL::Wire
*wire
);
832 SigSpec(RTLIL::Wire
*wire
, int offset
, int width
= 1);
833 SigSpec(const std::string
&str
);
834 SigSpec(int val
, int width
= 32);
835 SigSpec(RTLIL::State bit
, int width
= 1);
836 SigSpec(const RTLIL::SigBit
&bit
, int width
= 1);
837 SigSpec(const std::vector
<RTLIL::SigChunk
> &chunks
);
838 SigSpec(const std::vector
<RTLIL::SigBit
> &bits
);
839 SigSpec(const pool
<RTLIL::SigBit
> &bits
);
840 SigSpec(const std::set
<RTLIL::SigBit
> &bits
);
841 explicit SigSpec(bool bit
);
843 SigSpec(RTLIL::SigSpec
&&other
) {
844 width_
= other
.width_
;
846 chunks_
= std::move(other
.chunks_
);
847 bits_
= std::move(other
.bits_
);
850 const RTLIL::SigSpec
&operator=(RTLIL::SigSpec
&&other
) {
851 width_
= other
.width_
;
853 chunks_
= std::move(other
.chunks_
);
854 bits_
= std::move(other
.bits_
);
858 size_t get_hash() const {
863 inline const std::vector
<RTLIL::SigChunk
> &chunks() const { pack(); return chunks_
; }
864 inline const std::vector
<RTLIL::SigBit
> &bits() const { inline_unpack(); return bits_
; }
866 inline int size() const { return width_
; }
867 inline bool empty() const { return width_
== 0; }
869 inline RTLIL::SigBit
&operator[](int index
) { inline_unpack(); return bits_
.at(index
); }
870 inline const RTLIL::SigBit
&operator[](int index
) const { inline_unpack(); return bits_
.at(index
); }
872 inline RTLIL::SigSpecIterator
begin() { RTLIL::SigSpecIterator it
; it
.sig_p
= this; it
.index
= 0; return it
; }
873 inline RTLIL::SigSpecIterator
end() { RTLIL::SigSpecIterator it
; it
.sig_p
= this; it
.index
= width_
; return it
; }
875 inline RTLIL::SigSpecConstIterator
begin() const { RTLIL::SigSpecConstIterator it
; it
.sig_p
= this; it
.index
= 0; return it
; }
876 inline RTLIL::SigSpecConstIterator
end() const { RTLIL::SigSpecConstIterator it
; it
.sig_p
= this; it
.index
= width_
; return it
; }
879 void sort_and_unify();
881 void replace(const RTLIL::SigSpec
&pattern
, const RTLIL::SigSpec
&with
);
882 void replace(const RTLIL::SigSpec
&pattern
, const RTLIL::SigSpec
&with
, RTLIL::SigSpec
*other
) const;
884 void replace(const dict
<RTLIL::SigBit
, RTLIL::SigBit
> &rules
);
885 void replace(const dict
<RTLIL::SigBit
, RTLIL::SigBit
> &rules
, RTLIL::SigSpec
*other
) const;
887 void replace(const std::map
<RTLIL::SigBit
, RTLIL::SigBit
> &rules
);
888 void replace(const std::map
<RTLIL::SigBit
, RTLIL::SigBit
> &rules
, RTLIL::SigSpec
*other
) const;
890 void replace(int offset
, const RTLIL::SigSpec
&with
);
892 void remove(const RTLIL::SigSpec
&pattern
);
893 void remove(const RTLIL::SigSpec
&pattern
, RTLIL::SigSpec
*other
) const;
894 void remove2(const RTLIL::SigSpec
&pattern
, RTLIL::SigSpec
*other
);
896 void remove(const pool
<RTLIL::SigBit
> &pattern
);
897 void remove(const pool
<RTLIL::SigBit
> &pattern
, RTLIL::SigSpec
*other
) const;
898 void remove2(const pool
<RTLIL::SigBit
> &pattern
, RTLIL::SigSpec
*other
);
899 void remove2(const std::set
<RTLIL::SigBit
> &pattern
, RTLIL::SigSpec
*other
);
901 void remove(int offset
, int length
= 1);
904 RTLIL::SigSpec
extract(const RTLIL::SigSpec
&pattern
, const RTLIL::SigSpec
*other
= NULL
) const;
905 RTLIL::SigSpec
extract(const pool
<RTLIL::SigBit
> &pattern
, const RTLIL::SigSpec
*other
= NULL
) const;
906 RTLIL::SigSpec
extract(int offset
, int length
= 1) const;
907 RTLIL::SigSpec
extract_end(int offset
) const { return extract(offset
, width_
- offset
); }
909 void append(const RTLIL::SigSpec
&signal
);
910 inline void append(Wire
*wire
) { append(RTLIL::SigSpec(wire
)); }
911 inline void append(const RTLIL::SigChunk
&chunk
) { append(RTLIL::SigSpec(chunk
)); }
912 inline void append(const RTLIL::Const
&const_
) { append(RTLIL::SigSpec(const_
)); }
914 void append(const RTLIL::SigBit
&bit
);
915 inline void append(RTLIL::State state
) { append(RTLIL::SigBit(state
)); }
916 inline void append(bool bool_
) { append(RTLIL::SigBit(bool_
)); }
918 void extend_u0(int width
, bool is_signed
= false);
920 RTLIL::SigSpec
repeat(int num
) const;
922 void reverse() { inline_unpack(); std::reverse(bits_
.begin(), bits_
.end()); }
924 bool operator <(const RTLIL::SigSpec
&other
) const;
925 bool operator ==(const RTLIL::SigSpec
&other
) const;
926 inline bool operator !=(const RTLIL::SigSpec
&other
) const { return !(*this == other
); }
928 bool is_wire() const;
929 bool is_chunk() const;
930 inline bool is_bit() const { return width_
== 1; }
932 bool is_fully_const() const;
933 bool is_fully_zero() const;
934 bool is_fully_ones() const;
935 bool is_fully_def() const;
936 bool is_fully_undef() const;
937 bool has_const() const;
938 bool has_marked_bits() const;
939 bool is_onehot(int *pos
= nullptr) const;
941 bool as_bool() const;
942 int as_int(bool is_signed
= false) const;
943 std::string
as_string() const;
944 RTLIL::Const
as_const() const;
945 RTLIL::Wire
*as_wire() const;
946 RTLIL::SigChunk
as_chunk() const;
947 RTLIL::SigBit
as_bit() const;
949 bool match(const char* pattern
) const;
951 std::set
<RTLIL::SigBit
> to_sigbit_set() const;
952 pool
<RTLIL::SigBit
> to_sigbit_pool() const;
953 std::vector
<RTLIL::SigBit
> to_sigbit_vector() const;
954 std::map
<RTLIL::SigBit
, RTLIL::SigBit
> to_sigbit_map(const RTLIL::SigSpec
&other
) const;
955 dict
<RTLIL::SigBit
, RTLIL::SigBit
> to_sigbit_dict(const RTLIL::SigSpec
&other
) const;
957 static bool parse(RTLIL::SigSpec
&sig
, RTLIL::Module
*module
, std::string str
);
958 static bool parse_sel(RTLIL::SigSpec
&sig
, RTLIL::Design
*design
, RTLIL::Module
*module
, std::string str
);
959 static bool parse_rhs(const RTLIL::SigSpec
&lhs
, RTLIL::SigSpec
&sig
, RTLIL::Module
*module
, std::string str
);
961 operator std::vector
<RTLIL::SigChunk
>() const { return chunks(); }
962 operator std::vector
<RTLIL::SigBit
>() const { return bits(); }
963 const RTLIL::SigBit
&at(int offset
, const RTLIL::SigBit
&defval
) { return offset
< width_
? (*this)[offset
] : defval
; }
965 unsigned int hash() const { if (!hash_
) updhash(); return hash_
; };
968 void check(Module
*mod
= nullptr) const;
970 void check(Module
*mod
= nullptr) const { }
974 struct RTLIL::Selection
977 pool
<RTLIL::IdString
> selected_modules
;
978 dict
<RTLIL::IdString
, pool
<RTLIL::IdString
>> selected_members
;
980 Selection(bool full
= true) : full_selection(full
) { }
982 bool selected_module(RTLIL::IdString mod_name
) const;
983 bool selected_whole_module(RTLIL::IdString mod_name
) const;
984 bool selected_member(RTLIL::IdString mod_name
, RTLIL::IdString memb_name
) const;
985 void optimize(RTLIL::Design
*design
);
987 template<typename T1
> void select(T1
*module
) {
988 if (!full_selection
&& selected_modules
.count(module
->name
) == 0) {
989 selected_modules
.insert(module
->name
);
990 selected_members
.erase(module
->name
);
994 template<typename T1
, typename T2
> void select(T1
*module
, T2
*member
) {
995 if (!full_selection
&& selected_modules
.count(module
->name
) == 0)
996 selected_members
[module
->name
].insert(member
->name
);
1000 return !full_selection
&& selected_modules
.empty() && selected_members
.empty();
1004 struct RTLIL::Monitor
1006 unsigned int hashidx_
;
1007 unsigned int hash() const { return hashidx_
; }
1010 static unsigned int hashidx_count
= 123456789;
1011 hashidx_count
= mkhash_xorshift(hashidx_count
);
1012 hashidx_
= hashidx_count
;
1015 virtual ~Monitor() { }
1016 virtual void notify_module_add(RTLIL::Module
*) { }
1017 virtual void notify_module_del(RTLIL::Module
*) { }
1018 virtual void notify_connect(RTLIL::Cell
*, const RTLIL::IdString
&, const RTLIL::SigSpec
&, const RTLIL::SigSpec
&) { }
1019 virtual void notify_connect(RTLIL::Module
*, const RTLIL::SigSig
&) { }
1020 virtual void notify_connect(RTLIL::Module
*, const std::vector
<RTLIL::SigSig
>&) { }
1021 virtual void notify_blackout(RTLIL::Module
*) { }
1024 // Forward declaration; defined in preproc.h.
1025 struct define_map_t
;
1027 struct RTLIL::Design
1029 unsigned int hashidx_
;
1030 unsigned int hash() const { return hashidx_
; }
1032 pool
<RTLIL::Monitor
*> monitors
;
1033 dict
<std::string
, std::string
> scratchpad
;
1035 int refcount_modules_
;
1036 dict
<RTLIL::IdString
, RTLIL::Module
*> modules_
;
1037 std::vector
<RTLIL::Binding
*> bindings_
;
1039 std::vector
<AST::AstNode
*> verilog_packages
, verilog_globals
;
1040 std::unique_ptr
<define_map_t
> verilog_defines
;
1042 std::vector
<RTLIL::Selection
> selection_stack
;
1043 dict
<RTLIL::IdString
, RTLIL::Selection
> selection_vars
;
1044 std::string selected_active_module
;
1049 RTLIL::ObjRange
<RTLIL::Module
*> modules();
1050 RTLIL::Module
*module(RTLIL::IdString name
);
1051 const RTLIL::Module
*module(RTLIL::IdString name
) const;
1052 RTLIL::Module
*top_module();
1054 bool has(RTLIL::IdString id
) const {
1055 return modules_
.count(id
) != 0;
1058 void add(RTLIL::Module
*module
);
1059 void add(RTLIL::Binding
*binding
);
1061 RTLIL::Module
*addModule(RTLIL::IdString name
);
1062 void remove(RTLIL::Module
*module
);
1063 void rename(RTLIL::Module
*module
, RTLIL::IdString new_name
);
1065 void scratchpad_unset(const std::string
&varname
);
1067 void scratchpad_set_int(const std::string
&varname
, int value
);
1068 void scratchpad_set_bool(const std::string
&varname
, bool value
);
1069 void scratchpad_set_string(const std::string
&varname
, std::string value
);
1071 int scratchpad_get_int(const std::string
&varname
, int default_value
= 0) const;
1072 bool scratchpad_get_bool(const std::string
&varname
, bool default_value
= false) const;
1073 std::string
scratchpad_get_string(const std::string
&varname
, const std::string
&default_value
= std::string()) const;
1079 bool selected_module(RTLIL::IdString mod_name
) const;
1080 bool selected_whole_module(RTLIL::IdString mod_name
) const;
1081 bool selected_member(RTLIL::IdString mod_name
, RTLIL::IdString memb_name
) const;
1083 bool selected_module(RTLIL::Module
*mod
) const;
1084 bool selected_whole_module(RTLIL::Module
*mod
) const;
1086 RTLIL::Selection
&selection() {
1087 return selection_stack
.back();
1090 const RTLIL::Selection
&selection() const {
1091 return selection_stack
.back();
1094 bool full_selection() const {
1095 return selection_stack
.back().full_selection
;
1098 template<typename T1
> bool selected(T1
*module
) const {
1099 return selected_module(module
->name
);
1102 template<typename T1
, typename T2
> bool selected(T1
*module
, T2
*member
) const {
1103 return selected_member(module
->name
, member
->name
);
1106 template<typename T1
> void select(T1
*module
) {
1107 if (selection_stack
.size() > 0) {
1108 RTLIL::Selection
&sel
= selection_stack
.back();
1113 template<typename T1
, typename T2
> void select(T1
*module
, T2
*member
) {
1114 if (selection_stack
.size() > 0) {
1115 RTLIL::Selection
&sel
= selection_stack
.back();
1116 sel
.select(module
, member
);
1121 std::vector
<RTLIL::Module
*> selected_modules() const;
1122 std::vector
<RTLIL::Module
*> selected_whole_modules() const;
1123 std::vector
<RTLIL::Module
*> selected_whole_modules_warn(bool include_wb
= false) const;
1125 static std::map
<unsigned int, RTLIL::Design
*> *get_all_designs(void);
1129 struct RTLIL::Module
: public RTLIL::AttrObject
1131 unsigned int hashidx_
;
1132 unsigned int hash() const { return hashidx_
; }
1135 void add(RTLIL::Wire
*wire
);
1136 void add(RTLIL::Cell
*cell
);
1137 void add(RTLIL::Process
*process
);
1140 RTLIL::Design
*design
;
1141 pool
<RTLIL::Monitor
*> monitors
;
1143 int refcount_wires_
;
1144 int refcount_cells_
;
1146 dict
<RTLIL::IdString
, RTLIL::Wire
*> wires_
;
1147 dict
<RTLIL::IdString
, RTLIL::Cell
*> cells_
;
1149 std::vector
<RTLIL::SigSig
> connections_
;
1150 std::vector
<RTLIL::Binding
*> bindings_
;
1152 RTLIL::IdString name
;
1153 idict
<RTLIL::IdString
> avail_parameters
;
1154 dict
<RTLIL::IdString
, RTLIL::Const
> parameter_default_values
;
1155 dict
<RTLIL::IdString
, RTLIL::Memory
*> memories
;
1156 dict
<RTLIL::IdString
, RTLIL::Process
*> processes
;
1160 virtual RTLIL::IdString
derive(RTLIL::Design
*design
, const dict
<RTLIL::IdString
, RTLIL::Const
> ¶meters
, bool mayfail
= false);
1161 virtual RTLIL::IdString
derive(RTLIL::Design
*design
, const dict
<RTLIL::IdString
, RTLIL::Const
> ¶meters
, const dict
<RTLIL::IdString
, RTLIL::Module
*> &interfaces
, const dict
<RTLIL::IdString
, RTLIL::IdString
> &modports
, bool mayfail
= false);
1162 virtual size_t count_id(RTLIL::IdString id
);
1163 virtual void reprocess_module(RTLIL::Design
*design
, const dict
<RTLIL::IdString
, RTLIL::Module
*> &local_interfaces
);
1165 virtual void sort();
1166 virtual void check();
1167 virtual void optimize();
1168 virtual void makeblackbox();
1170 void connect(const RTLIL::SigSig
&conn
);
1171 void connect(const RTLIL::SigSpec
&lhs
, const RTLIL::SigSpec
&rhs
);
1172 void new_connections(const std::vector
<RTLIL::SigSig
> &new_conn
);
1173 const std::vector
<RTLIL::SigSig
> &connections() const;
1175 std::vector
<RTLIL::IdString
> ports
;
1178 template<typename T
> void rewrite_sigspecs(T
&functor
);
1179 template<typename T
> void rewrite_sigspecs2(T
&functor
);
1180 void cloneInto(RTLIL::Module
*new_mod
) const;
1181 virtual RTLIL::Module
*clone() const;
1183 bool has_memories() const;
1184 bool has_processes() const;
1186 bool has_memories_warn() const;
1187 bool has_processes_warn() const;
1189 std::vector
<RTLIL::Wire
*> selected_wires() const;
1190 std::vector
<RTLIL::Cell
*> selected_cells() const;
1192 template<typename T
> bool selected(T
*member
) const {
1193 return design
->selected_member(name
, member
->name
);
1196 RTLIL::Wire
* wire(RTLIL::IdString id
) {
1197 auto it
= wires_
.find(id
);
1198 return it
== wires_
.end() ? nullptr : it
->second
;
1200 RTLIL::Cell
* cell(RTLIL::IdString id
) {
1201 auto it
= cells_
.find(id
);
1202 return it
== cells_
.end() ? nullptr : it
->second
;
1205 const RTLIL::Wire
* wire(RTLIL::IdString id
) const{
1206 auto it
= wires_
.find(id
);
1207 return it
== wires_
.end() ? nullptr : it
->second
;
1209 const RTLIL::Cell
* cell(RTLIL::IdString id
) const {
1210 auto it
= cells_
.find(id
);
1211 return it
== cells_
.end() ? nullptr : it
->second
;
1214 RTLIL::ObjRange
<RTLIL::Wire
*> wires() { return RTLIL::ObjRange
<RTLIL::Wire
*>(&wires_
, &refcount_wires_
); }
1215 RTLIL::ObjRange
<RTLIL::Cell
*> cells() { return RTLIL::ObjRange
<RTLIL::Cell
*>(&cells_
, &refcount_cells_
); }
1217 void add(RTLIL::Binding
*binding
);
1219 // Removing wires is expensive. If you have to remove wires, remove them all at once.
1220 void remove(const pool
<RTLIL::Wire
*> &wires
);
1221 void remove(RTLIL::Cell
*cell
);
1222 void remove(RTLIL::Process
*process
);
1224 void rename(RTLIL::Wire
*wire
, RTLIL::IdString new_name
);
1225 void rename(RTLIL::Cell
*cell
, RTLIL::IdString new_name
);
1226 void rename(RTLIL::IdString old_name
, RTLIL::IdString new_name
);
1228 void swap_names(RTLIL::Wire
*w1
, RTLIL::Wire
*w2
);
1229 void swap_names(RTLIL::Cell
*c1
, RTLIL::Cell
*c2
);
1231 RTLIL::IdString
uniquify(RTLIL::IdString name
);
1232 RTLIL::IdString
uniquify(RTLIL::IdString name
, int &index
);
1234 RTLIL::Wire
*addWire(RTLIL::IdString name
, int width
= 1);
1235 RTLIL::Wire
*addWire(RTLIL::IdString name
, const RTLIL::Wire
*other
);
1237 RTLIL::Cell
*addCell(RTLIL::IdString name
, RTLIL::IdString type
);
1238 RTLIL::Cell
*addCell(RTLIL::IdString name
, const RTLIL::Cell
*other
);
1240 RTLIL::Memory
*addMemory(RTLIL::IdString name
, const RTLIL::Memory
*other
);
1242 RTLIL::Process
*addProcess(RTLIL::IdString name
);
1243 RTLIL::Process
*addProcess(RTLIL::IdString name
, const RTLIL::Process
*other
);
1245 // The add* methods create a cell and return the created cell. All signals must exist in advance.
1247 RTLIL::Cell
* addNot (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, bool is_signed
= false, const std::string
&src
= "");
1248 RTLIL::Cell
* addPos (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, bool is_signed
= false, const std::string
&src
= "");
1249 RTLIL::Cell
* addNeg (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, bool is_signed
= false, const std::string
&src
= "");
1251 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
= "");
1252 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
= "");
1253 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
= "");
1254 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
= "");
1256 RTLIL::Cell
* addReduceAnd (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, bool is_signed
= false, const std::string
&src
= "");
1257 RTLIL::Cell
* addReduceOr (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, bool is_signed
= false, const std::string
&src
= "");
1258 RTLIL::Cell
* addReduceXor (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, bool is_signed
= false, const std::string
&src
= "");
1259 RTLIL::Cell
* addReduceXnor (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, bool is_signed
= false, const std::string
&src
= "");
1260 RTLIL::Cell
* addReduceBool (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, bool is_signed
= false, const std::string
&src
= "");
1262 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
= "");
1263 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
= "");
1264 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
= "");
1265 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
= "");
1266 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
= "");
1267 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
= "");
1269 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
= "");
1270 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
= "");
1271 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
= "");
1272 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
= "");
1273 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
= "");
1274 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
= "");
1275 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
= "");
1276 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
= "");
1278 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
= "");
1279 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
= "");
1280 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
= "");
1281 // truncating division
1282 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
= "");
1283 // truncating modulo
1284 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
= "");
1285 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
= "");
1286 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
= "");
1287 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
= "");
1289 RTLIL::Cell
* addLogicNot (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, bool is_signed
= false, const std::string
&src
= "");
1290 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
= "");
1291 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
= "");
1293 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
= "");
1294 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
= "");
1296 RTLIL::Cell
* addSlice (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, RTLIL::Const offset
, const std::string
&src
= "");
1297 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
= "");
1298 RTLIL::Cell
* addLut (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, RTLIL::Const lut
, const std::string
&src
= "");
1299 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
= "");
1300 RTLIL::Cell
* addAssert (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_en
, const std::string
&src
= "");
1301 RTLIL::Cell
* addAssume (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_en
, const std::string
&src
= "");
1302 RTLIL::Cell
* addLive (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_en
, const std::string
&src
= "");
1303 RTLIL::Cell
* addFair (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_en
, const std::string
&src
= "");
1304 RTLIL::Cell
* addCover (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_en
, const std::string
&src
= "");
1305 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
= "");
1307 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
= "");
1308 RTLIL::Cell
* addFf (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_d
, const RTLIL::SigSpec
&sig_q
, const std::string
&src
= "");
1309 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
= "");
1310 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
= "");
1311 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
= "");
1312 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
= "");
1313 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
= "");
1314 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
= "");
1315 RTLIL::Cell
* addAldff (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_clk
, const RTLIL::SigSpec
&sig_aload
, const RTLIL::SigSpec
&sig_d
, const RTLIL::SigSpec
&sig_q
, const RTLIL::SigSpec
&sig_ad
, bool clk_polarity
= true, bool aload_polarity
= true, const std::string
&src
= "");
1316 RTLIL::Cell
* addAldffe (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_clk
, const RTLIL::SigSpec
&sig_en
, const RTLIL::SigSpec
&sig_aload
, const RTLIL::SigSpec
&sig_d
, const RTLIL::SigSpec
&sig_q
, const RTLIL::SigSpec
&sig_ad
, bool clk_polarity
= true, bool en_polarity
= true, bool aload_polarity
= true, const std::string
&src
= "");
1317 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
= "");
1318 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
= "");
1319 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
= "");
1320 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
= "");
1321 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
= "");
1322 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
= "");
1324 RTLIL::Cell
* addBufGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_y
, const std::string
&src
= "");
1325 RTLIL::Cell
* addNotGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_y
, const std::string
&src
= "");
1326 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
= "");
1327 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
= "");
1328 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
= "");
1329 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
= "");
1330 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
= "");
1331 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
= "");
1332 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
= "");
1333 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
= "");
1334 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
= "");
1335 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
= "");
1336 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
= "");
1337 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
= "");
1338 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
= "");
1339 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
= "");
1341 RTLIL::Cell
* addSrGate (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_set
, const RTLIL::SigSpec
&sig_clr
,
1342 const RTLIL::SigSpec
&sig_q
, bool set_polarity
= true, bool clr_polarity
= true, const std::string
&src
= "");
1343 RTLIL::Cell
* addFfGate (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_d
, const RTLIL::SigSpec
&sig_q
, const std::string
&src
= "");
1344 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
= "");
1345 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
= "");
1346 RTLIL::Cell
* addDffsrGate (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_clk
, const RTLIL::SigSpec
&sig_set
, const RTLIL::SigSpec
&sig_clr
,
1347 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
= "");
1348 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
,
1349 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
= "");
1350 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
,
1351 bool arst_value
= false, bool clk_polarity
= true, bool arst_polarity
= true, const std::string
&src
= "");
1352 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
,
1353 bool arst_value
= false, bool clk_polarity
= true, bool en_polarity
= true, bool arst_polarity
= true, const std::string
&src
= "");
1354 RTLIL::Cell
* addAldffGate (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_clk
, const RTLIL::SigSpec
&sig_aload
, const RTLIL::SigSpec
&sig_d
, const RTLIL::SigSpec
&sig_q
,
1355 const RTLIL::SigSpec
&sig_ad
, bool clk_polarity
= true, bool aload_polarity
= true, const std::string
&src
= "");
1356 RTLIL::Cell
* addAldffeGate (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_clk
, const RTLIL::SigSpec
&sig_en
, const RTLIL::SigSpec
&sig_aload
, const RTLIL::SigSpec
&sig_d
, const RTLIL::SigSpec
&sig_q
,
1357 const RTLIL::SigSpec
&sig_ad
, bool clk_polarity
= true, bool en_polarity
= true, bool aload_polarity
= true, const std::string
&src
= "");
1358 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
,
1359 bool srst_value
= false, bool clk_polarity
= true, bool srst_polarity
= true, const std::string
&src
= "");
1360 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
,
1361 bool srst_value
= false, bool clk_polarity
= true, bool en_polarity
= true, bool srst_polarity
= true, const std::string
&src
= "");
1362 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
,
1363 bool srst_value
= false, bool clk_polarity
= true, bool en_polarity
= true, bool srst_polarity
= true, const std::string
&src
= "");
1364 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
= "");
1365 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
,
1366 bool arst_value
= false, bool en_polarity
= true, bool arst_polarity
= true, const std::string
&src
= "");
1367 RTLIL::Cell
* addDlatchsrGate (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_en
, const RTLIL::SigSpec
&sig_set
, const RTLIL::SigSpec
&sig_clr
,
1368 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
= "");
1370 // The methods without the add* prefix create a cell and an output signal. They return the newly created output signal.
1372 RTLIL::SigSpec
Not (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, bool is_signed
= false, const std::string
&src
= "");
1373 RTLIL::SigSpec
Pos (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, bool is_signed
= false, const std::string
&src
= "");
1374 RTLIL::SigSpec
Neg (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, bool is_signed
= false, const std::string
&src
= "");
1376 RTLIL::SigSpec
And (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1377 RTLIL::SigSpec
Or (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1378 RTLIL::SigSpec
Xor (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1379 RTLIL::SigSpec
Xnor (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1381 RTLIL::SigSpec
ReduceAnd (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, bool is_signed
= false, const std::string
&src
= "");
1382 RTLIL::SigSpec
ReduceOr (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, bool is_signed
= false, const std::string
&src
= "");
1383 RTLIL::SigSpec
ReduceXor (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, bool is_signed
= false, const std::string
&src
= "");
1384 RTLIL::SigSpec
ReduceXnor (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, bool is_signed
= false, const std::string
&src
= "");
1385 RTLIL::SigSpec
ReduceBool (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, bool is_signed
= false, const std::string
&src
= "");
1387 RTLIL::SigSpec
Shl (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1388 RTLIL::SigSpec
Shr (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1389 RTLIL::SigSpec
Sshl (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1390 RTLIL::SigSpec
Sshr (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1391 RTLIL::SigSpec
Shift (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1392 RTLIL::SigSpec
Shiftx (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1394 RTLIL::SigSpec
Lt (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1395 RTLIL::SigSpec
Le (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1396 RTLIL::SigSpec
Eq (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1397 RTLIL::SigSpec
Ne (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1398 RTLIL::SigSpec
Eqx (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1399 RTLIL::SigSpec
Nex (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1400 RTLIL::SigSpec
Ge (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1401 RTLIL::SigSpec
Gt (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1403 RTLIL::SigSpec
Add (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1404 RTLIL::SigSpec
Sub (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1405 RTLIL::SigSpec
Mul (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1406 // truncating division
1407 RTLIL::SigSpec
Div (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1408 // truncating modulo
1409 RTLIL::SigSpec
Mod (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1410 RTLIL::SigSpec
DivFloor (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1411 RTLIL::SigSpec
ModFloor (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1412 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
= "");
1414 RTLIL::SigSpec
LogicNot (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, bool is_signed
= false, const std::string
&src
= "");
1415 RTLIL::SigSpec
LogicAnd (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1416 RTLIL::SigSpec
LogicOr (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1418 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
= "");
1419 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
= "");
1421 RTLIL::SigBit
BufGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const std::string
&src
= "");
1422 RTLIL::SigBit
NotGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const std::string
&src
= "");
1423 RTLIL::SigBit
AndGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_b
, const std::string
&src
= "");
1424 RTLIL::SigBit
NandGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_b
, const std::string
&src
= "");
1425 RTLIL::SigBit
OrGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_b
, const std::string
&src
= "");
1426 RTLIL::SigBit
NorGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_b
, const std::string
&src
= "");
1427 RTLIL::SigBit
XorGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_b
, const std::string
&src
= "");
1428 RTLIL::SigBit
XnorGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_b
, const std::string
&src
= "");
1429 RTLIL::SigBit
AndnotGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_b
, const std::string
&src
= "");
1430 RTLIL::SigBit
OrnotGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_b
, const std::string
&src
= "");
1431 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
= "");
1432 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
= "");
1433 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
= "");
1434 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
= "");
1435 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
= "");
1436 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
= "");
1438 RTLIL::SigSpec
Anyconst (RTLIL::IdString name
, int width
= 1, const std::string
&src
= "");
1439 RTLIL::SigSpec
Anyseq (RTLIL::IdString name
, int width
= 1, const std::string
&src
= "");
1440 RTLIL::SigSpec
Allconst (RTLIL::IdString name
, int width
= 1, const std::string
&src
= "");
1441 RTLIL::SigSpec
Allseq (RTLIL::IdString name
, int width
= 1, const std::string
&src
= "");
1442 RTLIL::SigSpec
Initstate (RTLIL::IdString name
, const std::string
&src
= "");
1445 static std::map
<unsigned int, RTLIL::Module
*> *get_all_modules(void);
1449 struct RTLIL::Wire
: public RTLIL::AttrObject
1451 unsigned int hashidx_
;
1452 unsigned int hash() const { return hashidx_
; }
1455 // use module->addWire() and module->remove() to create or destroy wires
1456 friend struct RTLIL::Module
;
1461 // do not simply copy wires
1462 Wire(RTLIL::Wire
&other
) = delete;
1463 void operator=(RTLIL::Wire
&other
) = delete;
1465 RTLIL::Module
*module
;
1466 RTLIL::IdString name
;
1467 int width
, start_offset
, port_id
;
1468 bool port_input
, port_output
, upto
, is_signed
;
1471 static std::map
<unsigned int, RTLIL::Wire
*> *get_all_wires(void);
1475 struct RTLIL::Memory
: public RTLIL::AttrObject
1477 unsigned int hashidx_
;
1478 unsigned int hash() const { return hashidx_
; }
1482 RTLIL::IdString name
;
1483 int width
, start_offset
, size
;
1486 static std::map
<unsigned int, RTLIL::Memory
*> *get_all_memorys(void);
1490 struct RTLIL::Cell
: public RTLIL::AttrObject
1492 unsigned int hashidx_
;
1493 unsigned int hash() const { return hashidx_
; }
1496 // use module->addCell() and module->remove() to create or destroy cells
1497 friend struct RTLIL::Module
;
1502 // do not simply copy cells
1503 Cell(RTLIL::Cell
&other
) = delete;
1504 void operator=(RTLIL::Cell
&other
) = delete;
1506 RTLIL::Module
*module
;
1507 RTLIL::IdString name
;
1508 RTLIL::IdString type
;
1509 dict
<RTLIL::IdString
, RTLIL::SigSpec
> connections_
;
1510 dict
<RTLIL::IdString
, RTLIL::Const
> parameters
;
1512 // access cell ports
1513 bool hasPort(RTLIL::IdString portname
) const;
1514 void unsetPort(RTLIL::IdString portname
);
1515 void setPort(RTLIL::IdString portname
, RTLIL::SigSpec signal
);
1516 const RTLIL::SigSpec
&getPort(RTLIL::IdString portname
) const;
1517 const dict
<RTLIL::IdString
, RTLIL::SigSpec
> &connections() const;
1519 // information about cell ports
1521 bool input(RTLIL::IdString portname
) const;
1522 bool output(RTLIL::IdString portname
) const;
1524 // access cell parameters
1525 bool hasParam(RTLIL::IdString paramname
) const;
1526 void unsetParam(RTLIL::IdString paramname
);
1527 void setParam(RTLIL::IdString paramname
, RTLIL::Const value
);
1528 const RTLIL::Const
&getParam(RTLIL::IdString paramname
) const;
1532 void fixup_parameters(bool set_a_signed
= false, bool set_b_signed
= false);
1534 bool has_keep_attr() const {
1535 return get_bool_attribute(ID::keep
) || (module
&& module
->design
&& module
->design
->module(type
) &&
1536 module
->design
->module(type
)->get_bool_attribute(ID::keep
));
1539 template<typename T
> void rewrite_sigspecs(T
&functor
);
1540 template<typename T
> void rewrite_sigspecs2(T
&functor
);
1543 static std::map
<unsigned int, RTLIL::Cell
*> *get_all_cells(void);
1546 bool has_memid() const;
1547 bool is_mem_cell() const;
1550 struct RTLIL::CaseRule
: public RTLIL::AttrObject
1552 std::vector
<RTLIL::SigSpec
> compare
;
1553 std::vector
<RTLIL::SigSig
> actions
;
1554 std::vector
<RTLIL::SwitchRule
*> switches
;
1560 template<typename T
> void rewrite_sigspecs(T
&functor
);
1561 template<typename T
> void rewrite_sigspecs2(T
&functor
);
1562 RTLIL::CaseRule
*clone() const;
1565 struct RTLIL::SwitchRule
: public RTLIL::AttrObject
1567 RTLIL::SigSpec signal
;
1568 std::vector
<RTLIL::CaseRule
*> cases
;
1574 template<typename T
> void rewrite_sigspecs(T
&functor
);
1575 template<typename T
> void rewrite_sigspecs2(T
&functor
);
1576 RTLIL::SwitchRule
*clone() const;
1579 struct RTLIL::MemWriteAction
: RTLIL::AttrObject
1581 RTLIL::IdString memid
;
1582 RTLIL::SigSpec address
;
1583 RTLIL::SigSpec data
;
1584 RTLIL::SigSpec enable
;
1585 RTLIL::Const priority_mask
;
1588 struct RTLIL::SyncRule
1590 RTLIL::SyncType type
;
1591 RTLIL::SigSpec signal
;
1592 std::vector
<RTLIL::SigSig
> actions
;
1593 std::vector
<RTLIL::MemWriteAction
> mem_write_actions
;
1595 template<typename T
> void rewrite_sigspecs(T
&functor
);
1596 template<typename T
> void rewrite_sigspecs2(T
&functor
);
1597 RTLIL::SyncRule
*clone() const;
1600 struct RTLIL::Process
: public RTLIL::AttrObject
1602 unsigned int hashidx_
;
1603 unsigned int hash() const { return hashidx_
; }
1606 // use module->addProcess() and module->remove() to create or destroy processes
1607 friend struct RTLIL::Module
;
1612 RTLIL::IdString name
;
1613 RTLIL::Module
*module
;
1614 RTLIL::CaseRule root_case
;
1615 std::vector
<RTLIL::SyncRule
*> syncs
;
1617 template<typename T
> void rewrite_sigspecs(T
&functor
);
1618 template<typename T
> void rewrite_sigspecs2(T
&functor
);
1619 RTLIL::Process
*clone() const;
1623 inline RTLIL::SigBit::SigBit() : wire(NULL
), data(RTLIL::State::S0
) { }
1624 inline RTLIL::SigBit::SigBit(RTLIL::State bit
) : wire(NULL
), data(bit
) { }
1625 inline RTLIL::SigBit::SigBit(bool bit
) : wire(NULL
), data(bit
? State::S1
: State::S0
) { }
1626 inline RTLIL::SigBit::SigBit(RTLIL::Wire
*wire
) : wire(wire
), offset(0) { log_assert(wire
&& wire
->width
== 1); }
1627 inline RTLIL::SigBit::SigBit(RTLIL::Wire
*wire
, int offset
) : wire(wire
), offset(offset
) { log_assert(wire
!= nullptr); }
1628 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]; }
1629 inline RTLIL::SigBit::SigBit(const RTLIL::SigChunk
&chunk
, int index
) : wire(chunk
.wire
) { if (wire
) offset
= chunk
.offset
+ index
; else data
= chunk
.data
[index
]; }
1631 inline bool RTLIL::SigBit::operator<(const RTLIL::SigBit
&other
) const {
1632 if (wire
== other
.wire
)
1633 return wire
? (offset
< other
.offset
) : (data
< other
.data
);
1634 if (wire
!= nullptr && other
.wire
!= nullptr)
1635 return wire
->name
< other
.wire
->name
;
1636 return (wire
!= nullptr) < (other
.wire
!= nullptr);
1639 inline bool RTLIL::SigBit::operator==(const RTLIL::SigBit
&other
) const {
1640 return (wire
== other
.wire
) && (wire
? (offset
== other
.offset
) : (data
== other
.data
));
1643 inline bool RTLIL::SigBit::operator!=(const RTLIL::SigBit
&other
) const {
1644 return (wire
!= other
.wire
) || (wire
? (offset
!= other
.offset
) : (data
!= other
.data
));
1647 inline unsigned int RTLIL::SigBit::hash() const {
1649 return mkhash_add(wire
->name
.hash(), offset
);
1653 inline RTLIL::SigBit
&RTLIL::SigSpecIterator::operator*() const {
1654 return (*sig_p
)[index
];
1657 inline const RTLIL::SigBit
&RTLIL::SigSpecConstIterator::operator*() const {
1658 return (*sig_p
)[index
];
1661 inline RTLIL::SigBit::SigBit(const RTLIL::SigSpec
&sig
) {
1662 log_assert(sig
.size() == 1 && sig
.chunks().size() == 1);
1663 *this = SigBit(sig
.chunks().front());
1666 template<typename T
>
1667 void RTLIL::Module::rewrite_sigspecs(T
&functor
)
1669 for (auto &it
: cells_
)
1670 it
.second
->rewrite_sigspecs(functor
);
1671 for (auto &it
: processes
)
1672 it
.second
->rewrite_sigspecs(functor
);
1673 for (auto &it
: connections_
) {
1679 template<typename T
>
1680 void RTLIL::Module::rewrite_sigspecs2(T
&functor
)
1682 for (auto &it
: cells_
)
1683 it
.second
->rewrite_sigspecs2(functor
);
1684 for (auto &it
: processes
)
1685 it
.second
->rewrite_sigspecs2(functor
);
1686 for (auto &it
: connections_
) {
1687 functor(it
.first
, it
.second
);
1691 template<typename T
>
1692 void RTLIL::Cell::rewrite_sigspecs(T
&functor
) {
1693 for (auto &it
: connections_
)
1697 template<typename T
>
1698 void RTLIL::Cell::rewrite_sigspecs2(T
&functor
) {
1699 for (auto &it
: connections_
)
1703 template<typename T
>
1704 void RTLIL::CaseRule::rewrite_sigspecs(T
&functor
) {
1705 for (auto &it
: compare
)
1707 for (auto &it
: actions
) {
1711 for (auto it
: switches
)
1712 it
->rewrite_sigspecs(functor
);
1715 template<typename T
>
1716 void RTLIL::CaseRule::rewrite_sigspecs2(T
&functor
) {
1717 for (auto &it
: compare
)
1719 for (auto &it
: actions
) {
1720 functor(it
.first
, it
.second
);
1722 for (auto it
: switches
)
1723 it
->rewrite_sigspecs2(functor
);
1726 template<typename T
>
1727 void RTLIL::SwitchRule::rewrite_sigspecs(T
&functor
)
1730 for (auto it
: cases
)
1731 it
->rewrite_sigspecs(functor
);
1734 template<typename T
>
1735 void RTLIL::SwitchRule::rewrite_sigspecs2(T
&functor
)
1738 for (auto it
: cases
)
1739 it
->rewrite_sigspecs2(functor
);
1742 template<typename T
>
1743 void RTLIL::SyncRule::rewrite_sigspecs(T
&functor
)
1746 for (auto &it
: actions
) {
1750 for (auto &it
: mem_write_actions
) {
1751 functor(it
.address
);
1757 template<typename T
>
1758 void RTLIL::SyncRule::rewrite_sigspecs2(T
&functor
)
1761 for (auto &it
: actions
) {
1762 functor(it
.first
, it
.second
);
1764 for (auto &it
: mem_write_actions
) {
1765 functor(it
.address
);
1771 template<typename T
>
1772 void RTLIL::Process::rewrite_sigspecs(T
&functor
)
1774 root_case
.rewrite_sigspecs(functor
);
1775 for (auto it
: syncs
)
1776 it
->rewrite_sigspecs(functor
);
1779 template<typename T
>
1780 void RTLIL::Process::rewrite_sigspecs2(T
&functor
)
1782 root_case
.rewrite_sigspecs2(functor
);
1783 for (auto it
: syncs
)
1784 it
->rewrite_sigspecs2(functor
);