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
82 // the global id string cache
84 static struct destruct_guard_t
{
85 bool ok
; // POD, will be initialized to zero
86 destruct_guard_t() { ok
= true; }
87 ~destruct_guard_t() { ok
= false; }
90 static std::vector
<int> global_refcount_storage_
;
91 static std::vector
<char*> global_id_storage_
;
92 static dict
<char*, int, hash_cstr_ops
> global_id_index_
;
93 static std::vector
<int> global_free_idx_list_
;
95 static int last_created_idx_ptr_
;
96 static int last_created_idx_
[8];
98 static inline void xtrace_db_dump()
100 #ifdef YOSYS_XTRACE_GET_PUT
101 for (int idx
= 0; idx
< GetSize(global_id_storage_
); idx
++)
103 if (global_id_storage_
.at(idx
) == nullptr)
104 log("#X# DB-DUMP index %d: FREE\n", idx
);
106 log("#X# DB-DUMP index %d: '%s' (ref %d)\n", idx
, global_id_storage_
.at(idx
), global_refcount_storage_
.at(idx
));
111 static inline void checkpoint()
113 last_created_idx_ptr_
= 0;
114 for (int i
= 0; i
< 8; i
++) {
115 if (last_created_idx_
[i
])
116 put_reference(last_created_idx_
[i
]);
117 last_created_idx_
[i
] = 0;
119 #ifdef YOSYS_SORT_ID_FREE_LIST
120 std::sort(global_free_idx_list_
.begin(), global_free_idx_list_
.end(), std::greater
<int>());
124 static inline int get_reference(int idx
)
126 global_refcount_storage_
.at(idx
)++;
127 #ifdef YOSYS_XTRACE_GET_PUT
129 log("#X# GET-BY-INDEX '%s' (index %d, refcount %d)\n", global_id_storage_
.at(idx
), idx
, global_refcount_storage_
.at(idx
));
135 static inline int get_reference(const char *p
)
137 log_assert(destruct_guard
.ok
);
140 log_assert(p
[1] != 0);
141 log_assert(p
[0] == '$' || p
[0] == '\\');
144 auto it
= global_id_index_
.find((char*)p
);
145 if (it
!= global_id_index_
.end()) {
146 global_refcount_storage_
.at(it
->second
)++;
147 #ifdef YOSYS_XTRACE_GET_PUT
149 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
));
155 if (global_free_idx_list_
.empty()) {
156 log_assert(global_id_storage_
.size() < 0x40000000);
157 global_free_idx_list_
.push_back(global_id_storage_
.size());
158 global_id_storage_
.push_back(nullptr);
159 global_refcount_storage_
.push_back(0);
162 int idx
= global_free_idx_list_
.back();
163 global_free_idx_list_
.pop_back();
164 global_id_storage_
.at(idx
) = strdup(p
);
165 global_id_index_
[global_id_storage_
.at(idx
)] = idx
;
166 global_refcount_storage_
.at(idx
)++;
168 // Avoid Create->Delete->Create pattern
169 if (last_created_idx_
[last_created_idx_ptr_
])
170 put_reference(last_created_idx_
[last_created_idx_ptr_
]);
171 last_created_idx_
[last_created_idx_ptr_
] = idx
;
172 get_reference(last_created_idx_
[last_created_idx_ptr_
]);
173 last_created_idx_ptr_
= (last_created_idx_ptr_
+ 1) & 7;
176 log("#X# New IdString '%s' with index %d.\n", p
, idx
);
177 log_backtrace("-X- ", yosys_xtrace
-1);
180 #ifdef YOSYS_XTRACE_GET_PUT
182 log("#X# GET-BY-NAME '%s' (index %d, refcount %d)\n", global_id_storage_
.at(idx
), idx
, global_refcount_storage_
.at(idx
));
188 static inline void put_reference(int idx
)
190 // put_reference() may be called from destructors after the destructor of
191 // global_refcount_storage_ has been run. in this case we simply do nothing.
192 if (!destruct_guard
.ok
)
195 #ifdef YOSYS_XTRACE_GET_PUT
197 log("#X# PUT '%s' (index %d, refcount %d)\n", global_id_storage_
.at(idx
), idx
, global_refcount_storage_
.at(idx
));
201 log_assert(global_refcount_storage_
.at(idx
) > 0);
203 if (--global_refcount_storage_
.at(idx
) != 0)
207 log("#X# Removed IdString '%s' with index %d.\n", global_id_storage_
.at(idx
), idx
);
208 log_backtrace("-X- ", yosys_xtrace
-1);
211 global_id_index_
.erase(global_id_storage_
.at(idx
));
212 free(global_id_storage_
.at(idx
));
213 global_id_storage_
.at(idx
) = nullptr;
214 global_free_idx_list_
.push_back(idx
);
217 // the actual IdString object is just is a single int
221 IdString() : index_(get_reference("")) { }
222 IdString(const char *str
) : index_(get_reference(str
)) { }
223 IdString(const IdString
&str
) : index_(get_reference(str
.index_
)) { }
224 IdString(const std::string
&str
) : index_(get_reference(str
.c_str())) { }
225 ~IdString() { put_reference(index_
); }
227 void operator=(const IdString
&rhs
) {
228 put_reference(index_
);
229 index_
= get_reference(rhs
.index_
);
232 void operator=(const char *rhs
) {
237 void operator=(const std::string
&rhs
) {
242 const char *c_str() const {
243 return global_id_storage_
.at(index_
);
246 std::string
str() const {
247 return std::string(global_id_storage_
.at(index_
));
250 bool operator<(const IdString
&rhs
) const {
251 return index_
< rhs
.index_
;
254 bool operator==(const IdString
&rhs
) const { return index_
== rhs
.index_
; }
255 bool operator!=(const IdString
&rhs
) const { return index_
!= rhs
.index_
; }
257 // The methods below are just convenience functions for better compatibility with std::string.
259 bool operator==(const std::string
&rhs
) const { return str() == rhs
; }
260 bool operator!=(const std::string
&rhs
) const { return str() != rhs
; }
262 bool operator==(const char *rhs
) const { return strcmp(c_str(), rhs
) == 0; }
263 bool operator!=(const char *rhs
) const { return strcmp(c_str(), rhs
) != 0; }
265 char operator[](size_t i
) const {
266 const char *p
= c_str();
267 for (; i
!= 0; i
--, p
++)
272 std::string
substr(size_t pos
= 0, size_t len
= std::string::npos
) const {
273 if (len
== std::string::npos
|| len
>= strlen(c_str() + pos
))
274 return std::string(c_str() + pos
);
276 return std::string(c_str() + pos
, len
);
279 bool begins_with(const char* prefix
) const {
280 size_t len
= strlen(prefix
);
281 if (size() < len
) return false;
282 return substr(0, len
) == prefix
;
285 bool ends_with(const char* suffix
) const {
286 size_t len
= strlen(suffix
);
287 if (size() < len
) return false;
288 return substr(size()-len
) == suffix
;
291 size_t size() const {
296 return c_str()[0] == 0;
303 unsigned int hash() const {
307 // The following is a helper key_compare class. Instead of for example std::set<Cell*>
308 // use std::set<Cell*, IdString::compare_ptr_by_name<Cell>> if the order of cells in the
309 // set has an influence on the algorithm.
311 template<typename T
> struct compare_ptr_by_name
{
312 bool operator()(const T
*a
, const T
*b
) const {
313 return (a
== nullptr || b
== nullptr) ? (a
< b
) : (a
->name
< b
->name
);
317 // often one needs to check if a given IdString is part of a list (for example a list
318 // of cell types). the following functions helps with that.
320 template<typename T
, typename
... Args
>
321 bool in(T first
, Args
... rest
) const {
322 return in(first
) || in(rest
...);
325 bool in(IdString rhs
) const { return *this == rhs
; }
326 bool in(const char *rhs
) const { return *this == rhs
; }
327 bool in(const std::string
&rhs
) const { return *this == rhs
; }
328 bool in(const pool
<IdString
> &rhs
) const { return rhs
.count(*this) != 0; }
331 static inline std::string
escape_id(std::string str
) {
332 if (str
.size() > 0 && str
[0] != '\\' && str
[0] != '$')
337 static inline std::string
unescape_id(std::string str
) {
342 if (str
[1] == '$' || str
[1] == '\\')
344 if (str
[1] >= '0' && str
[1] <= '9')
346 return str
.substr(1);
349 static inline std::string
unescape_id(RTLIL::IdString str
) {
350 return unescape_id(str
.str());
353 static inline const char *id2cstr(const RTLIL::IdString
&str
) {
357 template <typename T
> struct sort_by_name_id
{
358 bool operator()(T
*a
, T
*b
) const {
359 return a
->name
< b
->name
;
363 template <typename T
> struct sort_by_name_str
{
364 bool operator()(T
*a
, T
*b
) const {
365 return strcmp(a
->name
.c_str(), b
->name
.c_str()) < 0;
369 struct sort_by_id_str
{
370 bool operator()(RTLIL::IdString a
, RTLIL::IdString b
) const {
371 return strcmp(a
.c_str(), b
.c_str()) < 0;
375 // see calc.cc for the implementation of this functions
376 RTLIL::Const
const_not (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
377 RTLIL::Const
const_and (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
378 RTLIL::Const
const_or (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
379 RTLIL::Const
const_xor (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
380 RTLIL::Const
const_xnor (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
382 RTLIL::Const
const_reduce_and (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
383 RTLIL::Const
const_reduce_or (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
384 RTLIL::Const
const_reduce_xor (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
385 RTLIL::Const
const_reduce_xnor (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
386 RTLIL::Const
const_reduce_bool (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
388 RTLIL::Const
const_logic_not (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
389 RTLIL::Const
const_logic_and (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
390 RTLIL::Const
const_logic_or (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
392 RTLIL::Const
const_shl (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
393 RTLIL::Const
const_shr (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
394 RTLIL::Const
const_sshl (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
395 RTLIL::Const
const_sshr (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
396 RTLIL::Const
const_shift (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
397 RTLIL::Const
const_shiftx (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
399 RTLIL::Const
const_lt (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
400 RTLIL::Const
const_le (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
401 RTLIL::Const
const_eq (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
402 RTLIL::Const
const_ne (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
403 RTLIL::Const
const_eqx (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
404 RTLIL::Const
const_nex (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
405 RTLIL::Const
const_ge (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
406 RTLIL::Const
const_gt (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
408 RTLIL::Const
const_add (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
409 RTLIL::Const
const_sub (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
410 RTLIL::Const
const_mul (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
411 RTLIL::Const
const_div (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
412 RTLIL::Const
const_mod (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
413 RTLIL::Const
const_pow (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
415 RTLIL::Const
const_pos (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
416 RTLIL::Const
const_neg (const RTLIL::Const
&arg1
, const RTLIL::Const
&arg2
, bool signed1
, bool signed2
, int result_len
);
419 // This iterator-range-pair is used for Design::modules(), Module::wires() and Module::cells().
420 // It maintains a reference counter that is used to make sure that the container is not modified while being iterated over.
425 typename dict
<RTLIL::IdString
, T
>::iterator it
;
426 dict
<RTLIL::IdString
, T
> *list_p
;
429 ObjIterator() : list_p(nullptr), refcount_p(nullptr) {
432 ObjIterator(decltype(list_p
) list_p
, int *refcount_p
) : list_p(list_p
), refcount_p(refcount_p
) {
433 if (list_p
->empty()) {
434 this->list_p
= nullptr;
435 this->refcount_p
= nullptr;
437 it
= list_p
->begin();
442 ObjIterator(const RTLIL::ObjIterator
<T
> &other
) {
444 list_p
= other
.list_p
;
445 refcount_p
= other
.refcount_p
;
450 ObjIterator
&operator=(const RTLIL::ObjIterator
<T
> &other
) {
454 list_p
= other
.list_p
;
455 refcount_p
= other
.refcount_p
;
466 inline T
operator*() const {
467 log_assert(list_p
!= nullptr);
471 inline bool operator!=(const RTLIL::ObjIterator
<T
> &other
) const {
472 if (list_p
== nullptr || other
.list_p
== nullptr)
473 return list_p
!= other
.list_p
;
474 return it
!= other
.it
;
477 inline void operator++() {
478 log_assert(list_p
!= nullptr);
479 if (++it
== list_p
->end()) {
482 refcount_p
= nullptr;
490 dict
<RTLIL::IdString
, T
> *list_p
;
493 ObjRange(decltype(list_p
) list_p
, int *refcount_p
) : list_p(list_p
), refcount_p(refcount_p
) { }
494 RTLIL::ObjIterator
<T
> begin() { return RTLIL::ObjIterator
<T
>(list_p
, refcount_p
); }
495 RTLIL::ObjIterator
<T
> end() { return RTLIL::ObjIterator
<T
>(); }
497 size_t size() const {
498 return list_p
->size();
501 operator pool
<T
>() const {
503 for (auto &it
: *list_p
)
504 result
.insert(it
.second
);
508 operator std::vector
<T
>() const {
509 std::vector
<T
> result
;
510 result
.reserve(list_p
->size());
511 for (auto &it
: *list_p
)
512 result
.push_back(it
.second
);
516 pool
<T
> to_pool() const { return *this; }
517 std::vector
<T
> to_vector() const { return *this; }
524 std::vector
<RTLIL::State
> bits
;
527 Const(std::string str
);
528 Const(int val
, int width
= 32);
529 Const(RTLIL::State bit
, int width
= 1);
530 Const(const std::vector
<RTLIL::State
> &bits
) : bits(bits
) { flags
= CONST_FLAG_NONE
; }
531 Const(const std::vector
<bool> &bits
);
532 Const(const RTLIL::Const
&c
);
533 RTLIL::Const
&operator =(const RTLIL::Const
&other
) = default;
535 bool operator <(const RTLIL::Const
&other
) const;
536 bool operator ==(const RTLIL::Const
&other
) const;
537 bool operator !=(const RTLIL::Const
&other
) const;
539 bool as_bool() const;
540 int as_int(bool is_signed
= false) const;
541 std::string
as_string() const;
542 static Const
from_string(std::string str
);
544 std::string
decode_string() const;
546 inline int size() const { return bits
.size(); }
547 inline RTLIL::State
&operator[](int index
) { return bits
.at(index
); }
548 inline const RTLIL::State
&operator[](int index
) const { return bits
.at(index
); }
550 bool is_fully_zero() const;
551 bool is_fully_ones() const;
552 bool is_fully_def() const;
553 bool is_fully_undef() const;
555 inline RTLIL::Const
extract(int offset
, int len
= 1, RTLIL::State padding
= RTLIL::State::S0
) const {
557 ret
.bits
.reserve(len
);
558 for (int i
= offset
; i
< offset
+ len
; i
++)
559 ret
.bits
.push_back(i
< GetSize(bits
) ? bits
[i
] : padding
);
563 void extu(int width
) {
564 bits
.resize(width
, RTLIL::State::S0
);
567 void exts(int width
) {
568 bits
.resize(width
, bits
.empty() ? RTLIL::State::Sx
: bits
.back());
571 inline unsigned int hash() const {
572 unsigned int h
= mkhash_init
;
579 struct RTLIL::AttrObject
581 dict
<RTLIL::IdString
, RTLIL::Const
> attributes
;
583 void set_bool_attribute(RTLIL::IdString id
, bool value
=true);
584 bool get_bool_attribute(RTLIL::IdString id
) const;
586 bool get_blackbox_attribute(bool ignore_wb
=false) const {
587 return get_bool_attribute("\\blackbox") || (!ignore_wb
&& get_bool_attribute("\\whitebox"));
590 void set_strpool_attribute(RTLIL::IdString id
, const pool
<string
> &data
);
591 void add_strpool_attribute(RTLIL::IdString id
, const pool
<string
> &data
);
592 pool
<string
> get_strpool_attribute(RTLIL::IdString id
) const;
594 void set_src_attribute(const std::string
&src
);
595 std::string
get_src_attribute() const;
598 struct RTLIL::SigChunk
601 std::vector
<RTLIL::State
> data
; // only used if wire == NULL, LSB at index 0
605 SigChunk(const RTLIL::Const
&value
);
606 SigChunk(RTLIL::Wire
*wire
);
607 SigChunk(RTLIL::Wire
*wire
, int offset
, int width
= 1);
608 SigChunk(const std::string
&str
);
609 SigChunk(int val
, int width
= 32);
610 SigChunk(RTLIL::State bit
, int width
= 1);
611 SigChunk(RTLIL::SigBit bit
);
612 SigChunk(const RTLIL::SigChunk
&sigchunk
);
613 RTLIL::SigChunk
&operator =(const RTLIL::SigChunk
&other
) = default;
615 RTLIL::SigChunk
extract(int offset
, int length
) const;
616 inline int size() const { return width
; }
618 bool operator <(const RTLIL::SigChunk
&other
) const;
619 bool operator ==(const RTLIL::SigChunk
&other
) const;
620 bool operator !=(const RTLIL::SigChunk
&other
) const;
627 RTLIL::State data
; // used if wire == NULL
628 int offset
; // used if wire != NULL
632 SigBit(RTLIL::State bit
);
634 SigBit(RTLIL::Wire
*wire
);
635 SigBit(RTLIL::Wire
*wire
, int offset
);
636 SigBit(const RTLIL::SigChunk
&chunk
);
637 SigBit(const RTLIL::SigChunk
&chunk
, int index
);
638 SigBit(const RTLIL::SigSpec
&sig
);
639 SigBit(const RTLIL::SigBit
&sigbit
);
640 RTLIL::SigBit
&operator =(const RTLIL::SigBit
&other
) = default;
642 bool operator <(const RTLIL::SigBit
&other
) const;
643 bool operator ==(const RTLIL::SigBit
&other
) const;
644 bool operator !=(const RTLIL::SigBit
&other
) const;
645 unsigned int hash() const;
648 struct RTLIL::SigSpecIterator
: public std::iterator
<std::input_iterator_tag
, RTLIL::SigSpec
>
650 RTLIL::SigSpec
*sig_p
;
653 inline RTLIL::SigBit
&operator*() const;
654 inline bool operator!=(const RTLIL::SigSpecIterator
&other
) const { return index
!= other
.index
; }
655 inline bool operator==(const RTLIL::SigSpecIterator
&other
) const { return index
== other
.index
; }
656 inline void operator++() { index
++; }
659 struct RTLIL::SigSpecConstIterator
: public std::iterator
<std::input_iterator_tag
, RTLIL::SigSpec
>
661 const RTLIL::SigSpec
*sig_p
;
664 inline const RTLIL::SigBit
&operator*() const;
665 inline bool operator!=(const RTLIL::SigSpecConstIterator
&other
) const { return index
!= other
.index
; }
666 inline bool operator==(const RTLIL::SigSpecIterator
&other
) const { return index
== other
.index
; }
667 inline void operator++() { index
++; }
670 struct RTLIL::SigSpec
675 std::vector
<RTLIL::SigChunk
> chunks_
; // LSB at index 0
676 std::vector
<RTLIL::SigBit
> bits_
; // LSB at index 0
680 void updhash() const;
682 inline bool packed() const {
683 return bits_
.empty();
686 inline void inline_unpack() const {
687 if (!chunks_
.empty())
693 SigSpec(const RTLIL::SigSpec
&other
);
694 SigSpec(std::initializer_list
<RTLIL::SigSpec
> parts
);
695 const RTLIL::SigSpec
&operator=(const RTLIL::SigSpec
&other
);
697 SigSpec(const RTLIL::Const
&value
);
698 SigSpec(const RTLIL::SigChunk
&chunk
);
699 SigSpec(RTLIL::Wire
*wire
);
700 SigSpec(RTLIL::Wire
*wire
, int offset
, int width
= 1);
701 SigSpec(const std::string
&str
);
702 SigSpec(int val
, int width
= 32);
703 SigSpec(RTLIL::State bit
, int width
= 1);
704 SigSpec(RTLIL::SigBit bit
, int width
= 1);
705 SigSpec(std::vector
<RTLIL::SigChunk
> chunks
);
706 SigSpec(std::vector
<RTLIL::SigBit
> bits
);
707 SigSpec(pool
<RTLIL::SigBit
> bits
);
708 SigSpec(std::set
<RTLIL::SigBit
> bits
);
711 SigSpec(RTLIL::SigSpec
&&other
) {
712 width_
= other
.width_
;
714 chunks_
= std::move(other
.chunks_
);
715 bits_
= std::move(other
.bits_
);
718 const RTLIL::SigSpec
&operator=(RTLIL::SigSpec
&&other
) {
719 width_
= other
.width_
;
721 chunks_
= std::move(other
.chunks_
);
722 bits_
= std::move(other
.bits_
);
726 size_t get_hash() const {
731 inline const std::vector
<RTLIL::SigChunk
> &chunks() const { pack(); return chunks_
; }
732 inline const std::vector
<RTLIL::SigBit
> &bits() const { inline_unpack(); return bits_
; }
734 inline int size() const { return width_
; }
735 inline bool empty() const { return width_
== 0; }
737 inline RTLIL::SigBit
&operator[](int index
) { inline_unpack(); return bits_
.at(index
); }
738 inline const RTLIL::SigBit
&operator[](int index
) const { inline_unpack(); return bits_
.at(index
); }
740 inline RTLIL::SigSpecIterator
begin() { RTLIL::SigSpecIterator it
; it
.sig_p
= this; it
.index
= 0; return it
; }
741 inline RTLIL::SigSpecIterator
end() { RTLIL::SigSpecIterator it
; it
.sig_p
= this; it
.index
= width_
; return it
; }
743 inline RTLIL::SigSpecConstIterator
begin() const { RTLIL::SigSpecConstIterator it
; it
.sig_p
= this; it
.index
= 0; return it
; }
744 inline RTLIL::SigSpecConstIterator
end() const { RTLIL::SigSpecConstIterator it
; it
.sig_p
= this; it
.index
= width_
; return it
; }
747 void sort_and_unify();
749 void replace(const RTLIL::SigSpec
&pattern
, const RTLIL::SigSpec
&with
);
750 void replace(const RTLIL::SigSpec
&pattern
, const RTLIL::SigSpec
&with
, RTLIL::SigSpec
*other
) const;
752 void replace(const dict
<RTLIL::SigBit
, RTLIL::SigBit
> &rules
);
753 void replace(const dict
<RTLIL::SigBit
, RTLIL::SigBit
> &rules
, RTLIL::SigSpec
*other
) const;
755 void replace(const std::map
<RTLIL::SigBit
, RTLIL::SigBit
> &rules
);
756 void replace(const std::map
<RTLIL::SigBit
, RTLIL::SigBit
> &rules
, RTLIL::SigSpec
*other
) const;
758 void replace(int offset
, const RTLIL::SigSpec
&with
);
760 void remove(const RTLIL::SigSpec
&pattern
);
761 void remove(const RTLIL::SigSpec
&pattern
, RTLIL::SigSpec
*other
) const;
762 void remove2(const RTLIL::SigSpec
&pattern
, RTLIL::SigSpec
*other
);
764 void remove(const pool
<RTLIL::SigBit
> &pattern
);
765 void remove(const pool
<RTLIL::SigBit
> &pattern
, RTLIL::SigSpec
*other
) const;
766 void remove2(const pool
<RTLIL::SigBit
> &pattern
, RTLIL::SigSpec
*other
);
767 void remove2(const std::set
<RTLIL::SigBit
> &pattern
, RTLIL::SigSpec
*other
);
769 void remove(int offset
, int length
= 1);
772 RTLIL::SigSpec
extract(const RTLIL::SigSpec
&pattern
, const RTLIL::SigSpec
*other
= NULL
) const;
773 RTLIL::SigSpec
extract(const pool
<RTLIL::SigBit
> &pattern
, const RTLIL::SigSpec
*other
= NULL
) const;
774 RTLIL::SigSpec
extract(int offset
, int length
= 1) const;
776 void append(const RTLIL::SigSpec
&signal
);
777 void append_bit(const RTLIL::SigBit
&bit
);
779 void extend_u0(int width
, bool is_signed
= false);
781 RTLIL::SigSpec
repeat(int num
) const;
783 bool operator <(const RTLIL::SigSpec
&other
) const;
784 bool operator ==(const RTLIL::SigSpec
&other
) const;
785 inline bool operator !=(const RTLIL::SigSpec
&other
) const { return !(*this == other
); }
787 bool is_wire() const;
788 bool is_chunk() const;
789 inline bool is_bit() const { return width_
== 1; }
791 bool is_fully_const() const;
792 bool is_fully_zero() const;
793 bool is_fully_ones() const;
794 bool is_fully_def() const;
795 bool is_fully_undef() const;
796 bool has_const() const;
797 bool has_marked_bits() const;
799 bool as_bool() const;
800 int as_int(bool is_signed
= false) const;
801 std::string
as_string() const;
802 RTLIL::Const
as_const() const;
803 RTLIL::Wire
*as_wire() const;
804 RTLIL::SigChunk
as_chunk() const;
805 RTLIL::SigBit
as_bit() const;
807 bool match(std::string pattern
) const;
809 std::set
<RTLIL::SigBit
> to_sigbit_set() const;
810 pool
<RTLIL::SigBit
> to_sigbit_pool() const;
811 std::vector
<RTLIL::SigBit
> to_sigbit_vector() const;
812 std::map
<RTLIL::SigBit
, RTLIL::SigBit
> to_sigbit_map(const RTLIL::SigSpec
&other
) const;
813 dict
<RTLIL::SigBit
, RTLIL::SigBit
> to_sigbit_dict(const RTLIL::SigSpec
&other
) const;
815 static bool parse(RTLIL::SigSpec
&sig
, RTLIL::Module
*module
, std::string str
);
816 static bool parse_sel(RTLIL::SigSpec
&sig
, RTLIL::Design
*design
, RTLIL::Module
*module
, std::string str
);
817 static bool parse_rhs(const RTLIL::SigSpec
&lhs
, RTLIL::SigSpec
&sig
, RTLIL::Module
*module
, std::string str
);
819 operator std::vector
<RTLIL::SigChunk
>() const { return chunks(); }
820 operator std::vector
<RTLIL::SigBit
>() const { return bits(); }
822 unsigned int hash() const { if (!hash_
) updhash(); return hash_
; };
827 void check() const { }
831 struct RTLIL::Selection
834 pool
<RTLIL::IdString
> selected_modules
;
835 dict
<RTLIL::IdString
, pool
<RTLIL::IdString
>> selected_members
;
837 Selection(bool full
= true) : full_selection(full
) { }
839 bool selected_module(RTLIL::IdString mod_name
) const;
840 bool selected_whole_module(RTLIL::IdString mod_name
) const;
841 bool selected_member(RTLIL::IdString mod_name
, RTLIL::IdString memb_name
) const;
842 void optimize(RTLIL::Design
*design
);
844 template<typename T1
> void select(T1
*module
) {
845 if (!full_selection
&& selected_modules
.count(module
->name
) == 0) {
846 selected_modules
.insert(module
->name
);
847 selected_members
.erase(module
->name
);
851 template<typename T1
, typename T2
> void select(T1
*module
, T2
*member
) {
852 if (!full_selection
&& selected_modules
.count(module
->name
) == 0)
853 selected_members
[module
->name
].insert(member
->name
);
857 return !full_selection
&& selected_modules
.empty() && selected_members
.empty();
861 struct RTLIL::Monitor
863 unsigned int hashidx_
;
864 unsigned int hash() const { return hashidx_
; }
867 static unsigned int hashidx_count
= 123456789;
868 hashidx_count
= mkhash_xorshift(hashidx_count
);
869 hashidx_
= hashidx_count
;
872 virtual ~Monitor() { }
873 virtual void notify_module_add(RTLIL::Module
*) { }
874 virtual void notify_module_del(RTLIL::Module
*) { }
875 virtual void notify_connect(RTLIL::Cell
*, const RTLIL::IdString
&, const RTLIL::SigSpec
&, RTLIL::SigSpec
&) { }
876 virtual void notify_connect(RTLIL::Module
*, const RTLIL::SigSig
&) { }
877 virtual void notify_connect(RTLIL::Module
*, const std::vector
<RTLIL::SigSig
>&) { }
878 virtual void notify_blackout(RTLIL::Module
*) { }
883 unsigned int hashidx_
;
884 unsigned int hash() const { return hashidx_
; }
886 pool
<RTLIL::Monitor
*> monitors
;
887 dict
<std::string
, std::string
> scratchpad
;
889 int refcount_modules_
;
890 dict
<RTLIL::IdString
, RTLIL::Module
*> modules_
;
891 std::vector
<AST::AstNode
*> verilog_packages
, verilog_globals
;
892 dict
<std::string
, std::pair
<std::string
, bool>> verilog_defines
;
894 std::vector
<RTLIL::Selection
> selection_stack
;
895 dict
<RTLIL::IdString
, RTLIL::Selection
> selection_vars
;
896 std::string selected_active_module
;
901 RTLIL::ObjRange
<RTLIL::Module
*> modules();
902 RTLIL::Module
*module(RTLIL::IdString name
);
903 RTLIL::Module
*top_module();
905 bool has(RTLIL::IdString id
) const {
906 return modules_
.count(id
) != 0;
909 void add(RTLIL::Module
*module
);
910 RTLIL::Module
*addModule(RTLIL::IdString name
);
911 void remove(RTLIL::Module
*module
);
912 void rename(RTLIL::Module
*module
, RTLIL::IdString new_name
);
914 void scratchpad_unset(std::string varname
);
916 void scratchpad_set_int(std::string varname
, int value
);
917 void scratchpad_set_bool(std::string varname
, bool value
);
918 void scratchpad_set_string(std::string varname
, std::string value
);
920 int scratchpad_get_int(std::string varname
, int default_value
= 0) const;
921 bool scratchpad_get_bool(std::string varname
, bool default_value
= false) const;
922 std::string
scratchpad_get_string(std::string varname
, std::string default_value
= std::string()) const;
928 bool selected_module(RTLIL::IdString mod_name
) const;
929 bool selected_whole_module(RTLIL::IdString mod_name
) const;
930 bool selected_member(RTLIL::IdString mod_name
, RTLIL::IdString memb_name
) const;
932 bool selected_module(RTLIL::Module
*mod
) const;
933 bool selected_whole_module(RTLIL::Module
*mod
) const;
935 RTLIL::Selection
&selection() {
936 return selection_stack
.back();
939 const RTLIL::Selection
&selection() const {
940 return selection_stack
.back();
943 bool full_selection() const {
944 return selection_stack
.back().full_selection
;
947 template<typename T1
> bool selected(T1
*module
) const {
948 return selected_module(module
->name
);
951 template<typename T1
, typename T2
> bool selected(T1
*module
, T2
*member
) const {
952 return selected_member(module
->name
, member
->name
);
955 template<typename T1
, typename T2
> void select(T1
*module
, T2
*member
) {
956 if (selection_stack
.size() > 0) {
957 RTLIL::Selection
&sel
= selection_stack
.back();
958 sel
.select(module
, member
);
963 std::vector
<RTLIL::Module
*> selected_modules() const;
964 std::vector
<RTLIL::Module
*> selected_whole_modules() const;
965 std::vector
<RTLIL::Module
*> selected_whole_modules_warn() const;
967 static std::map
<unsigned int, RTLIL::Design
*> *get_all_designs(void);
971 struct RTLIL::Module
: public RTLIL::AttrObject
973 unsigned int hashidx_
;
974 unsigned int hash() const { return hashidx_
; }
977 void add(RTLIL::Wire
*wire
);
978 void add(RTLIL::Cell
*cell
);
981 RTLIL::Design
*design
;
982 pool
<RTLIL::Monitor
*> monitors
;
987 dict
<RTLIL::IdString
, RTLIL::Wire
*> wires_
;
988 dict
<RTLIL::IdString
, RTLIL::Cell
*> cells_
;
989 std::vector
<RTLIL::SigSig
> connections_
;
991 RTLIL::IdString name
;
992 pool
<RTLIL::IdString
> avail_parameters
;
993 dict
<RTLIL::IdString
, RTLIL::Memory
*> memories
;
994 dict
<RTLIL::IdString
, RTLIL::Process
*> processes
;
998 virtual RTLIL::IdString
derive(RTLIL::Design
*design
, dict
<RTLIL::IdString
, RTLIL::Const
> parameters
, bool mayfail
= false);
999 virtual RTLIL::IdString
derive(RTLIL::Design
*design
, dict
<RTLIL::IdString
, RTLIL::Const
> parameters
, dict
<RTLIL::IdString
, RTLIL::Module
*> interfaces
, dict
<RTLIL::IdString
, RTLIL::IdString
> modports
, bool mayfail
= false);
1000 virtual size_t count_id(RTLIL::IdString id
);
1001 virtual void reprocess_module(RTLIL::Design
*design
, dict
<RTLIL::IdString
, RTLIL::Module
*> local_interfaces
);
1003 virtual void sort();
1004 virtual void check();
1005 virtual void optimize();
1006 virtual void makeblackbox();
1008 void connect(const RTLIL::SigSig
&conn
);
1009 void connect(const RTLIL::SigSpec
&lhs
, const RTLIL::SigSpec
&rhs
);
1010 void new_connections(const std::vector
<RTLIL::SigSig
> &new_conn
);
1011 const std::vector
<RTLIL::SigSig
> &connections() const;
1013 std::vector
<RTLIL::IdString
> ports
;
1016 template<typename T
> void rewrite_sigspecs(T
&functor
);
1017 template<typename T
> void rewrite_sigspecs2(T
&functor
);
1018 void cloneInto(RTLIL::Module
*new_mod
) const;
1019 virtual RTLIL::Module
*clone() const;
1021 bool has_memories() const;
1022 bool has_processes() const;
1024 bool has_memories_warn() const;
1025 bool has_processes_warn() const;
1027 std::vector
<RTLIL::Wire
*> selected_wires() const;
1028 std::vector
<RTLIL::Cell
*> selected_cells() const;
1030 template<typename T
> bool selected(T
*member
) const {
1031 return design
->selected_member(name
, member
->name
);
1034 RTLIL::Wire
* wire(RTLIL::IdString id
) { return wires_
.count(id
) ? wires_
.at(id
) : nullptr; }
1035 RTLIL::Cell
* cell(RTLIL::IdString id
) { return cells_
.count(id
) ? cells_
.at(id
) : nullptr; }
1037 RTLIL::ObjRange
<RTLIL::Wire
*> wires() { return RTLIL::ObjRange
<RTLIL::Wire
*>(&wires_
, &refcount_wires_
); }
1038 RTLIL::ObjRange
<RTLIL::Cell
*> cells() { return RTLIL::ObjRange
<RTLIL::Cell
*>(&cells_
, &refcount_cells_
); }
1040 // Removing wires is expensive. If you have to remove wires, remove them all at once.
1041 void remove(const pool
<RTLIL::Wire
*> &wires
);
1042 void remove(RTLIL::Cell
*cell
);
1044 void rename(RTLIL::Wire
*wire
, RTLIL::IdString new_name
);
1045 void rename(RTLIL::Cell
*cell
, RTLIL::IdString new_name
);
1046 void rename(RTLIL::IdString old_name
, RTLIL::IdString new_name
);
1048 void swap_names(RTLIL::Wire
*w1
, RTLIL::Wire
*w2
);
1049 void swap_names(RTLIL::Cell
*c1
, RTLIL::Cell
*c2
);
1051 RTLIL::IdString
uniquify(RTLIL::IdString name
);
1052 RTLIL::IdString
uniquify(RTLIL::IdString name
, int &index
);
1054 RTLIL::Wire
*addWire(RTLIL::IdString name
, int width
= 1);
1055 RTLIL::Wire
*addWire(RTLIL::IdString name
, const RTLIL::Wire
*other
);
1057 RTLIL::Cell
*addCell(RTLIL::IdString name
, RTLIL::IdString type
);
1058 RTLIL::Cell
*addCell(RTLIL::IdString name
, const RTLIL::Cell
*other
);
1060 // The add* methods create a cell and return the created cell. All signals must exist in advance.
1062 RTLIL::Cell
* addNot (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1063 RTLIL::Cell
* addPos (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1064 RTLIL::Cell
* addNeg (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1066 RTLIL::Cell
* addAnd (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1067 RTLIL::Cell
* addOr (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1068 RTLIL::Cell
* addXor (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1069 RTLIL::Cell
* addXnor (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1071 RTLIL::Cell
* addReduceAnd (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1072 RTLIL::Cell
* addReduceOr (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1073 RTLIL::Cell
* addReduceXor (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1074 RTLIL::Cell
* addReduceXnor (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1075 RTLIL::Cell
* addReduceBool (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1077 RTLIL::Cell
* addShl (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1078 RTLIL::Cell
* addShr (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1079 RTLIL::Cell
* addSshl (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1080 RTLIL::Cell
* addSshr (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1081 RTLIL::Cell
* addShift (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1082 RTLIL::Cell
* addShiftx (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1084 RTLIL::Cell
* addLt (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1085 RTLIL::Cell
* addLe (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1086 RTLIL::Cell
* addEq (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1087 RTLIL::Cell
* addNe (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1088 RTLIL::Cell
* addEqx (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1089 RTLIL::Cell
* addNex (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1090 RTLIL::Cell
* addGe (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1091 RTLIL::Cell
* addGt (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1093 RTLIL::Cell
* addAdd (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1094 RTLIL::Cell
* addSub (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1095 RTLIL::Cell
* addMul (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1096 RTLIL::Cell
* addDiv (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1097 RTLIL::Cell
* addMod (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1098 RTLIL::Cell
* addPow (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool a_signed
= false, bool b_signed
= false, const std::string
&src
= "");
1100 RTLIL::Cell
* addLogicNot (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1101 RTLIL::Cell
* addLogicAnd (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1102 RTLIL::Cell
* addLogicOr (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, bool is_signed
= false, const std::string
&src
= "");
1104 RTLIL::Cell
* addMux (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_s
, RTLIL::SigSpec sig_y
, const std::string
&src
= "");
1105 RTLIL::Cell
* addPmux (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_s
, RTLIL::SigSpec sig_y
, const std::string
&src
= "");
1107 RTLIL::Cell
* addSlice (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_y
, RTLIL::Const offset
, const std::string
&src
= "");
1108 RTLIL::Cell
* addConcat (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, const std::string
&src
= "");
1109 RTLIL::Cell
* addLut (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_y
, RTLIL::Const lut
, const std::string
&src
= "");
1110 RTLIL::Cell
* addTribuf (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_en
, RTLIL::SigSpec sig_y
, const std::string
&src
= "");
1111 RTLIL::Cell
* addAssert (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_en
, const std::string
&src
= "");
1112 RTLIL::Cell
* addAssume (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_en
, const std::string
&src
= "");
1113 RTLIL::Cell
* addLive (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_en
, const std::string
&src
= "");
1114 RTLIL::Cell
* addFair (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_en
, const std::string
&src
= "");
1115 RTLIL::Cell
* addCover (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_en
, const std::string
&src
= "");
1116 RTLIL::Cell
* addEquiv (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_y
, const std::string
&src
= "");
1118 RTLIL::Cell
* addSr (RTLIL::IdString name
, RTLIL::SigSpec sig_set
, RTLIL::SigSpec sig_clr
, RTLIL::SigSpec sig_q
, bool set_polarity
= true, bool clr_polarity
= true, const std::string
&src
= "");
1119 RTLIL::Cell
* addFf (RTLIL::IdString name
, RTLIL::SigSpec sig_d
, RTLIL::SigSpec sig_q
, const std::string
&src
= "");
1120 RTLIL::Cell
* addDff (RTLIL::IdString name
, RTLIL::SigSpec sig_clk
, RTLIL::SigSpec sig_d
, RTLIL::SigSpec sig_q
, bool clk_polarity
= true, const std::string
&src
= "");
1121 RTLIL::Cell
* addDffe (RTLIL::IdString name
, RTLIL::SigSpec sig_clk
, RTLIL::SigSpec sig_en
, RTLIL::SigSpec sig_d
, RTLIL::SigSpec sig_q
, bool clk_polarity
= true, bool en_polarity
= true, const std::string
&src
= "");
1122 RTLIL::Cell
* addDffsr (RTLIL::IdString name
, RTLIL::SigSpec sig_clk
, RTLIL::SigSpec sig_set
, RTLIL::SigSpec sig_clr
,
1123 RTLIL::SigSpec sig_d
, RTLIL::SigSpec sig_q
, bool clk_polarity
= true, bool set_polarity
= true, bool clr_polarity
= true, const std::string
&src
= "");
1124 RTLIL::Cell
* addAdff (RTLIL::IdString name
, RTLIL::SigSpec sig_clk
, RTLIL::SigSpec sig_arst
, RTLIL::SigSpec sig_d
, RTLIL::SigSpec sig_q
,
1125 RTLIL::Const arst_value
, bool clk_polarity
= true, bool arst_polarity
= true, const std::string
&src
= "");
1126 RTLIL::Cell
* addDlatch (RTLIL::IdString name
, RTLIL::SigSpec sig_en
, RTLIL::SigSpec sig_d
, RTLIL::SigSpec sig_q
, bool en_polarity
= true, const std::string
&src
= "");
1127 RTLIL::Cell
* addDlatchsr (RTLIL::IdString name
, RTLIL::SigSpec sig_en
, RTLIL::SigSpec sig_set
, RTLIL::SigSpec sig_clr
,
1128 RTLIL::SigSpec sig_d
, RTLIL::SigSpec sig_q
, bool en_polarity
= true, bool set_polarity
= true, bool clr_polarity
= true, const std::string
&src
= "");
1130 RTLIL::Cell
* addBufGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_y
, const std::string
&src
= "");
1131 RTLIL::Cell
* addNotGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_y
, const std::string
&src
= "");
1132 RTLIL::Cell
* addAndGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, RTLIL::SigBit sig_y
, const std::string
&src
= "");
1133 RTLIL::Cell
* addNandGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, RTLIL::SigBit sig_y
, const std::string
&src
= "");
1134 RTLIL::Cell
* addOrGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, RTLIL::SigBit sig_y
, const std::string
&src
= "");
1135 RTLIL::Cell
* addNorGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, RTLIL::SigBit sig_y
, const std::string
&src
= "");
1136 RTLIL::Cell
* addXorGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, RTLIL::SigBit sig_y
, const std::string
&src
= "");
1137 RTLIL::Cell
* addXnorGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, RTLIL::SigBit sig_y
, const std::string
&src
= "");
1138 RTLIL::Cell
* addAndnotGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, RTLIL::SigBit sig_y
, const std::string
&src
= "");
1139 RTLIL::Cell
* addOrnotGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, RTLIL::SigBit sig_y
, const std::string
&src
= "");
1140 RTLIL::Cell
* addMuxGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, RTLIL::SigBit sig_s
, RTLIL::SigBit sig_y
, const std::string
&src
= "");
1141 RTLIL::Cell
* addAoi3Gate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, RTLIL::SigBit sig_c
, RTLIL::SigBit sig_y
, const std::string
&src
= "");
1142 RTLIL::Cell
* addOai3Gate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, RTLIL::SigBit sig_c
, RTLIL::SigBit sig_y
, const std::string
&src
= "");
1143 RTLIL::Cell
* addAoi4Gate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, RTLIL::SigBit sig_c
, RTLIL::SigBit sig_d
, RTLIL::SigBit sig_y
, const std::string
&src
= "");
1144 RTLIL::Cell
* addOai4Gate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, RTLIL::SigBit sig_c
, RTLIL::SigBit sig_d
, RTLIL::SigBit sig_y
, const std::string
&src
= "");
1146 RTLIL::Cell
* addFfGate (RTLIL::IdString name
, RTLIL::SigSpec sig_d
, RTLIL::SigSpec sig_q
, const std::string
&src
= "");
1147 RTLIL::Cell
* addDffGate (RTLIL::IdString name
, RTLIL::SigSpec sig_clk
, RTLIL::SigSpec sig_d
, RTLIL::SigSpec sig_q
, bool clk_polarity
= true, const std::string
&src
= "");
1148 RTLIL::Cell
* addDffeGate (RTLIL::IdString name
, RTLIL::SigSpec sig_clk
, RTLIL::SigSpec sig_en
, RTLIL::SigSpec sig_d
, RTLIL::SigSpec sig_q
, bool clk_polarity
= true, bool en_polarity
= true, const std::string
&src
= "");
1149 RTLIL::Cell
* addDffsrGate (RTLIL::IdString name
, RTLIL::SigSpec sig_clk
, RTLIL::SigSpec sig_set
, RTLIL::SigSpec sig_clr
,
1150 RTLIL::SigSpec sig_d
, RTLIL::SigSpec sig_q
, bool clk_polarity
= true, bool set_polarity
= true, bool clr_polarity
= true, const std::string
&src
= "");
1151 RTLIL::Cell
* addAdffGate (RTLIL::IdString name
, RTLIL::SigSpec sig_clk
, RTLIL::SigSpec sig_arst
, RTLIL::SigSpec sig_d
, RTLIL::SigSpec sig_q
,
1152 bool arst_value
= false, bool clk_polarity
= true, bool arst_polarity
= true, const std::string
&src
= "");
1153 RTLIL::Cell
* addDlatchGate (RTLIL::IdString name
, RTLIL::SigSpec sig_en
, RTLIL::SigSpec sig_d
, RTLIL::SigSpec sig_q
, bool en_polarity
= true, const std::string
&src
= "");
1154 RTLIL::Cell
* addDlatchsrGate (RTLIL::IdString name
, RTLIL::SigSpec sig_en
, RTLIL::SigSpec sig_set
, RTLIL::SigSpec sig_clr
,
1155 RTLIL::SigSpec sig_d
, RTLIL::SigSpec sig_q
, bool en_polarity
= true, bool set_polarity
= true, bool clr_polarity
= true, const std::string
&src
= "");
1157 // The methods without the add* prefix create a cell and an output signal. They return the newly created output signal.
1159 RTLIL::SigSpec
Not (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, bool is_signed
= false, const std::string
&src
= "");
1160 RTLIL::SigSpec
Pos (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, bool is_signed
= false, const std::string
&src
= "");
1161 RTLIL::SigSpec
Bu0 (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, bool is_signed
= false, const std::string
&src
= "");
1162 RTLIL::SigSpec
Neg (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, bool is_signed
= false, const std::string
&src
= "");
1164 RTLIL::SigSpec
And (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1165 RTLIL::SigSpec
Or (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1166 RTLIL::SigSpec
Xor (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1167 RTLIL::SigSpec
Xnor (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1169 RTLIL::SigSpec
ReduceAnd (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, bool is_signed
= false, const std::string
&src
= "");
1170 RTLIL::SigSpec
ReduceOr (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, bool is_signed
= false, const std::string
&src
= "");
1171 RTLIL::SigSpec
ReduceXor (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, bool is_signed
= false, const std::string
&src
= "");
1172 RTLIL::SigSpec
ReduceXnor (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, bool is_signed
= false, const std::string
&src
= "");
1173 RTLIL::SigSpec
ReduceBool (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, bool is_signed
= false, const std::string
&src
= "");
1175 RTLIL::SigSpec
Shl (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1176 RTLIL::SigSpec
Shr (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1177 RTLIL::SigSpec
Sshl (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1178 RTLIL::SigSpec
Sshr (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1179 RTLIL::SigSpec
Shift (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1180 RTLIL::SigSpec
Shiftx (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1182 RTLIL::SigSpec
Lt (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1183 RTLIL::SigSpec
Le (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1184 RTLIL::SigSpec
Eq (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1185 RTLIL::SigSpec
Ne (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1186 RTLIL::SigSpec
Eqx (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1187 RTLIL::SigSpec
Nex (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1188 RTLIL::SigSpec
Ge (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1189 RTLIL::SigSpec
Gt (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1191 RTLIL::SigSpec
Add (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1192 RTLIL::SigSpec
Sub (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1193 RTLIL::SigSpec
Mul (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1194 RTLIL::SigSpec
Div (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1195 RTLIL::SigSpec
Mod (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1196 RTLIL::SigSpec
Pow (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool a_signed
= false, bool b_signed
= false, const std::string
&src
= "");
1198 RTLIL::SigSpec
LogicNot (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, bool is_signed
= false, const std::string
&src
= "");
1199 RTLIL::SigSpec
LogicAnd (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1200 RTLIL::SigSpec
LogicOr (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, bool is_signed
= false, const std::string
&src
= "");
1202 RTLIL::SigSpec
Mux (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_s
, const std::string
&src
= "");
1203 RTLIL::SigSpec
Pmux (RTLIL::IdString name
, RTLIL::SigSpec sig_a
, RTLIL::SigSpec sig_b
, RTLIL::SigSpec sig_s
, const std::string
&src
= "");
1205 RTLIL::SigBit
BufGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, const std::string
&src
= "");
1206 RTLIL::SigBit
NotGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, const std::string
&src
= "");
1207 RTLIL::SigBit
AndGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, const std::string
&src
= "");
1208 RTLIL::SigBit
NandGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, const std::string
&src
= "");
1209 RTLIL::SigBit
OrGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, const std::string
&src
= "");
1210 RTLIL::SigBit
NorGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, const std::string
&src
= "");
1211 RTLIL::SigBit
XorGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, const std::string
&src
= "");
1212 RTLIL::SigBit
XnorGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, const std::string
&src
= "");
1213 RTLIL::SigBit
AndnotGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, const std::string
&src
= "");
1214 RTLIL::SigBit
OrnotGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, const std::string
&src
= "");
1215 RTLIL::SigBit
MuxGate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, RTLIL::SigBit sig_s
, const std::string
&src
= "");
1216 RTLIL::SigBit
Aoi3Gate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, RTLIL::SigBit sig_c
, const std::string
&src
= "");
1217 RTLIL::SigBit
Oai3Gate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, RTLIL::SigBit sig_c
, const std::string
&src
= "");
1218 RTLIL::SigBit
Aoi4Gate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, RTLIL::SigBit sig_c
, RTLIL::SigBit sig_d
, const std::string
&src
= "");
1219 RTLIL::SigBit
Oai4Gate (RTLIL::IdString name
, RTLIL::SigBit sig_a
, RTLIL::SigBit sig_b
, RTLIL::SigBit sig_c
, RTLIL::SigBit sig_d
, const std::string
&src
= "");
1221 RTLIL::SigSpec
Anyconst (RTLIL::IdString name
, int width
= 1, const std::string
&src
= "");
1222 RTLIL::SigSpec
Anyseq (RTLIL::IdString name
, int width
= 1, const std::string
&src
= "");
1223 RTLIL::SigSpec
Allconst (RTLIL::IdString name
, int width
= 1, const std::string
&src
= "");
1224 RTLIL::SigSpec
Allseq (RTLIL::IdString name
, int width
= 1, const std::string
&src
= "");
1225 RTLIL::SigSpec
Initstate (RTLIL::IdString name
, const std::string
&src
= "");
1228 static std::map
<unsigned int, RTLIL::Module
*> *get_all_modules(void);
1232 struct RTLIL::Wire
: public RTLIL::AttrObject
1234 unsigned int hashidx_
;
1235 unsigned int hash() const { return hashidx_
; }
1238 // use module->addWire() and module->remove() to create or destroy wires
1239 friend struct RTLIL::Module
;
1244 // do not simply copy wires
1245 Wire(RTLIL::Wire
&other
) = delete;
1246 void operator=(RTLIL::Wire
&other
) = delete;
1248 RTLIL::Module
*module
;
1249 RTLIL::IdString name
;
1250 int width
, start_offset
, port_id
;
1251 bool port_input
, port_output
, upto
;
1254 static std::map
<unsigned int, RTLIL::Wire
*> *get_all_wires(void);
1258 struct RTLIL::Memory
: public RTLIL::AttrObject
1260 unsigned int hashidx_
;
1261 unsigned int hash() const { return hashidx_
; }
1265 RTLIL::IdString name
;
1266 int width
, start_offset
, size
;
1269 static std::map
<unsigned int, RTLIL::Memory
*> *get_all_memorys(void);
1273 struct RTLIL::Cell
: public RTLIL::AttrObject
1275 unsigned int hashidx_
;
1276 unsigned int hash() const { return hashidx_
; }
1279 // use module->addCell() and module->remove() to create or destroy cells
1280 friend struct RTLIL::Module
;
1285 // do not simply copy cells
1286 Cell(RTLIL::Cell
&other
) = delete;
1287 void operator=(RTLIL::Cell
&other
) = delete;
1289 RTLIL::Module
*module
;
1290 RTLIL::IdString name
;
1291 RTLIL::IdString type
;
1292 dict
<RTLIL::IdString
, RTLIL::SigSpec
> connections_
;
1293 dict
<RTLIL::IdString
, RTLIL::Const
> parameters
;
1295 // access cell ports
1296 bool hasPort(RTLIL::IdString portname
) const;
1297 void unsetPort(RTLIL::IdString portname
);
1298 void setPort(RTLIL::IdString portname
, RTLIL::SigSpec signal
);
1299 const RTLIL::SigSpec
&getPort(RTLIL::IdString portname
) const;
1300 const dict
<RTLIL::IdString
, RTLIL::SigSpec
> &connections() const;
1302 // information about cell ports
1304 bool input(RTLIL::IdString portname
) const;
1305 bool output(RTLIL::IdString portname
) const;
1307 // access cell parameters
1308 bool hasParam(RTLIL::IdString paramname
) const;
1309 void unsetParam(RTLIL::IdString paramname
);
1310 void setParam(RTLIL::IdString paramname
, RTLIL::Const value
);
1311 const RTLIL::Const
&getParam(RTLIL::IdString paramname
) const;
1315 void fixup_parameters(bool set_a_signed
= false, bool set_b_signed
= false);
1317 bool has_keep_attr() const {
1318 return get_bool_attribute("\\keep") || (module
&& module
->design
&& module
->design
->module(type
) &&
1319 module
->design
->module(type
)->get_bool_attribute("\\keep"));
1322 template<typename T
> void rewrite_sigspecs(T
&functor
);
1323 template<typename T
> void rewrite_sigspecs2(T
&functor
);
1326 static std::map
<unsigned int, RTLIL::Cell
*> *get_all_cells(void);
1330 struct RTLIL::CaseRule
1332 std::vector
<RTLIL::SigSpec
> compare
;
1333 std::vector
<RTLIL::SigSig
> actions
;
1334 std::vector
<RTLIL::SwitchRule
*> switches
;
1341 template<typename T
> void rewrite_sigspecs(T
&functor
);
1342 template<typename T
> void rewrite_sigspecs2(T
&functor
);
1343 RTLIL::CaseRule
*clone() const;
1346 struct RTLIL::SwitchRule
: public RTLIL::AttrObject
1348 RTLIL::SigSpec signal
;
1349 std::vector
<RTLIL::CaseRule
*> cases
;
1355 template<typename T
> void rewrite_sigspecs(T
&functor
);
1356 template<typename T
> void rewrite_sigspecs2(T
&functor
);
1357 RTLIL::SwitchRule
*clone() const;
1360 struct RTLIL::SyncRule
1362 RTLIL::SyncType type
;
1363 RTLIL::SigSpec signal
;
1364 std::vector
<RTLIL::SigSig
> actions
;
1366 template<typename T
> void rewrite_sigspecs(T
&functor
);
1367 template<typename T
> void rewrite_sigspecs2(T
&functor
);
1368 RTLIL::SyncRule
*clone() const;
1371 struct RTLIL::Process
: public RTLIL::AttrObject
1373 RTLIL::IdString name
;
1374 RTLIL::CaseRule root_case
;
1375 std::vector
<RTLIL::SyncRule
*> syncs
;
1379 template<typename T
> void rewrite_sigspecs(T
&functor
);
1380 template<typename T
> void rewrite_sigspecs2(T
&functor
);
1381 RTLIL::Process
*clone() const;
1385 inline RTLIL::SigBit::SigBit() : wire(NULL
), data(RTLIL::State::S0
) { }
1386 inline RTLIL::SigBit::SigBit(RTLIL::State bit
) : wire(NULL
), data(bit
) { }
1387 inline RTLIL::SigBit::SigBit(bool bit
) : wire(NULL
), data(bit
? RTLIL::S1
: RTLIL::S0
) { }
1388 inline RTLIL::SigBit::SigBit(RTLIL::Wire
*wire
) : wire(wire
), offset(0) { log_assert(wire
&& wire
->width
== 1); }
1389 inline RTLIL::SigBit::SigBit(RTLIL::Wire
*wire
, int offset
) : wire(wire
), offset(offset
) { log_assert(wire
!= nullptr); }
1390 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]; }
1391 inline RTLIL::SigBit::SigBit(const RTLIL::SigChunk
&chunk
, int index
) : wire(chunk
.wire
) { if (wire
) offset
= chunk
.offset
+ index
; else data
= chunk
.data
[index
]; }
1392 inline RTLIL::SigBit::SigBit(const RTLIL::SigBit
&sigbit
) : wire(sigbit
.wire
), data(sigbit
.data
){if(wire
) offset
= sigbit
.offset
;}
1394 inline bool RTLIL::SigBit::operator<(const RTLIL::SigBit
&other
) const {
1395 if (wire
== other
.wire
)
1396 return wire
? (offset
< other
.offset
) : (data
< other
.data
);
1397 if (wire
!= nullptr && other
.wire
!= nullptr)
1398 return wire
->name
< other
.wire
->name
;
1399 return (wire
!= nullptr) < (other
.wire
!= nullptr);
1402 inline bool RTLIL::SigBit::operator==(const RTLIL::SigBit
&other
) const {
1403 return (wire
== other
.wire
) && (wire
? (offset
== other
.offset
) : (data
== other
.data
));
1406 inline bool RTLIL::SigBit::operator!=(const RTLIL::SigBit
&other
) const {
1407 return (wire
!= other
.wire
) || (wire
? (offset
!= other
.offset
) : (data
!= other
.data
));
1410 inline unsigned int RTLIL::SigBit::hash() const {
1412 return mkhash_add(wire
->name
.hash(), offset
);
1416 inline RTLIL::SigBit
&RTLIL::SigSpecIterator::operator*() const {
1417 return (*sig_p
)[index
];
1420 inline const RTLIL::SigBit
&RTLIL::SigSpecConstIterator::operator*() const {
1421 return (*sig_p
)[index
];
1424 inline RTLIL::SigBit::SigBit(const RTLIL::SigSpec
&sig
) {
1425 log_assert(sig
.size() == 1 && sig
.chunks().size() == 1);
1426 *this = SigBit(sig
.chunks().front());
1429 template<typename T
>
1430 void RTLIL::Module::rewrite_sigspecs(T
&functor
)
1432 for (auto &it
: cells_
)
1433 it
.second
->rewrite_sigspecs(functor
);
1434 for (auto &it
: processes
)
1435 it
.second
->rewrite_sigspecs(functor
);
1436 for (auto &it
: connections_
) {
1442 template<typename T
>
1443 void RTLIL::Module::rewrite_sigspecs2(T
&functor
)
1445 for (auto &it
: cells_
)
1446 it
.second
->rewrite_sigspecs2(functor
);
1447 for (auto &it
: processes
)
1448 it
.second
->rewrite_sigspecs2(functor
);
1449 for (auto &it
: connections_
) {
1450 functor(it
.first
, it
.second
);
1454 template<typename T
>
1455 void RTLIL::Cell::rewrite_sigspecs(T
&functor
) {
1456 for (auto &it
: connections_
)
1460 template<typename T
>
1461 void RTLIL::Cell::rewrite_sigspecs2(T
&functor
) {
1462 for (auto &it
: connections_
)
1466 template<typename T
>
1467 void RTLIL::CaseRule::rewrite_sigspecs(T
&functor
) {
1468 for (auto &it
: compare
)
1470 for (auto &it
: actions
) {
1474 for (auto it
: switches
)
1475 it
->rewrite_sigspecs(functor
);
1478 template<typename T
>
1479 void RTLIL::CaseRule::rewrite_sigspecs2(T
&functor
) {
1480 for (auto &it
: compare
)
1482 for (auto &it
: actions
) {
1483 functor(it
.first
, it
.second
);
1485 for (auto it
: switches
)
1486 it
->rewrite_sigspecs2(functor
);
1489 template<typename T
>
1490 void RTLIL::SwitchRule::rewrite_sigspecs(T
&functor
)
1493 for (auto it
: cases
)
1494 it
->rewrite_sigspecs(functor
);
1497 template<typename T
>
1498 void RTLIL::SwitchRule::rewrite_sigspecs2(T
&functor
)
1501 for (auto it
: cases
)
1502 it
->rewrite_sigspecs2(functor
);
1505 template<typename T
>
1506 void RTLIL::SyncRule::rewrite_sigspecs(T
&functor
)
1509 for (auto &it
: actions
) {
1515 template<typename T
>
1516 void RTLIL::SyncRule::rewrite_sigspecs2(T
&functor
)
1519 for (auto &it
: actions
) {
1520 functor(it
.first
, it
.second
);
1524 template<typename T
>
1525 void RTLIL::Process::rewrite_sigspecs(T
&functor
)
1527 root_case
.rewrite_sigspecs(functor
);
1528 for (auto it
: syncs
)
1529 it
->rewrite_sigspecs(functor
);
1532 template<typename T
>
1533 void RTLIL::Process::rewrite_sigspecs2(T
&functor
)
1535 root_case
.rewrite_sigspecs2(functor
);
1536 for (auto it
: syncs
)
1537 it
->rewrite_sigspecs2(functor
);