2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
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
;
75 typedef std::pair
<SigSpec
, SigSpec
> SigSig
;
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
84 // the global id string cache
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; }
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_
;
99 #ifdef YOSYS_USE_STICKY_IDS
100 static int last_created_idx_ptr_
;
101 static int last_created_idx_
[8];
104 static inline void xtrace_db_dump()
106 #ifdef YOSYS_XTRACE_GET_PUT
107 for (int idx
= 0; idx
< GetSize(global_id_storage_
); idx
++)
109 if (global_id_storage_
.at(idx
) == nullptr)
110 log("#X# DB-DUMP index %d: FREE\n", idx
);
112 log("#X# DB-DUMP index %d: '%s' (ref %d)\n", idx
, global_id_storage_
.at(idx
), global_refcount_storage_
.at(idx
));
117 static inline void checkpoint()
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;
127 #ifdef YOSYS_SORT_ID_FREE_LIST
128 std::sort(global_free_idx_list_
.begin(), global_free_idx_list_
.end(), std::greater
<int>());
132 static inline int get_reference(int idx
)
135 #ifndef YOSYS_NO_IDS_REFCNT
136 global_refcount_storage_
[idx
]++;
138 #ifdef YOSYS_XTRACE_GET_PUT
140 log("#X# GET-BY-INDEX '%s' (index %d, refcount %d)\n", global_id_storage_
.at(idx
), idx
, global_refcount_storage_
.at(idx
));
146 static int get_reference(const char *p
)
148 log_assert(destruct_guard
.ok
);
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
)++;
158 #ifdef YOSYS_XTRACE_GET_PUT
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
));
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)' ');
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;
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);
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
)++;
189 if (global_id_storage_
.empty()) {
190 global_id_storage_
.push_back((char*)"");
191 global_id_index_
[global_id_storage_
.back()] = 0;
193 int idx
= global_id_storage_
.size();
194 global_id_storage_
.push_back(strdup(p
));
195 global_id_index_
[global_id_storage_
.back()] = idx
;
199 log("#X# New IdString '%s' with index %d.\n", p
, idx
);
200 log_backtrace("-X- ", yosys_xtrace
-1);
203 #ifdef YOSYS_XTRACE_GET_PUT
205 log("#X# GET-BY-NAME '%s' (index %d, refcount %d)\n", global_id_storage_
.at(idx
), idx
, global_refcount_storage_
.at(idx
));
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;
220 #ifndef YOSYS_NO_IDS_REFCNT
221 static inline void put_reference(int idx
)
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
)
228 #ifdef YOSYS_XTRACE_GET_PUT
230 log("#X# PUT '%s' (index %d, refcount %d)\n", global_id_storage_
.at(idx
), idx
, global_refcount_storage_
.at(idx
));
234 int &refcount
= global_refcount_storage_
[idx
];
239 log_assert(refcount
== 0);
242 static inline void free_reference(int idx
)
245 log("#X# Removed IdString '%s' with index %d.\n", global_id_storage_
.at(idx
), idx
);
246 log_backtrace("-X- ", yosys_xtrace
-1);
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
);
255 static inline void put_reference(int) { }
258 // the actual IdString object is just is a single int
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_
); }
269 inline void operator=(const IdString
&rhs
) {
270 put_reference(index_
);
271 index_
= get_reference(rhs
.index_
);
274 inline void operator=(const char *rhs
) {
279 inline void operator=(const std::string
&rhs
) {
284 inline const char *c_str() const {
285 return global_id_storage_
.at(index_
);
288 inline std::string
str() const {
289 return std::string(global_id_storage_
.at(index_
));
292 inline bool operator<(const IdString
&rhs
) const {
293 return index_
< rhs
.index_
;
296 inline bool operator==(const IdString
&rhs
) const { return index_
== rhs
.index_
; }
297 inline bool operator!=(const IdString
&rhs
) const { return index_
!= rhs
.index_
; }
299 // The methods below are just convenience functions for better compatibility with std::string.
301 bool operator==(const std::string
&rhs
) const { return c_str() == rhs
; }
302 bool operator!=(const std::string
&rhs
) const { return c_str() != rhs
; }
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; }
307 char operator[](size_t i
) const {
308 const char *p
= c_str();
309 for (; i
!= 0; i
--, p
++)
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
);
318 return std::string(c_str() + pos
, len
);
321 int compare(size_t pos
, size_t len
, const char* s
) const {
322 return strncmp(c_str()+pos
, s
, len
);
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;
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;
337 size_t size() const {
338 return strlen(c_str());
342 return c_str()[0] == 0;
349 unsigned int hash() const {
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.
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
);
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.
366 template<typename
... Args
>
367 bool in(Args
... args
) const {
368 // Credit: https://articles.emptycrate.com/2016/05/14/folds_in_cpp11_ish.html
370 (void) std::initializer_list
<int>{ (result
= result
|| in(args
), 0)... };
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; }
381 #define X(_id) extern IdString _id;
382 #include "kernel/constids.inc"
386 extern dict
<std::string
, std::string
> constpad
;
388 const pool
<IdString
> &builtin_ff_cell_types();
390 static inline std::string
escape_id(const std::string
&str
) {
391 if (str
.size() > 0 && str
[0] != '\\' && str
[0] != '$')
396 static inline std::string
unescape_id(const std::string
&str
) {
401 if (str
[1] == '$' || str
[1] == '\\')
403 if (str
[1] >= '0' && str
[1] <= '9')
405 return str
.substr(1);
408 static inline std::string
unescape_id(RTLIL::IdString str
) {
409 return unescape_id(str
.str());
412 static inline const char *id2cstr(RTLIL::IdString str
) {
416 template <typename T
> struct sort_by_name_id
{
417 bool operator()(T
*a
, T
*b
) const {
418 return a
->name
< b
->name
;
422 template <typename T
> struct sort_by_name_str
{
423 bool operator()(T
*a
, T
*b
) const {
424 return strcmp(a
->name
.c_str(), b
->name
.c_str()) < 0;
428 struct sort_by_id_str
{
429 bool operator()(RTLIL::IdString a
, RTLIL::IdString b
) const {
430 return strcmp(a
.c_str(), b
.c_str()) < 0;
434 // see calc.cc for the implementation of this functions
435 RTLIL::Const
const_not (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
436 RTLIL::Const
const_and (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
437 RTLIL::Const
const_or (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
438 RTLIL::Const
const_xor (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
439 RTLIL::Const
const_xnor (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
441 RTLIL::Const
const_reduce_and (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
442 RTLIL::Const
const_reduce_or (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
443 RTLIL::Const
const_reduce_xor (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
444 RTLIL::Const
const_reduce_xnor (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
445 RTLIL::Const
const_reduce_bool (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
447 RTLIL::Const
const_logic_not (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
448 RTLIL::Const
const_logic_and (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
449 RTLIL::Const
const_logic_or (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
451 RTLIL::Const
const_shl (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
452 RTLIL::Const
const_shr (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
453 RTLIL::Const
const_sshl (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
454 RTLIL::Const
const_sshr (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
455 RTLIL::Const
const_shift (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
456 RTLIL::Const
const_shiftx (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
458 RTLIL::Const
const_lt (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
459 RTLIL::Const
const_le (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
460 RTLIL::Const
const_eq (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
461 RTLIL::Const
const_ne (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
462 RTLIL::Const
const_eqx (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
463 RTLIL::Const
const_nex (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
464 RTLIL::Const
const_ge (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
465 RTLIL::Const
const_gt (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
467 RTLIL::Const
const_add (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
468 RTLIL::Const
const_sub (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
469 RTLIL::Const
const_mul (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
470 RTLIL::Const
const_div (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
471 RTLIL::Const
const_divfloor (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
472 RTLIL::Const
const_modfloor (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
473 RTLIL::Const
const_mod (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
474 RTLIL::Const
const_pow (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
476 RTLIL::Const
const_pos (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
477 RTLIL::Const
const_neg (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
480 // This iterator-range-pair is used for Design::modules(), Module::wires() and Module::cells().
481 // It maintains a reference counter that is used to make sure that the container is not modified while being iterated over.
485 using iterator_category
= std::forward_iterator_tag
;
486 using value_type
= T
;
487 using difference_type
= ptrdiff_t;
489 using reference
= T
&;
490 typename dict
<RTLIL::IdString
, T
>::iterator it
;
491 dict
<RTLIL::IdString
, T
> *list_p
;
494 ObjIterator() : list_p(nullptr), refcount_p(nullptr) {
497 ObjIterator(decltype(list_p
) list_p
, int *refcount_p
) : list_p(list_p
), refcount_p(refcount_p
) {
498 if (list_p
->empty()) {
499 this->list_p
= nullptr;
500 this->refcount_p
= nullptr;
502 it
= list_p
->begin();
507 ObjIterator(const RTLIL::ObjIterator
<T
> &other
) {
509 list_p
= other
.list_p
;
510 refcount_p
= other
.refcount_p
;
515 ObjIterator
&operator=(const RTLIL::ObjIterator
<T
> &other
) {
519 list_p
= other
.list_p
;
520 refcount_p
= other
.refcount_p
;
531 inline T
operator*() const {
532 log_assert(list_p
!= nullptr);
536 inline bool operator!=(const RTLIL::ObjIterator
<T
> &other
) const {
537 if (list_p
== nullptr || other
.list_p
== nullptr)
538 return list_p
!= other
.list_p
;
539 return it
!= other
.it
;
543 inline bool operator==(const RTLIL::ObjIterator
<T
> &other
) const {
544 return !(*this != other
);
547 inline ObjIterator
<T
>& operator++() {
548 log_assert(list_p
!= nullptr);
549 if (++it
== list_p
->end()) {
552 refcount_p
= nullptr;
557 inline const ObjIterator
<T
> operator++(int) {
558 ObjIterator
<T
> result(*this);
567 dict
<RTLIL::IdString
, T
> *list_p
;
570 ObjRange(decltype(list_p
) list_p
, int *refcount_p
) : list_p(list_p
), refcount_p(refcount_p
) { }
571 RTLIL::ObjIterator
<T
> begin() { return RTLIL::ObjIterator
<T
>(list_p
, refcount_p
); }
572 RTLIL::ObjIterator
<T
> end() { return RTLIL::ObjIterator
<T
>(); }
574 size_t size() const {
575 return list_p
->size();
578 operator pool
<T
>() const {
580 for (auto &it
: *list_p
)
581 result
.insert(it
.second
);
585 operator std::vector
<T
>() const {
586 std::vector
<T
> result
;
587 result
.reserve(list_p
->size());
588 for (auto &it
: *list_p
)
589 result
.push_back(it
.second
);
593 pool
<T
> to_pool() const { return *this; }
594 std::vector
<T
> to_vector() const { return *this; }
601 std::vector
<RTLIL::State
> bits
;
604 Const(std::string str
);
605 Const(int val
, int width
= 32);
606 Const(RTLIL::State bit
, int width
= 1);
607 Const(const std::vector
<RTLIL::State
> &bits
) : bits(bits
) { flags
= CONST_FLAG_NONE
; }
608 Const(const std::vector
<bool> &bits
);
609 Const(const RTLIL::Const
&c
);
610 RTLIL::Const
&operator =(const RTLIL::Const
&other
) = default;
612 bool operator <(const RTLIL::Const
&other
) const;
613 bool operator ==(const RTLIL::Const
&other
) const;
614 bool operator !=(const RTLIL::Const
&other
) const;
616 bool as_bool() const;
617 int as_int(bool is_signed
= false) const;
618 std::string
as_string() const;
619 static Const
from_string(const std::string
&str
);
621 std::string
decode_string() const;
623 inline int size() const { return bits
.size(); }
624 inline bool empty() const { return bits
.empty(); }
625 inline RTLIL::State
&operator[](int index
) { return bits
.at(index
); }
626 inline const RTLIL::State
&operator[](int index
) const { return bits
.at(index
); }
627 inline decltype(bits
)::iterator
begin() { return bits
.begin(); }
628 inline decltype(bits
)::iterator
end() { return bits
.end(); }
630 bool is_fully_zero() const;
631 bool is_fully_ones() const;
632 bool is_fully_def() const;
633 bool is_fully_undef() const;
635 inline RTLIL::Const
extract(int offset
, int len
= 1, RTLIL::State padding
= RTLIL::State::S0
) const {
637 ret
.bits
.reserve(len
);
638 for (int i
= offset
; i
< offset
+ len
; i
++)
639 ret
.bits
.push_back(i
< GetSize(bits
) ? bits
[i
] : padding
);
643 void extu(int width
) {
644 bits
.resize(width
, RTLIL::State::S0
);
647 void exts(int width
) {
648 bits
.resize(width
, bits
.empty() ? RTLIL::State::Sx
: bits
.back());
651 inline unsigned int hash() const {
652 unsigned int h
= mkhash_init
;
659 struct RTLIL::AttrObject
661 dict
<RTLIL::IdString
, RTLIL::Const
> attributes
;
663 bool has_attribute(RTLIL::IdString id
) const;
665 void set_bool_attribute(RTLIL::IdString id
, bool value
=true);
666 bool get_bool_attribute(RTLIL::IdString id
) const;
668 bool get_blackbox_attribute(bool ignore_wb
=false) const {
669 return get_bool_attribute(ID::blackbox
) || (!ignore_wb
&& get_bool_attribute(ID::whitebox
));
672 void set_string_attribute(RTLIL::IdString id
, string value
);
673 string
get_string_attribute(RTLIL::IdString id
) const;
675 void set_strpool_attribute(RTLIL::IdString id
, const pool
<string
> &data
);
676 void add_strpool_attribute(RTLIL::IdString id
, const pool
<string
> &data
);
677 pool
<string
> get_strpool_attribute(RTLIL::IdString id
) const;
679 void set_src_attribute(const std::string
&src
) {
680 set_string_attribute(ID::src
, src
);
682 std::string
get_src_attribute() const {
683 return get_string_attribute(ID::src
);
686 void set_hdlname_attribute(const vector
<string
> &hierarchy
);
687 vector
<string
> get_hdlname_attribute() const;
690 struct RTLIL::SigChunk
693 std::vector
<RTLIL::State
> data
; // only used if wire == NULL, LSB at index 0
697 SigChunk(const RTLIL::Const
&value
);
698 SigChunk(RTLIL::Wire
*wire
);
699 SigChunk(RTLIL::Wire
*wire
, int offset
, int width
= 1);
700 SigChunk(const std::string
&str
);
701 SigChunk(int val
, int width
= 32);
702 SigChunk(RTLIL::State bit
, int width
= 1);
703 SigChunk(const RTLIL::SigBit
&bit
);
704 SigChunk(const RTLIL::SigChunk
&sigchunk
);
705 RTLIL::SigChunk
&operator =(const RTLIL::SigChunk
&other
) = default;
707 RTLIL::SigChunk
extract(int offset
, int length
) const;
708 inline int size() const { return width
; }
710 bool operator <(const RTLIL::SigChunk
&other
) const;
711 bool operator ==(const RTLIL::SigChunk
&other
) const;
712 bool operator !=(const RTLIL::SigChunk
&other
) const;
719 RTLIL::State data
; // used if wire == NULL
720 int offset
; // used if wire != NULL
724 SigBit(RTLIL::State bit
);
726 SigBit(RTLIL::Wire
*wire
);
727 SigBit(RTLIL::Wire
*wire
, int offset
);
728 SigBit(const RTLIL::SigChunk
&chunk
);
729 SigBit(const RTLIL::SigChunk
&chunk
, int index
);
730 SigBit(const RTLIL::SigSpec
&sig
);
731 SigBit(const RTLIL::SigBit
&sigbit
) = default;
732 RTLIL::SigBit
&operator =(const RTLIL::SigBit
&other
) = default;
734 bool operator <(const RTLIL::SigBit
&other
) const;
735 bool operator ==(const RTLIL::SigBit
&other
) const;
736 bool operator !=(const RTLIL::SigBit
&other
) const;
737 unsigned int hash() const;
740 struct RTLIL::SigSpecIterator
: public std::iterator
<std::input_iterator_tag
, RTLIL::SigSpec
>
742 RTLIL::SigSpec
*sig_p
;
745 inline RTLIL::SigBit
&operator*() const;
746 inline bool operator!=(const RTLIL::SigSpecIterator
&other
) const { return index
!= other
.index
; }
747 inline bool operator==(const RTLIL::SigSpecIterator
&other
) const { return index
== other
.index
; }
748 inline void operator++() { index
++; }
751 struct RTLIL::SigSpecConstIterator
: public std::iterator
<std::input_iterator_tag
, RTLIL::SigSpec
>
753 const RTLIL::SigSpec
*sig_p
;
756 inline const RTLIL::SigBit
&operator*() const;
757 inline bool operator!=(const RTLIL::SigSpecConstIterator
&other
) const { return index
!= other
.index
; }
758 inline bool operator==(const RTLIL::SigSpecIterator
&other
) const { return index
== other
.index
; }
759 inline void operator++() { index
++; }
762 struct RTLIL::SigSpec
767 std::vector
<RTLIL::SigChunk
> chunks_
; // LSB at index 0
768 std::vector
<RTLIL::SigBit
> bits_
; // LSB at index 0
772 void updhash() const;
774 inline bool packed() const {
775 return bits_
.empty();
778 inline void inline_unpack() const {
779 if (!chunks_
.empty())
783 // Only used by Module::remove(const pool<Wire*> &wires)
784 // but cannot be more specific as it isn't yet declared
785 friend struct RTLIL::Module
;
789 SigSpec(const RTLIL::SigSpec
&other
);
790 SigSpec(std::initializer_list
<RTLIL::SigSpec
> parts
);
791 RTLIL::SigSpec
&operator=(const RTLIL::SigSpec
&other
);
793 SigSpec(const RTLIL::Const
&value
);
794 SigSpec(const RTLIL::SigChunk
&chunk
);
795 SigSpec(RTLIL::Wire
*wire
);
796 SigSpec(RTLIL::Wire
*wire
, int offset
, int width
= 1);
797 SigSpec(const std::string
&str
);
798 SigSpec(int val
, int width
= 32);
799 SigSpec(RTLIL::State bit
, int width
= 1);
800 SigSpec(const RTLIL::SigBit
&bit
, int width
= 1);
801 SigSpec(const std::vector
<RTLIL::SigChunk
> &chunks
);
802 SigSpec(const std::vector
<RTLIL::SigBit
> &bits
);
803 SigSpec(const pool
<RTLIL::SigBit
> &bits
);
804 SigSpec(const std::set
<RTLIL::SigBit
> &bits
);
807 SigSpec(RTLIL::SigSpec
&&other
) {
808 width_
= other
.width_
;
810 chunks_
= std::move(other
.chunks_
);
811 bits_
= std::move(other
.bits_
);
814 const RTLIL::SigSpec
&operator=(RTLIL::SigSpec
&&other
) {
815 width_
= other
.width_
;
817 chunks_
= std::move(other
.chunks_
);
818 bits_
= std::move(other
.bits_
);
822 size_t get_hash() const {
827 inline const std::vector
<RTLIL::SigChunk
> &chunks() const { pack(); return chunks_
; }
828 inline const std::vector
<RTLIL::SigBit
> &bits() const { inline_unpack(); return bits_
; }
830 inline int size() const { return width_
; }
831 inline bool empty() const { return width_
== 0; }
833 inline RTLIL::SigBit
&operator[](int index
) { inline_unpack(); return bits_
.at(index
); }
834 inline const RTLIL::SigBit
&operator[](int index
) const { inline_unpack(); return bits_
.at(index
); }
836 inline RTLIL::SigSpecIterator
begin() { RTLIL::SigSpecIterator it
; it
.sig_p
= this; it
.index
= 0; return it
; }
837 inline RTLIL::SigSpecIterator
end() { RTLIL::SigSpecIterator it
; it
.sig_p
= this; it
.index
= width_
; return it
; }
839 inline RTLIL::SigSpecConstIterator
begin() const { RTLIL::SigSpecConstIterator it
; it
.sig_p
= this; it
.index
= 0; return it
; }
840 inline RTLIL::SigSpecConstIterator
end() const { RTLIL::SigSpecConstIterator it
; it
.sig_p
= this; it
.index
= width_
; return it
; }
843 void sort_and_unify();
845 void replace(const RTLIL::SigSpec
&pattern
, const RTLIL::SigSpec
&with
);
846 void replace(const RTLIL::SigSpec
&pattern
, const RTLIL::SigSpec
&with
, RTLIL::SigSpec
*other
) const;
848 void replace(const dict
<RTLIL::SigBit
, RTLIL::SigBit
> &rules
);
849 void replace(const dict
<RTLIL::SigBit
, RTLIL::SigBit
> &rules
, RTLIL::SigSpec
*other
) const;
851 void replace(const std::map
<RTLIL::SigBit
, RTLIL::SigBit
> &rules
);
852 void replace(const std::map
<RTLIL::SigBit
, RTLIL::SigBit
> &rules
, RTLIL::SigSpec
*other
) const;
854 void replace(int offset
, const RTLIL::SigSpec
&with
);
856 void remove(const RTLIL::SigSpec
&pattern
);
857 void remove(const RTLIL::SigSpec
&pattern
, RTLIL::SigSpec
*other
) const;
858 void remove2(const RTLIL::SigSpec
&pattern
, RTLIL::SigSpec
*other
);
860 void remove(const pool
<RTLIL::SigBit
> &pattern
);
861 void remove(const pool
<RTLIL::SigBit
> &pattern
, RTLIL::SigSpec
*other
) const;
862 void remove2(const pool
<RTLIL::SigBit
> &pattern
, RTLIL::SigSpec
*other
);
863 void remove2(const std::set
<RTLIL::SigBit
> &pattern
, RTLIL::SigSpec
*other
);
865 void remove(int offset
, int length
= 1);
868 RTLIL::SigSpec
extract(const RTLIL::SigSpec
&pattern
, const RTLIL::SigSpec
*other
= NULL
) const;
869 RTLIL::SigSpec
extract(const pool
<RTLIL::SigBit
> &pattern
, const RTLIL::SigSpec
*other
= NULL
) const;
870 RTLIL::SigSpec
extract(int offset
, int length
= 1) const;
871 RTLIL::SigSpec
extract_end(int offset
) const { return extract(offset
, width_
- offset
); }
873 void append(const RTLIL::SigSpec
&signal
);
874 inline void append(Wire
*wire
) { append(RTLIL::SigSpec(wire
)); }
875 inline void append(const RTLIL::SigChunk
&chunk
) { append(RTLIL::SigSpec(chunk
)); }
876 inline void append(const RTLIL::Const
&const_
) { append(RTLIL::SigSpec(const_
)); }
878 void append(const RTLIL::SigBit
&bit
);
879 inline void append(RTLIL::State state
) { append(RTLIL::SigBit(state
)); }
880 inline void append(bool bool_
) { append(RTLIL::SigBit(bool_
)); }
882 void extend_u0(int width
, bool is_signed
= false);
884 RTLIL::SigSpec
repeat(int num
) const;
886 void reverse() { inline_unpack(); std::reverse(bits_
.begin(), bits_
.end()); }
888 bool operator <(const RTLIL::SigSpec
&other
) const;
889 bool operator ==(const RTLIL::SigSpec
&other
) const;
890 inline bool operator !=(const RTLIL::SigSpec
&other
) const { return !(*this == other
); }
892 bool is_wire() const;
893 bool is_chunk() const;
894 inline bool is_bit() const { return width_
== 1; }
896 bool is_fully_const() const;
897 bool is_fully_zero() const;
898 bool is_fully_ones() const;
899 bool is_fully_def() const;
900 bool is_fully_undef() const;
901 bool has_const() const;
902 bool has_marked_bits() const;
904 bool as_bool() const;
905 int as_int(bool is_signed
= false) const;
906 std::string
as_string() const;
907 RTLIL::Const
as_const() const;
908 RTLIL::Wire
*as_wire() const;
909 RTLIL::SigChunk
as_chunk() const;
910 RTLIL::SigBit
as_bit() const;
912 bool match(const char* pattern
) const;
914 std::set
<RTLIL::SigBit
> to_sigbit_set() const;
915 pool
<RTLIL::SigBit
> to_sigbit_pool() const;
916 std::vector
<RTLIL::SigBit
> to_sigbit_vector() const;
917 std::map
<RTLIL::SigBit
, RTLIL::SigBit
> to_sigbit_map(const RTLIL::SigSpec
&other
) const;
918 dict
<RTLIL::SigBit
, RTLIL::SigBit
> to_sigbit_dict(const RTLIL::SigSpec
&other
) const;
920 static bool parse(RTLIL::SigSpec
&sig
, RTLIL::Module
*module
, std::string str
);
921 static bool parse_sel(RTLIL::SigSpec
&sig
, RTLIL::Design
*design
, RTLIL::Module
*module
, std::string str
);
922 static bool parse_rhs(const RTLIL::SigSpec
&lhs
, RTLIL::SigSpec
&sig
, RTLIL::Module
*module
, std::string str
);
924 operator std::vector
<RTLIL::SigChunk
>() const { return chunks(); }
925 operator std::vector
<RTLIL::SigBit
>() const { return bits(); }
926 const RTLIL::SigBit
&at(int offset
, const RTLIL::SigBit
&defval
) { return offset
< width_
? (*this)[offset
] : defval
; }
928 unsigned int hash() const { if (!hash_
) updhash(); return hash_
; };
933 void check() const { }
937 struct RTLIL::Selection
940 pool
<RTLIL::IdString
> selected_modules
;
941 dict
<RTLIL::IdString
, pool
<RTLIL::IdString
>> selected_members
;
943 Selection(bool full
= true) : full_selection(full
) { }
945 bool selected_module(RTLIL::IdString mod_name
) const;
946 bool selected_whole_module(RTLIL::IdString mod_name
) const;
947 bool selected_member(RTLIL::IdString mod_name
, RTLIL::IdString memb_name
) const;
948 void optimize(RTLIL::Design
*design
);
950 template<typename T1
> void select(T1
*module
) {
951 if (!full_selection
&& selected_modules
.count(module
->name
) == 0) {
952 selected_modules
.insert(module
->name
);
953 selected_members
.erase(module
->name
);
957 template<typename T1
, typename T2
> void select(T1
*module
, T2
*member
) {
958 if (!full_selection
&& selected_modules
.count(module
->name
) == 0)
959 selected_members
[module
->name
].insert(member
->name
);
963 return !full_selection
&& selected_modules
.empty() && selected_members
.empty();
967 struct RTLIL::Monitor
969 unsigned int hashidx_
;
970 unsigned int hash() const { return hashidx_
; }
973 static unsigned int hashidx_count
= 123456789;
974 hashidx_count
= mkhash_xorshift(hashidx_count
);
975 hashidx_
= hashidx_count
;
978 virtual ~Monitor() { }
979 virtual void notify_module_add(RTLIL::Module
*) { }
980 virtual void notify_module_del(RTLIL::Module
*) { }
981 virtual void notify_connect(RTLIL::Cell
*, const RTLIL::IdString
&, const RTLIL::SigSpec
&, const RTLIL::SigSpec
&) { }
982 virtual void notify_connect(RTLIL::Module
*, const RTLIL::SigSig
&) { }
983 virtual void notify_connect(RTLIL::Module
*, const std::vector
<RTLIL::SigSig
>&) { }
984 virtual void notify_blackout(RTLIL::Module
*) { }
987 // Forward declaration; defined in preproc.h.
992 unsigned int hashidx_
;
993 unsigned int hash() const { return hashidx_
; }
995 pool
<RTLIL::Monitor
*> monitors
;
996 dict
<std::string
, std::string
> scratchpad
;
998 int refcount_modules_
;
999 dict
<RTLIL::IdString
, RTLIL::Module
*> modules_
;
1000 std::vector
<AST::AstNode
*> verilog_packages
, verilog_globals
;
1001 std::unique_ptr
<define_map_t
> verilog_defines
;
1003 std::vector
<RTLIL::Selection
> selection_stack
;
1004 dict
<RTLIL::IdString
, RTLIL::Selection
> selection_vars
;
1005 std::string selected_active_module
;
1010 RTLIL::ObjRange
<RTLIL::Module
*> modules();
1011 RTLIL::Module
*module(RTLIL::IdString name
);
1012 RTLIL::Module
*top_module();
1014 bool has(RTLIL::IdString id
) const {
1015 return modules_
.count(id
) != 0;
1018 void add(RTLIL::Module
*module
);
1019 RTLIL::Module
*addModule(RTLIL::IdString name
);
1020 void remove(RTLIL::Module
*module
);
1021 void rename(RTLIL::Module
*module
, RTLIL::IdString new_name
);
1023 void scratchpad_unset(const std::string
&varname
);
1025 void scratchpad_set_int(const std::string
&varname
, int value
);
1026 void scratchpad_set_bool(const std::string
&varname
, bool value
);
1027 void scratchpad_set_string(const std::string
&varname
, std::string value
);
1029 int scratchpad_get_int(const std::string
&varname
, int default_value
= 0) const;
1030 bool scratchpad_get_bool(const std::string
&varname
, bool default_value
= false) const;
1031 std::string
scratchpad_get_string(const std::string
&varname
, const std::string
&default_value
= std::string()) const;
1037 bool selected_module(RTLIL::IdString mod_name
) const;
1038 bool selected_whole_module(RTLIL::IdString mod_name
) const;
1039 bool selected_member(RTLIL::IdString mod_name
, RTLIL::IdString memb_name
) const;
1041 bool selected_module(RTLIL::Module
*mod
) const;
1042 bool selected_whole_module(RTLIL::Module
*mod
) const;
1044 RTLIL::Selection
&selection() {
1045 return selection_stack
.back();
1048 const RTLIL::Selection
&selection() const {
1049 return selection_stack
.back();
1052 bool full_selection() const {
1053 return selection_stack
.back().full_selection
;
1056 template<typename T1
> bool selected(T1
*module
) const {
1057 return selected_module(module
->name
);
1060 template<typename T1
, typename T2
> bool selected(T1
*module
, T2
*member
) const {
1061 return selected_member(module
->name
, member
->name
);
1064 template<typename T1
, typename T2
> void select(T1
*module
, T2
*member
) {
1065 if (selection_stack
.size() > 0) {
1066 RTLIL::Selection
&sel
= selection_stack
.back();
1067 sel
.select(module
, member
);
1072 std::vector
<RTLIL::Module
*> selected_modules() const;
1073 std::vector
<RTLIL::Module
*> selected_whole_modules() const;
1074 std::vector
<RTLIL::Module
*> selected_whole_modules_warn() const;
1076 static std::map
<unsigned int, RTLIL::Design
*> *get_all_designs(void);
1080 struct RTLIL::Module
: public RTLIL::AttrObject
1082 unsigned int hashidx_
;
1083 unsigned int hash() const { return hashidx_
; }
1086 void add(RTLIL::Wire
*wire
);
1087 void add(RTLIL::Cell
*cell
);
1090 RTLIL::Design
*design
;
1091 pool
<RTLIL::Monitor
*> monitors
;
1093 int refcount_wires_
;
1094 int refcount_cells_
;
1096 dict
<RTLIL::IdString
, RTLIL::Wire
*> wires_
;
1097 dict
<RTLIL::IdString
, RTLIL::Cell
*> cells_
;
1098 std::vector
<RTLIL::SigSig
> connections_
;
1100 RTLIL::IdString name
;
1101 idict
<RTLIL::IdString
> avail_parameters
;
1102 dict
<RTLIL::IdString
, RTLIL::Const
> parameter_default_values
;
1103 dict
<RTLIL::IdString
, RTLIL::Memory
*> memories
;
1104 dict
<RTLIL::IdString
, RTLIL::Process
*> processes
;
1108 virtual RTLIL::IdString
derive(RTLIL::Design
*design
, const dict
<RTLIL::IdString
, RTLIL::Const
> ¶meters
, bool mayfail
= false);
1109 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);
1110 virtual size_t count_id(RTLIL::IdString id
);
1111 virtual void reprocess_module(RTLIL::Design
*design
, const dict
<RTLIL::IdString
, RTLIL::Module
*> &local_interfaces
);
1113 virtual void sort();
1114 virtual void check();
1115 virtual void optimize();
1116 virtual void makeblackbox();
1118 void connect(const RTLIL::SigSig
&conn
);
1119 void connect(const RTLIL::SigSpec
&lhs
, const RTLIL::SigSpec
&rhs
);
1120 void new_connections(const std::vector
<RTLIL::SigSig
> &new_conn
);
1121 const std::vector
<RTLIL::SigSig
> &connections() const;
1123 std::vector
<RTLIL::IdString
> ports
;
1126 template<typename T
> void rewrite_sigspecs(T
&functor
);
1127 template<typename T
> void rewrite_sigspecs2(T
&functor
);
1128 void cloneInto(RTLIL::Module
*new_mod
) const;
1129 virtual RTLIL::Module
*clone() const;
1131 bool has_memories() const;
1132 bool has_processes() const;
1134 bool has_memories_warn() const;
1135 bool has_processes_warn() const;
1137 std::vector
<RTLIL::Wire
*> selected_wires() const;
1138 std::vector
<RTLIL::Cell
*> selected_cells() const;
1140 template<typename T
> bool selected(T
*member
) const {
1141 return design
->selected_member(name
, member
->name
);
1144 RTLIL::Wire
* wire(RTLIL::IdString id
) {
1145 auto it
= wires_
.find(id
);
1146 return it
== wires_
.end() ? nullptr : it
->second
;
1148 RTLIL::Cell
* cell(RTLIL::IdString id
) {
1149 auto it
= cells_
.find(id
);
1150 return it
== cells_
.end() ? nullptr : it
->second
;
1153 RTLIL::ObjRange
<RTLIL::Wire
*> wires() { return RTLIL::ObjRange
<RTLIL::Wire
*>(&wires_
, &refcount_wires_
); }
1154 RTLIL::ObjRange
<RTLIL::Cell
*> cells() { return RTLIL::ObjRange
<RTLIL::Cell
*>(&cells_
, &refcount_cells_
); }
1156 // Removing wires is expensive. If you have to remove wires, remove them all at once.
1157 void remove(const pool
<RTLIL::Wire
*> &wires
);
1158 void remove(RTLIL::Cell
*cell
);
1160 void rename(RTLIL::Wire
*wire
, RTLIL::IdString new_name
);
1161 void rename(RTLIL::Cell
*cell
, RTLIL::IdString new_name
);
1162 void rename(RTLIL::IdString old_name
, RTLIL::IdString new_name
);
1164 void swap_names(RTLIL::Wire
*w1
, RTLIL::Wire
*w2
);
1165 void swap_names(RTLIL::Cell
*c1
, RTLIL::Cell
*c2
);
1167 RTLIL::IdString
uniquify(RTLIL::IdString name
);
1168 RTLIL::IdString
uniquify(RTLIL::IdString name
, int &index
);
1170 RTLIL::Wire
*addWire(RTLIL::IdString name
, int width
= 1);
1171 RTLIL::Wire
*addWire(RTLIL::IdString name
, const RTLIL::Wire
*other
);
1173 RTLIL::Cell
*addCell(RTLIL::IdString name
, RTLIL::IdString type
);
1174 RTLIL::Cell
*addCell(RTLIL::IdString name
, const RTLIL::Cell
*other
);
1176 RTLIL::Memory
*addMemory(RTLIL::IdString name
, const RTLIL::Memory
*other
);
1178 RTLIL::Process
*addProcess(RTLIL::IdString name
, const RTLIL::Process
*other
);
1180 // The add* methods create a cell and return the created cell. All signals must exist in advance.
1182 RTLIL::Cell
* addNot (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, bool is_signed
= false, const std::string
&src
= "");
1183 RTLIL::Cell
* addPos (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, bool is_signed
= false, const std::string
&src
= "");
1184 RTLIL::Cell
* addNeg (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, bool is_signed
= false, const std::string
&src
= "");
1186 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
= "");
1187 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
= "");
1188 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
= "");
1189 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
= "");
1191 RTLIL::Cell
* addReduceAnd (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, bool is_signed
= false, const std::string
&src
= "");
1192 RTLIL::Cell
* addReduceOr (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, bool is_signed
= false, const std::string
&src
= "");
1193 RTLIL::Cell
* addReduceXor (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, bool is_signed
= false, const std::string
&src
= "");
1194 RTLIL::Cell
* addReduceXnor (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, bool is_signed
= false, const std::string
&src
= "");
1195 RTLIL::Cell
* addReduceBool (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, bool is_signed
= false, const std::string
&src
= "");
1197 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
= "");
1198 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
= "");
1199 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
= "");
1200 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
= "");
1201 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
= "");
1202 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
= "");
1204 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
= "");
1205 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
= "");
1206 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
= "");
1207 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
= "");
1208 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
= "");
1209 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
= "");
1210 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
= "");
1211 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
= "");
1213 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
= "");
1214 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
= "");
1215 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
= "");
1216 // truncating division
1217 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
= "");
1218 // truncating modulo
1219 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
= "");
1220 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
= "");
1221 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
= "");
1222 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
= "");
1224 RTLIL::Cell
* addLogicNot (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, bool is_signed
= false, const std::string
&src
= "");
1225 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
= "");
1226 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
= "");
1228 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
= "");
1229 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
= "");
1231 RTLIL::Cell
* addSlice (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, RTLIL::Const offset
, const std::string
&src
= "");
1232 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
= "");
1233 RTLIL::Cell
* addLut (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, RTLIL::Const lut
, const std::string
&src
= "");
1234 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
= "");
1235 RTLIL::Cell
* addAssert (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_en
, const std::string
&src
= "");
1236 RTLIL::Cell
* addAssume (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_en
, const std::string
&src
= "");
1237 RTLIL::Cell
* addLive (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_en
, const std::string
&src
= "");
1238 RTLIL::Cell
* addFair (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_en
, const std::string
&src
= "");
1239 RTLIL::Cell
* addCover (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_en
, const std::string
&src
= "");
1240 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
= "");
1242 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
= "");
1243 RTLIL::Cell
* addFf (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_d
, const RTLIL::SigSpec
&sig_q
, const std::string
&src
= "");
1244 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
= "");
1245 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
= "");
1246 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
= "");
1247 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
= "");
1248 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
= "");
1249 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
= "");
1251 RTLIL::Cell
* addBufGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_y
, const std::string
&src
= "");
1252 RTLIL::Cell
* addNotGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_y
, const std::string
&src
= "");
1253 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
= "");
1254 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
= "");
1255 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
= "");
1256 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
= "");
1257 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
= "");
1258 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
= "");
1259 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
= "");
1260 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
= "");
1261 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
= "");
1262 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
= "");
1263 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
= "");
1264 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
= "");
1265 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
= "");
1266 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
= "");
1268 RTLIL::Cell
* addFfGate (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_d
, const RTLIL::SigSpec
&sig_q
, const std::string
&src
= "");
1269 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
= "");
1270 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
= "");
1271 RTLIL::Cell
* addDffsrGate (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_clk
, const RTLIL::SigSpec
&sig_set
, const RTLIL::SigSpec
&sig_clr
,
1272 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
= "");
1273 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
,
1274 bool arst_value
= false, bool clk_polarity
= true, bool arst_polarity
= true, const std::string
&src
= "");
1275 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
= "");
1276 RTLIL::Cell
* addDlatchsrGate (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_en
, const RTLIL::SigSpec
&sig_set
, const RTLIL::SigSpec
&sig_clr
,
1277 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
= "");
1279 // The methods without the add* prefix create a cell and an output signal. They return the newly created output signal.
1281 RTLIL::SigSpec
Not (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, bool is_signed
= false, const std::string
&src
= "");
1282 RTLIL::SigSpec
Pos (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, bool is_signed
= false, const std::string
&src
= "");
1283 RTLIL::SigSpec
Bu0 (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, bool is_signed
= false, const std::string
&src
= "");
1284 RTLIL::SigSpec
Neg (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, bool is_signed
= false, const std::string
&src
= "");
1286 RTLIL::SigSpec
And (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1287 RTLIL::SigSpec
Or (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1288 RTLIL::SigSpec
Xor (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1289 RTLIL::SigSpec
Xnor (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1291 RTLIL::SigSpec
ReduceAnd (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, bool is_signed
= false, const std::string
&src
= "");
1292 RTLIL::SigSpec
ReduceOr (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, bool is_signed
= false, const std::string
&src
= "");
1293 RTLIL::SigSpec
ReduceXor (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, bool is_signed
= false, const std::string
&src
= "");
1294 RTLIL::SigSpec
ReduceXnor (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, bool is_signed
= false, const std::string
&src
= "");
1295 RTLIL::SigSpec
ReduceBool (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, bool is_signed
= false, const std::string
&src
= "");
1297 RTLIL::SigSpec
Shl (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1298 RTLIL::SigSpec
Shr (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1299 RTLIL::SigSpec
Sshl (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1300 RTLIL::SigSpec
Sshr (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1301 RTLIL::SigSpec
Shift (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1302 RTLIL::SigSpec
Shiftx (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1304 RTLIL::SigSpec
Lt (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1305 RTLIL::SigSpec
Le (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1306 RTLIL::SigSpec
Eq (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1307 RTLIL::SigSpec
Ne (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1308 RTLIL::SigSpec
Eqx (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1309 RTLIL::SigSpec
Nex (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1310 RTLIL::SigSpec
Ge (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1311 RTLIL::SigSpec
Gt (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1313 RTLIL::SigSpec
Add (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1314 RTLIL::SigSpec
Sub (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1315 RTLIL::SigSpec
Mul (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1316 // truncating division
1317 RTLIL::SigSpec
Div (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1318 // truncating modulo
1319 RTLIL::SigSpec
Mod (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1320 RTLIL::SigSpec
DivFloor (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1321 RTLIL::SigSpec
ModFloor (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1322 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
= "");
1324 RTLIL::SigSpec
LogicNot (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, bool is_signed
= false, const std::string
&src
= "");
1325 RTLIL::SigSpec
LogicAnd (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1326 RTLIL::SigSpec
LogicOr (RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, bool is_signed
= false, const std::string
&src
= "");
1328 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
= "");
1329 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
= "");
1331 RTLIL::SigBit
BufGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const std::string
&src
= "");
1332 RTLIL::SigBit
NotGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const std::string
&src
= "");
1333 RTLIL::SigBit
AndGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_b
, const std::string
&src
= "");
1334 RTLIL::SigBit
NandGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_b
, const std::string
&src
= "");
1335 RTLIL::SigBit
OrGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_b
, const std::string
&src
= "");
1336 RTLIL::SigBit
NorGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_b
, const std::string
&src
= "");
1337 RTLIL::SigBit
XorGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_b
, const std::string
&src
= "");
1338 RTLIL::SigBit
XnorGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_b
, const std::string
&src
= "");
1339 RTLIL::SigBit
AndnotGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_b
, const std::string
&src
= "");
1340 RTLIL::SigBit
OrnotGate (RTLIL::IdString name
, const RTLIL::SigBit
&sig_a
, const RTLIL::SigBit
&sig_b
, const std::string
&src
= "");
1341 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
= "");
1342 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
= "");
1343 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
= "");
1344 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
= "");
1345 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
= "");
1346 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
= "");
1348 RTLIL::SigSpec
Anyconst (RTLIL::IdString name
, int width
= 1, const std::string
&src
= "");
1349 RTLIL::SigSpec
Anyseq (RTLIL::IdString name
, int width
= 1, const std::string
&src
= "");
1350 RTLIL::SigSpec
Allconst (RTLIL::IdString name
, int width
= 1, const std::string
&src
= "");
1351 RTLIL::SigSpec
Allseq (RTLIL::IdString name
, int width
= 1, const std::string
&src
= "");
1352 RTLIL::SigSpec
Initstate (RTLIL::IdString name
, const std::string
&src
= "");
1355 static std::map
<unsigned int, RTLIL::Module
*> *get_all_modules(void);
1359 struct RTLIL::Wire
: public RTLIL::AttrObject
1361 unsigned int hashidx_
;
1362 unsigned int hash() const { return hashidx_
; }
1365 // use module->addWire() and module->remove() to create or destroy wires
1366 friend struct RTLIL::Module
;
1371 // do not simply copy wires
1372 Wire(RTLIL::Wire
&other
) = delete;
1373 void operator=(RTLIL::Wire
&other
) = delete;
1375 RTLIL::Module
*module
;
1376 RTLIL::IdString name
;
1377 int width
, start_offset
, port_id
;
1378 bool port_input
, port_output
, upto
, is_signed
;
1381 static std::map
<unsigned int, RTLIL::Wire
*> *get_all_wires(void);
1385 struct RTLIL::Memory
: public RTLIL::AttrObject
1387 unsigned int hashidx_
;
1388 unsigned int hash() const { return hashidx_
; }
1392 RTLIL::IdString name
;
1393 int width
, start_offset
, size
;
1396 static std::map
<unsigned int, RTLIL::Memory
*> *get_all_memorys(void);
1400 struct RTLIL::Cell
: public RTLIL::AttrObject
1402 unsigned int hashidx_
;
1403 unsigned int hash() const { return hashidx_
; }
1406 // use module->addCell() and module->remove() to create or destroy cells
1407 friend struct RTLIL::Module
;
1412 // do not simply copy cells
1413 Cell(RTLIL::Cell
&other
) = delete;
1414 void operator=(RTLIL::Cell
&other
) = delete;
1416 RTLIL::Module
*module
;
1417 RTLIL::IdString name
;
1418 RTLIL::IdString type
;
1419 dict
<RTLIL::IdString
, RTLIL::SigSpec
> connections_
;
1420 dict
<RTLIL::IdString
, RTLIL::Const
> parameters
;
1422 // access cell ports
1423 bool hasPort(RTLIL::IdString portname
) const;
1424 void unsetPort(RTLIL::IdString portname
);
1425 void setPort(RTLIL::IdString portname
, RTLIL::SigSpec signal
);
1426 const RTLIL::SigSpec
&getPort(RTLIL::IdString portname
) const;
1427 const dict
<RTLIL::IdString
, RTLIL::SigSpec
> &connections() const;
1429 // information about cell ports
1431 bool input(RTLIL::IdString portname
) const;
1432 bool output(RTLIL::IdString portname
) const;
1434 // access cell parameters
1435 bool hasParam(RTLIL::IdString paramname
) const;
1436 void unsetParam(RTLIL::IdString paramname
);
1437 void setParam(RTLIL::IdString paramname
, RTLIL::Const value
);
1438 const RTLIL::Const
&getParam(RTLIL::IdString paramname
) const;
1442 void fixup_parameters(bool set_a_signed
= false, bool set_b_signed
= false);
1444 bool has_keep_attr() const {
1445 return get_bool_attribute(ID::keep
) || (module
&& module
->design
&& module
->design
->module(type
) &&
1446 module
->design
->module(type
)->get_bool_attribute(ID::keep
));
1449 template<typename T
> void rewrite_sigspecs(T
&functor
);
1450 template<typename T
> void rewrite_sigspecs2(T
&functor
);
1453 static std::map
<unsigned int, RTLIL::Cell
*> *get_all_cells(void);
1457 struct RTLIL::CaseRule
: public RTLIL::AttrObject
1459 std::vector
<RTLIL::SigSpec
> compare
;
1460 std::vector
<RTLIL::SigSig
> actions
;
1461 std::vector
<RTLIL::SwitchRule
*> switches
;
1468 template<typename T
> void rewrite_sigspecs(T
&functor
);
1469 template<typename T
> void rewrite_sigspecs2(T
&functor
);
1470 RTLIL::CaseRule
*clone() const;
1473 struct RTLIL::SwitchRule
: public RTLIL::AttrObject
1475 RTLIL::SigSpec signal
;
1476 std::vector
<RTLIL::CaseRule
*> cases
;
1482 template<typename T
> void rewrite_sigspecs(T
&functor
);
1483 template<typename T
> void rewrite_sigspecs2(T
&functor
);
1484 RTLIL::SwitchRule
*clone() const;
1487 struct RTLIL::SyncRule
1489 RTLIL::SyncType type
;
1490 RTLIL::SigSpec signal
;
1491 std::vector
<RTLIL::SigSig
> actions
;
1493 template<typename T
> void rewrite_sigspecs(T
&functor
);
1494 template<typename T
> void rewrite_sigspecs2(T
&functor
);
1495 RTLIL::SyncRule
*clone() const;
1498 struct RTLIL::Process
: public RTLIL::AttrObject
1500 RTLIL::IdString name
;
1501 RTLIL::CaseRule root_case
;
1502 std::vector
<RTLIL::SyncRule
*> syncs
;
1506 template<typename T
> void rewrite_sigspecs(T
&functor
);
1507 template<typename T
> void rewrite_sigspecs2(T
&functor
);
1508 RTLIL::Process
*clone() const;
1512 inline RTLIL::SigBit::SigBit() : wire(NULL
), data(RTLIL::State::S0
) { }
1513 inline RTLIL::SigBit::SigBit(RTLIL::State bit
) : wire(NULL
), data(bit
) { }
1514 inline RTLIL::SigBit::SigBit(bool bit
) : wire(NULL
), data(bit
? State::S1
: State::S0
) { }
1515 inline RTLIL::SigBit::SigBit(RTLIL::Wire
*wire
) : wire(wire
), offset(0) { log_assert(wire
&& wire
->width
== 1); }
1516 inline RTLIL::SigBit::SigBit(RTLIL::Wire
*wire
, int offset
) : wire(wire
), offset(offset
) { log_assert(wire
!= nullptr); }
1517 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]; }
1518 inline RTLIL::SigBit::SigBit(const RTLIL::SigChunk
&chunk
, int index
) : wire(chunk
.wire
) { if (wire
) offset
= chunk
.offset
+ index
; else data
= chunk
.data
[index
]; }
1520 inline bool RTLIL::SigBit::operator<(const RTLIL::SigBit
&other
) const {
1521 if (wire
== other
.wire
)
1522 return wire
? (offset
< other
.offset
) : (data
< other
.data
);
1523 if (wire
!= nullptr && other
.wire
!= nullptr)
1524 return wire
->name
< other
.wire
->name
;
1525 return (wire
!= nullptr) < (other
.wire
!= nullptr);
1528 inline bool RTLIL::SigBit::operator==(const RTLIL::SigBit
&other
) const {
1529 return (wire
== other
.wire
) && (wire
? (offset
== other
.offset
) : (data
== other
.data
));
1532 inline bool RTLIL::SigBit::operator!=(const RTLIL::SigBit
&other
) const {
1533 return (wire
!= other
.wire
) || (wire
? (offset
!= other
.offset
) : (data
!= other
.data
));
1536 inline unsigned int RTLIL::SigBit::hash() const {
1538 return mkhash_add(wire
->name
.hash(), offset
);
1542 inline RTLIL::SigBit
&RTLIL::SigSpecIterator::operator*() const {
1543 return (*sig_p
)[index
];
1546 inline const RTLIL::SigBit
&RTLIL::SigSpecConstIterator::operator*() const {
1547 return (*sig_p
)[index
];
1550 inline RTLIL::SigBit::SigBit(const RTLIL::SigSpec
&sig
) {
1551 log_assert(sig
.size() == 1 && sig
.chunks().size() == 1);
1552 *this = SigBit(sig
.chunks().front());
1555 template<typename T
>
1556 void RTLIL::Module::rewrite_sigspecs(T
&functor
)
1558 for (auto &it
: cells_
)
1559 it
.second
->rewrite_sigspecs(functor
);
1560 for (auto &it
: processes
)
1561 it
.second
->rewrite_sigspecs(functor
);
1562 for (auto &it
: connections_
) {
1568 template<typename T
>
1569 void RTLIL::Module::rewrite_sigspecs2(T
&functor
)
1571 for (auto &it
: cells_
)
1572 it
.second
->rewrite_sigspecs2(functor
);
1573 for (auto &it
: processes
)
1574 it
.second
->rewrite_sigspecs2(functor
);
1575 for (auto &it
: connections_
) {
1576 functor(it
.first
, it
.second
);
1580 template<typename T
>
1581 void RTLIL::Cell::rewrite_sigspecs(T
&functor
) {
1582 for (auto &it
: connections_
)
1586 template<typename T
>
1587 void RTLIL::Cell::rewrite_sigspecs2(T
&functor
) {
1588 for (auto &it
: connections_
)
1592 template<typename T
>
1593 void RTLIL::CaseRule::rewrite_sigspecs(T
&functor
) {
1594 for (auto &it
: compare
)
1596 for (auto &it
: actions
) {
1600 for (auto it
: switches
)
1601 it
->rewrite_sigspecs(functor
);
1604 template<typename T
>
1605 void RTLIL::CaseRule::rewrite_sigspecs2(T
&functor
) {
1606 for (auto &it
: compare
)
1608 for (auto &it
: actions
) {
1609 functor(it
.first
, it
.second
);
1611 for (auto it
: switches
)
1612 it
->rewrite_sigspecs2(functor
);
1615 template<typename T
>
1616 void RTLIL::SwitchRule::rewrite_sigspecs(T
&functor
)
1619 for (auto it
: cases
)
1620 it
->rewrite_sigspecs(functor
);
1623 template<typename T
>
1624 void RTLIL::SwitchRule::rewrite_sigspecs2(T
&functor
)
1627 for (auto it
: cases
)
1628 it
->rewrite_sigspecs2(functor
);
1631 template<typename T
>
1632 void RTLIL::SyncRule::rewrite_sigspecs(T
&functor
)
1635 for (auto &it
: actions
) {
1641 template<typename T
>
1642 void RTLIL::SyncRule::rewrite_sigspecs2(T
&functor
)
1645 for (auto &it
: actions
) {
1646 functor(it
.first
, it
.second
);
1650 template<typename T
>
1651 void RTLIL::Process::rewrite_sigspecs(T
&functor
)
1653 root_case
.rewrite_sigspecs(functor
);
1654 for (auto it
: syncs
)
1655 it
->rewrite_sigspecs(functor
);
1658 template<typename T
>
1659 void RTLIL::Process::rewrite_sigspecs2(T
&functor
)
1661 root_case
.rewrite_sigspecs2(functor
);
1662 for (auto it
: syncs
)
1663 it
->rewrite_sigspecs2(functor
);