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"
21 #include "kernel/macc.h"
22 #include "kernel/celltypes.h"
23 #include "frontends/verilog/verilog_frontend.h"
24 #include "frontends/verilog/preproc.h"
25 #include "backends/ilang/ilang_backend.h"
32 RTLIL::IdString::destruct_guard_t
RTLIL::IdString::destruct_guard
;
33 std::vector
<char*> RTLIL::IdString::global_id_storage_
;
34 dict
<char*, int, hash_cstr_ops
> RTLIL::IdString::global_id_index_
;
35 #ifndef YOSYS_NO_IDS_REFCNT
36 std::vector
<int> RTLIL::IdString::global_refcount_storage_
;
37 std::vector
<int> RTLIL::IdString::global_free_idx_list_
;
39 #ifdef YOSYS_USE_STICKY_IDS
40 int RTLIL::IdString::last_created_idx_
[8];
41 int RTLIL::IdString::last_created_idx_ptr_
;
44 IdString
RTLIL::ID::A
;
45 IdString
RTLIL::ID::B
;
46 IdString
RTLIL::ID::Y
;
47 IdString
RTLIL::ID::keep
;
48 IdString
RTLIL::ID::whitebox
;
49 IdString
RTLIL::ID::blackbox
;
50 dict
<std::string
, std::string
> RTLIL::constpad
;
54 flags
= RTLIL::CONST_FLAG_NONE
;
57 RTLIL::Const::Const(std::string str
)
59 flags
= RTLIL::CONST_FLAG_STRING
;
60 for (int i
= str
.size()-1; i
>= 0; i
--) {
61 unsigned char ch
= str
[i
];
62 for (int j
= 0; j
< 8; j
++) {
63 bits
.push_back((ch
& 1) != 0 ? State::S1
: State::S0
);
69 RTLIL::Const::Const(int val
, int width
)
71 flags
= RTLIL::CONST_FLAG_NONE
;
72 for (int i
= 0; i
< width
; i
++) {
73 bits
.push_back((val
& 1) != 0 ? State::S1
: State::S0
);
78 RTLIL::Const::Const(RTLIL::State bit
, int width
)
80 flags
= RTLIL::CONST_FLAG_NONE
;
81 for (int i
= 0; i
< width
; i
++)
85 RTLIL::Const::Const(const std::vector
<bool> &bits
)
87 flags
= RTLIL::CONST_FLAG_NONE
;
88 for (const auto &b
: bits
)
89 this->bits
.emplace_back(b
? State::S1
: State::S0
);
92 RTLIL::Const::Const(const RTLIL::Const
&c
)
95 for (const auto &b
: c
.bits
)
96 this->bits
.push_back(b
);
99 bool RTLIL::Const::operator <(const RTLIL::Const
&other
) const
101 if (bits
.size() != other
.bits
.size())
102 return bits
.size() < other
.bits
.size();
103 for (size_t i
= 0; i
< bits
.size(); i
++)
104 if (bits
[i
] != other
.bits
[i
])
105 return bits
[i
] < other
.bits
[i
];
109 bool RTLIL::Const::operator ==(const RTLIL::Const
&other
) const
111 return bits
== other
.bits
;
114 bool RTLIL::Const::operator !=(const RTLIL::Const
&other
) const
116 return bits
!= other
.bits
;
119 bool RTLIL::Const::as_bool() const
121 for (size_t i
= 0; i
< bits
.size(); i
++)
122 if (bits
[i
] == State::S1
)
127 int RTLIL::Const::as_int(bool is_signed
) const
130 for (size_t i
= 0; i
< bits
.size() && i
< 32; i
++)
131 if (bits
[i
] == State::S1
)
133 if (is_signed
&& bits
.back() == State::S1
)
134 for (size_t i
= bits
.size(); i
< 32; i
++)
139 std::string
RTLIL::Const::as_string() const
142 ret
.reserve(bits
.size());
143 for (size_t i
= bits
.size(); i
> 0; i
--)
145 case S0
: ret
+= "0"; break;
146 case S1
: ret
+= "1"; break;
147 case Sx
: ret
+= "x"; break;
148 case Sz
: ret
+= "z"; break;
149 case Sa
: ret
+= "-"; break;
150 case Sm
: ret
+= "m"; break;
155 RTLIL::Const
RTLIL::Const::from_string(const std::string
&str
)
158 c
.bits
.reserve(str
.size());
159 for (auto it
= str
.rbegin(); it
!= str
.rend(); it
++)
161 case '0': c
.bits
.push_back(State::S0
); break;
162 case '1': c
.bits
.push_back(State::S1
); break;
163 case 'x': c
.bits
.push_back(State::Sx
); break;
164 case 'z': c
.bits
.push_back(State::Sz
); break;
165 case 'm': c
.bits
.push_back(State::Sm
); break;
166 default: c
.bits
.push_back(State::Sa
);
171 std::string
RTLIL::Const::decode_string() const
174 string
.reserve(GetSize(bits
)/8);
175 for (int i
= 0; i
< GetSize(bits
); i
+= 8) {
177 for (int j
= 0; j
< 8 && i
+ j
< int (bits
.size()); j
++)
178 if (bits
[i
+ j
] == RTLIL::State::S1
)
183 std::reverse(string
.begin(), string
.end());
187 bool RTLIL::Const::is_fully_zero() const
189 cover("kernel.rtlil.const.is_fully_zero");
191 for (const auto &bit
: bits
)
192 if (bit
!= RTLIL::State::S0
)
198 bool RTLIL::Const::is_fully_ones() const
200 cover("kernel.rtlil.const.is_fully_ones");
202 for (const auto &bit
: bits
)
203 if (bit
!= RTLIL::State::S1
)
209 bool RTLIL::Const::is_fully_def() const
211 cover("kernel.rtlil.const.is_fully_def");
213 for (const auto &bit
: bits
)
214 if (bit
!= RTLIL::State::S0
&& bit
!= RTLIL::State::S1
)
220 bool RTLIL::Const::is_fully_undef() const
222 cover("kernel.rtlil.const.is_fully_undef");
224 for (const auto &bit
: bits
)
225 if (bit
!= RTLIL::State::Sx
&& bit
!= RTLIL::State::Sz
)
231 void RTLIL::AttrObject::set_bool_attribute(RTLIL::IdString id
, bool value
)
234 attributes
[id
] = RTLIL::Const(1);
236 attributes
.erase(id
);
239 bool RTLIL::AttrObject::get_bool_attribute(RTLIL::IdString id
) const
241 const auto it
= attributes
.find(id
);
242 if (it
== attributes
.end())
244 return it
->second
.as_bool();
247 void RTLIL::AttrObject::set_strpool_attribute(RTLIL::IdString id
, const pool
<string
> &data
)
250 for (const auto &s
: data
) {
251 if (!attrval
.empty())
255 attributes
[id
] = RTLIL::Const(attrval
);
258 void RTLIL::AttrObject::add_strpool_attribute(RTLIL::IdString id
, const pool
<string
> &data
)
260 pool
<string
> union_data
= get_strpool_attribute(id
);
261 union_data
.insert(data
.begin(), data
.end());
262 if (!union_data
.empty())
263 set_strpool_attribute(id
, union_data
);
266 pool
<string
> RTLIL::AttrObject::get_strpool_attribute(RTLIL::IdString id
) const
269 if (attributes
.count(id
) != 0)
270 for (auto s
: split_tokens(attributes
.at(id
).decode_string(), "|"))
275 void RTLIL::AttrObject::set_src_attribute(const std::string
&src
)
278 attributes
.erase(ID(src
));
280 attributes
[ID(src
)] = src
;
283 std::string
RTLIL::AttrObject::get_src_attribute() const
286 const auto it
= attributes
.find(ID(src
));
287 if (it
!= attributes
.end())
288 src
= it
->second
.decode_string();
292 bool RTLIL::Selection::selected_module(RTLIL::IdString mod_name
) const
296 if (selected_modules
.count(mod_name
) > 0)
298 if (selected_members
.count(mod_name
) > 0)
303 bool RTLIL::Selection::selected_whole_module(RTLIL::IdString mod_name
) const
307 if (selected_modules
.count(mod_name
) > 0)
312 bool RTLIL::Selection::selected_member(RTLIL::IdString mod_name
, RTLIL::IdString memb_name
) const
316 if (selected_modules
.count(mod_name
) > 0)
318 if (selected_members
.count(mod_name
) > 0)
319 if (selected_members
.at(mod_name
).count(memb_name
) > 0)
324 void RTLIL::Selection::optimize(RTLIL::Design
*design
)
326 if (full_selection
) {
327 selected_modules
.clear();
328 selected_members
.clear();
332 std::vector
<RTLIL::IdString
> del_list
, add_list
;
335 for (auto mod_name
: selected_modules
) {
336 if (design
->modules_
.count(mod_name
) == 0)
337 del_list
.push_back(mod_name
);
338 selected_members
.erase(mod_name
);
340 for (auto mod_name
: del_list
)
341 selected_modules
.erase(mod_name
);
344 for (auto &it
: selected_members
)
345 if (design
->modules_
.count(it
.first
) == 0)
346 del_list
.push_back(it
.first
);
347 for (auto mod_name
: del_list
)
348 selected_members
.erase(mod_name
);
350 for (auto &it
: selected_members
) {
352 for (auto memb_name
: it
.second
)
353 if (design
->modules_
[it
.first
]->count_id(memb_name
) == 0)
354 del_list
.push_back(memb_name
);
355 for (auto memb_name
: del_list
)
356 it
.second
.erase(memb_name
);
361 for (auto &it
: selected_members
)
362 if (it
.second
.size() == 0)
363 del_list
.push_back(it
.first
);
364 else if (it
.second
.size() == design
->modules_
[it
.first
]->wires_
.size() + design
->modules_
[it
.first
]->memories
.size() +
365 design
->modules_
[it
.first
]->cells_
.size() + design
->modules_
[it
.first
]->processes
.size())
366 add_list
.push_back(it
.first
);
367 for (auto mod_name
: del_list
)
368 selected_members
.erase(mod_name
);
369 for (auto mod_name
: add_list
) {
370 selected_members
.erase(mod_name
);
371 selected_modules
.insert(mod_name
);
374 if (selected_modules
.size() == design
->modules_
.size()) {
375 full_selection
= true;
376 selected_modules
.clear();
377 selected_members
.clear();
381 RTLIL::Design::Design()
382 : verilog_defines (new define_map_t
)
384 static unsigned int hashidx_count
= 123456789;
385 hashidx_count
= mkhash_xorshift(hashidx_count
);
386 hashidx_
= hashidx_count
;
388 refcount_modules_
= 0;
389 selection_stack
.push_back(RTLIL::Selection());
392 RTLIL::Design::get_all_designs()->insert(std::pair
<unsigned int, RTLIL::Design
*>(hashidx_
, this));
396 RTLIL::Design::~Design()
398 for (auto it
= modules_
.begin(); it
!= modules_
.end(); ++it
)
400 for (auto n
: verilog_packages
)
402 for (auto n
: verilog_globals
)
405 RTLIL::Design::get_all_designs()->erase(hashidx_
);
410 static std::map
<unsigned int, RTLIL::Design
*> all_designs
;
411 std::map
<unsigned int, RTLIL::Design
*> *RTLIL::Design::get_all_designs(void)
417 RTLIL::ObjRange
<RTLIL::Module
*> RTLIL::Design::modules()
419 return RTLIL::ObjRange
<RTLIL::Module
*>(&modules_
, &refcount_modules_
);
422 RTLIL::Module
*RTLIL::Design::module(RTLIL::IdString name
)
424 return modules_
.count(name
) ? modules_
.at(name
) : NULL
;
427 RTLIL::Module
*RTLIL::Design::top_module()
429 RTLIL::Module
*module
= nullptr;
430 int module_count
= 0;
432 for (auto mod
: selected_modules()) {
433 if (mod
->get_bool_attribute(ID(top
)))
439 return module_count
== 1 ? module
: nullptr;
442 void RTLIL::Design::add(RTLIL::Module
*module
)
444 log_assert(modules_
.count(module
->name
) == 0);
445 log_assert(refcount_modules_
== 0);
446 modules_
[module
->name
] = module
;
447 module
->design
= this;
449 for (auto mon
: monitors
)
450 mon
->notify_module_add(module
);
453 log("#X# New Module: %s\n", log_id(module
));
454 log_backtrace("-X- ", yosys_xtrace
-1);
458 RTLIL::Module
*RTLIL::Design::addModule(RTLIL::IdString name
)
460 log_assert(modules_
.count(name
) == 0);
461 log_assert(refcount_modules_
== 0);
463 RTLIL::Module
*module
= new RTLIL::Module
;
464 modules_
[name
] = module
;
465 module
->design
= this;
468 for (auto mon
: monitors
)
469 mon
->notify_module_add(module
);
472 log("#X# New Module: %s\n", log_id(module
));
473 log_backtrace("-X- ", yosys_xtrace
-1);
479 void RTLIL::Design::scratchpad_unset(const std::string
&varname
)
481 scratchpad
.erase(varname
);
484 void RTLIL::Design::scratchpad_set_int(const std::string
&varname
, int value
)
486 scratchpad
[varname
] = stringf("%d", value
);
489 void RTLIL::Design::scratchpad_set_bool(const std::string
&varname
, bool value
)
491 scratchpad
[varname
] = value
? "true" : "false";
494 void RTLIL::Design::scratchpad_set_string(const std::string
&varname
, std::string value
)
496 scratchpad
[varname
] = std::move(value
);
499 int RTLIL::Design::scratchpad_get_int(const std::string
&varname
, int default_value
) const
501 auto it
= scratchpad
.find(varname
);
502 if (it
== scratchpad
.end())
503 return default_value
;
505 const std::string
&str
= it
->second
;
507 if (str
== "0" || str
== "false")
510 if (str
== "1" || str
== "true")
513 char *endptr
= nullptr;
514 long int parsed_value
= strtol(str
.c_str(), &endptr
, 10);
515 return *endptr
? default_value
: parsed_value
;
518 bool RTLIL::Design::scratchpad_get_bool(const std::string
&varname
, bool default_value
) const
520 auto it
= scratchpad
.find(varname
);
521 if (it
== scratchpad
.end())
522 return default_value
;
524 const std::string
&str
= it
->second
;
526 if (str
== "0" || str
== "false")
529 if (str
== "1" || str
== "true")
532 return default_value
;
535 std::string
RTLIL::Design::scratchpad_get_string(const std::string
&varname
, const std::string
&default_value
) const
537 auto it
= scratchpad
.find(varname
);
538 if (it
== scratchpad
.end())
539 return default_value
;
544 void RTLIL::Design::remove(RTLIL::Module
*module
)
546 for (auto mon
: monitors
)
547 mon
->notify_module_del(module
);
550 log("#X# Remove Module: %s\n", log_id(module
));
551 log_backtrace("-X- ", yosys_xtrace
-1);
554 log_assert(modules_
.at(module
->name
) == module
);
555 modules_
.erase(module
->name
);
559 void RTLIL::Design::rename(RTLIL::Module
*module
, RTLIL::IdString new_name
)
561 modules_
.erase(module
->name
);
562 module
->name
= new_name
;
566 void RTLIL::Design::sort()
569 modules_
.sort(sort_by_id_str());
570 for (auto &it
: modules_
)
574 void RTLIL::Design::check()
577 for (auto &it
: modules_
) {
578 log_assert(this == it
.second
->design
);
579 log_assert(it
.first
== it
.second
->name
);
580 log_assert(!it
.first
.empty());
586 void RTLIL::Design::optimize()
588 for (auto &it
: modules_
)
589 it
.second
->optimize();
590 for (auto &it
: selection_stack
)
592 for (auto &it
: selection_vars
)
593 it
.second
.optimize(this);
596 bool RTLIL::Design::selected_module(RTLIL::IdString mod_name
) const
598 if (!selected_active_module
.empty() && mod_name
!= selected_active_module
)
600 if (selection_stack
.size() == 0)
602 return selection_stack
.back().selected_module(mod_name
);
605 bool RTLIL::Design::selected_whole_module(RTLIL::IdString mod_name
) const
607 if (!selected_active_module
.empty() && mod_name
!= selected_active_module
)
609 if (selection_stack
.size() == 0)
611 return selection_stack
.back().selected_whole_module(mod_name
);
614 bool RTLIL::Design::selected_member(RTLIL::IdString mod_name
, RTLIL::IdString memb_name
) const
616 if (!selected_active_module
.empty() && mod_name
!= selected_active_module
)
618 if (selection_stack
.size() == 0)
620 return selection_stack
.back().selected_member(mod_name
, memb_name
);
623 bool RTLIL::Design::selected_module(RTLIL::Module
*mod
) const
625 return selected_module(mod
->name
);
628 bool RTLIL::Design::selected_whole_module(RTLIL::Module
*mod
) const
630 return selected_whole_module(mod
->name
);
633 std::vector
<RTLIL::Module
*> RTLIL::Design::selected_modules() const
635 std::vector
<RTLIL::Module
*> result
;
636 result
.reserve(modules_
.size());
637 for (auto &it
: modules_
)
638 if (selected_module(it
.first
) && !it
.second
->get_blackbox_attribute())
639 result
.push_back(it
.second
);
643 std::vector
<RTLIL::Module
*> RTLIL::Design::selected_whole_modules() const
645 std::vector
<RTLIL::Module
*> result
;
646 result
.reserve(modules_
.size());
647 for (auto &it
: modules_
)
648 if (selected_whole_module(it
.first
) && !it
.second
->get_blackbox_attribute())
649 result
.push_back(it
.second
);
653 std::vector
<RTLIL::Module
*> RTLIL::Design::selected_whole_modules_warn() const
655 std::vector
<RTLIL::Module
*> result
;
656 result
.reserve(modules_
.size());
657 for (auto &it
: modules_
)
658 if (it
.second
->get_blackbox_attribute())
660 else if (selected_whole_module(it
.first
))
661 result
.push_back(it
.second
);
662 else if (selected_module(it
.first
))
663 log_warning("Ignoring partially selected module %s.\n", log_id(it
.first
));
667 RTLIL::Module::Module()
669 static unsigned int hashidx_count
= 123456789;
670 hashidx_count
= mkhash_xorshift(hashidx_count
);
671 hashidx_
= hashidx_count
;
678 RTLIL::Module::get_all_modules()->insert(std::pair
<unsigned int, RTLIL::Module
*>(hashidx_
, this));
682 RTLIL::Module::~Module()
684 for (auto it
= wires_
.begin(); it
!= wires_
.end(); ++it
)
686 for (auto it
= memories
.begin(); it
!= memories
.end(); ++it
)
688 for (auto it
= cells_
.begin(); it
!= cells_
.end(); ++it
)
690 for (auto it
= processes
.begin(); it
!= processes
.end(); ++it
)
693 RTLIL::Module::get_all_modules()->erase(hashidx_
);
698 static std::map
<unsigned int, RTLIL::Module
*> all_modules
;
699 std::map
<unsigned int, RTLIL::Module
*> *RTLIL::Module::get_all_modules(void)
705 void RTLIL::Module::makeblackbox()
707 pool
<RTLIL::Wire
*> delwires
;
709 for (auto it
= wires_
.begin(); it
!= wires_
.end(); ++it
)
710 if (!it
->second
->port_input
&& !it
->second
->port_output
)
711 delwires
.insert(it
->second
);
713 for (auto it
= memories
.begin(); it
!= memories
.end(); ++it
)
717 for (auto it
= cells_
.begin(); it
!= cells_
.end(); ++it
)
721 for (auto it
= processes
.begin(); it
!= processes
.end(); ++it
)
726 set_bool_attribute(ID::blackbox
);
729 void RTLIL::Module::reprocess_module(RTLIL::Design
*, const dict
<RTLIL::IdString
, RTLIL::Module
*> &)
731 log_error("Cannot reprocess_module module `%s' !\n", id2cstr(name
));
734 RTLIL::IdString
RTLIL::Module::derive(RTLIL::Design
*, const dict
<RTLIL::IdString
, RTLIL::Const
> &, bool mayfail
)
737 return RTLIL::IdString();
738 log_error("Module `%s' is used with parameters but is not parametric!\n", id2cstr(name
));
742 RTLIL::IdString
RTLIL::Module::derive(RTLIL::Design
*, const dict
<RTLIL::IdString
, RTLIL::Const
> &, const dict
<RTLIL::IdString
, RTLIL::Module
*> &, const dict
<RTLIL::IdString
, RTLIL::IdString
> &, bool mayfail
)
745 return RTLIL::IdString();
746 log_error("Module `%s' is used with parameters but is not parametric!\n", id2cstr(name
));
749 size_t RTLIL::Module::count_id(RTLIL::IdString id
)
751 return wires_
.count(id
) + memories
.count(id
) + cells_
.count(id
) + processes
.count(id
);
756 struct InternalCellChecker
758 RTLIL::Module
*module
;
760 pool
<RTLIL::IdString
> expected_params
, expected_ports
;
762 InternalCellChecker(RTLIL::Module
*module
, RTLIL::Cell
*cell
) : module(module
), cell(cell
) { }
764 void error(int linenr
)
766 std::stringstream buf
;
767 ILANG_BACKEND::dump_cell(buf
, " ", cell
);
769 log_error("Found error in internal cell %s%s%s (%s) at %s:%d:\n%s",
770 module
? module
->name
.c_str() : "", module
? "." : "",
771 cell
->name
.c_str(), cell
->type
.c_str(), __FILE__
, linenr
, buf
.str().c_str());
774 int param(RTLIL::IdString name
)
776 auto it
= cell
->parameters
.find(name
);
777 if (it
== cell
->parameters
.end())
779 expected_params
.insert(name
);
780 return it
->second
.as_int();
783 int param_bool(RTLIL::IdString name
)
786 if (GetSize(cell
->parameters
.at(name
)) > 32)
788 if (v
!= 0 && v
!= 1)
793 int param_bool(RTLIL::IdString name
, bool expected
)
795 int v
= param_bool(name
);
801 void param_bits(RTLIL::IdString name
, int width
)
804 if (GetSize(cell
->parameters
.at(name
).bits
) != width
)
808 void port(RTLIL::IdString name
, int width
)
810 auto it
= cell
->connections_
.find(name
);
811 if (it
== cell
->connections_
.end())
813 if (GetSize(it
->second
) != width
)
815 expected_ports
.insert(name
);
818 void check_expected(bool check_matched_sign
= false)
820 for (auto ¶
: cell
->parameters
)
821 if (expected_params
.count(para
.first
) == 0)
823 for (auto &conn
: cell
->connections())
824 if (expected_ports
.count(conn
.first
) == 0)
827 if (check_matched_sign
) {
828 log_assert(expected_params
.count(ID(A_SIGNED
)) != 0 && expected_params
.count(ID(B_SIGNED
)) != 0);
829 bool a_is_signed
= cell
->parameters
.at(ID(A_SIGNED
)).as_bool();
830 bool b_is_signed
= cell
->parameters
.at(ID(B_SIGNED
)).as_bool();
831 if (a_is_signed
!= b_is_signed
)
838 if (!cell
->type
.begins_with("$") || cell
->type
.begins_with("$__") || cell
->type
.begins_with("$paramod") || cell
->type
.begins_with("$fmcombine") ||
839 cell
->type
.begins_with("$verific$") || cell
->type
.begins_with("$array:") || cell
->type
.begins_with("$extern:"))
842 if (cell
->type
.in(ID($
not), ID($pos
), ID($neg
))) {
843 param_bool(ID(A_SIGNED
));
844 port(ID::A
, param(ID(A_WIDTH
)));
845 port(ID::Y
, param(ID(Y_WIDTH
)));
850 if (cell
->type
.in(ID($
and), ID($
or), ID($
xor), ID($xnor
))) {
851 param_bool(ID(A_SIGNED
));
852 param_bool(ID(B_SIGNED
));
853 port(ID::A
, param(ID(A_WIDTH
)));
854 port(ID::B
, param(ID(B_WIDTH
)));
855 port(ID::Y
, param(ID(Y_WIDTH
)));
856 check_expected(true);
860 if (cell
->type
.in(ID($reduce_and
), ID($reduce_or
), ID($reduce_xor
), ID($reduce_xnor
), ID($reduce_bool
))) {
861 param_bool(ID(A_SIGNED
));
862 port(ID::A
, param(ID(A_WIDTH
)));
863 port(ID::Y
, param(ID(Y_WIDTH
)));
868 if (cell
->type
.in(ID($shl
), ID($shr
), ID($sshl
), ID($sshr
))) {
869 param_bool(ID(A_SIGNED
));
870 param_bool(ID(B_SIGNED
), /*expected=*/false);
871 port(ID::A
, param(ID(A_WIDTH
)));
872 port(ID::B
, param(ID(B_WIDTH
)));
873 port(ID::Y
, param(ID(Y_WIDTH
)));
874 check_expected(/*check_matched_sign=*/false);
878 if (cell
->type
.in(ID($shift
), ID($shiftx
))) {
879 param_bool(ID(A_SIGNED
));
880 param_bool(ID(B_SIGNED
));
881 port(ID::A
, param(ID(A_WIDTH
)));
882 port(ID::B
, param(ID(B_WIDTH
)));
883 port(ID::Y
, param(ID(Y_WIDTH
)));
884 check_expected(/*check_matched_sign=*/false);
888 if (cell
->type
.in(ID($lt
), ID($le
), ID($eq
), ID($ne
), ID($eqx
), ID($nex
), ID($ge
), ID($gt
))) {
889 param_bool(ID(A_SIGNED
));
890 param_bool(ID(B_SIGNED
));
891 port(ID::A
, param(ID(A_WIDTH
)));
892 port(ID::B
, param(ID(B_WIDTH
)));
893 port(ID::Y
, param(ID(Y_WIDTH
)));
894 check_expected(true);
898 if (cell
->type
.in(ID($add
), ID($sub
), ID($mul
), ID($div
), ID($mod
), ID($pow
))) {
899 param_bool(ID(A_SIGNED
));
900 param_bool(ID(B_SIGNED
));
901 port(ID::A
, param(ID(A_WIDTH
)));
902 port(ID::B
, param(ID(B_WIDTH
)));
903 port(ID::Y
, param(ID(Y_WIDTH
)));
904 check_expected(cell
->type
!= ID($pow
));
908 if (cell
->type
== ID($fa
)) {
909 port(ID::A
, param(ID(WIDTH
)));
910 port(ID::B
, param(ID(WIDTH
)));
911 port(ID(C
), param(ID(WIDTH
)));
912 port(ID(X
), param(ID(WIDTH
)));
913 port(ID::Y
, param(ID(WIDTH
)));
918 if (cell
->type
== ID($lcu
)) {
919 port(ID(P
), param(ID(WIDTH
)));
920 port(ID(G
), param(ID(WIDTH
)));
922 port(ID(CO
), param(ID(WIDTH
)));
927 if (cell
->type
== ID($alu
)) {
928 param_bool(ID(A_SIGNED
));
929 param_bool(ID(B_SIGNED
));
930 port(ID::A
, param(ID(A_WIDTH
)));
931 port(ID::B
, param(ID(B_WIDTH
)));
934 port(ID(X
), param(ID(Y_WIDTH
)));
935 port(ID::Y
, param(ID(Y_WIDTH
)));
936 port(ID(CO
), param(ID(Y_WIDTH
)));
937 check_expected(true);
941 if (cell
->type
== ID($macc
)) {
943 param(ID(CONFIG_WIDTH
));
944 port(ID::A
, param(ID(A_WIDTH
)));
945 port(ID::B
, param(ID(B_WIDTH
)));
946 port(ID::Y
, param(ID(Y_WIDTH
)));
948 Macc().from_cell(cell
);
952 if (cell
->type
== ID($logic_not
)) {
953 param_bool(ID(A_SIGNED
));
954 port(ID::A
, param(ID(A_WIDTH
)));
955 port(ID::Y
, param(ID(Y_WIDTH
)));
960 if (cell
->type
.in(ID($logic_and
), ID($logic_or
))) {
961 param_bool(ID(A_SIGNED
));
962 param_bool(ID(B_SIGNED
));
963 port(ID::A
, param(ID(A_WIDTH
)));
964 port(ID::B
, param(ID(B_WIDTH
)));
965 port(ID::Y
, param(ID(Y_WIDTH
)));
966 check_expected(/*check_matched_sign=*/false);
970 if (cell
->type
== ID($slice
)) {
972 port(ID::A
, param(ID(A_WIDTH
)));
973 port(ID::Y
, param(ID(Y_WIDTH
)));
974 if (param(ID(OFFSET
)) + param(ID(Y_WIDTH
)) > param(ID(A_WIDTH
)))
980 if (cell
->type
== ID($concat
)) {
981 port(ID::A
, param(ID(A_WIDTH
)));
982 port(ID::B
, param(ID(B_WIDTH
)));
983 port(ID::Y
, param(ID(A_WIDTH
)) + param(ID(B_WIDTH
)));
988 if (cell
->type
== ID($mux
)) {
989 port(ID::A
, param(ID(WIDTH
)));
990 port(ID::B
, param(ID(WIDTH
)));
992 port(ID::Y
, param(ID(WIDTH
)));
997 if (cell
->type
== ID($pmux
)) {
998 port(ID::A
, param(ID(WIDTH
)));
999 port(ID::B
, param(ID(WIDTH
)) * param(ID(S_WIDTH
)));
1000 port(ID(S
), param(ID(S_WIDTH
)));
1001 port(ID::Y
, param(ID(WIDTH
)));
1006 if (cell
->type
== ID($lut
)) {
1008 port(ID::A
, param(ID(WIDTH
)));
1014 if (cell
->type
== ID($sop
)) {
1017 port(ID::A
, param(ID(WIDTH
)));
1023 if (cell
->type
== ID($sr
)) {
1024 param_bool(ID(SET_POLARITY
));
1025 param_bool(ID(CLR_POLARITY
));
1026 port(ID(SET
), param(ID(WIDTH
)));
1027 port(ID(CLR
), param(ID(WIDTH
)));
1028 port(ID(Q
), param(ID(WIDTH
)));
1033 if (cell
->type
== ID($ff
)) {
1034 port(ID(D
), param(ID(WIDTH
)));
1035 port(ID(Q
), param(ID(WIDTH
)));
1040 if (cell
->type
== ID($dff
)) {
1041 param_bool(ID(CLK_POLARITY
));
1043 port(ID(D
), param(ID(WIDTH
)));
1044 port(ID(Q
), param(ID(WIDTH
)));
1049 if (cell
->type
== ID($dffe
)) {
1050 param_bool(ID(CLK_POLARITY
));
1051 param_bool(ID(EN_POLARITY
));
1054 port(ID(D
), param(ID(WIDTH
)));
1055 port(ID(Q
), param(ID(WIDTH
)));
1060 if (cell
->type
== ID($dffsr
)) {
1061 param_bool(ID(CLK_POLARITY
));
1062 param_bool(ID(SET_POLARITY
));
1063 param_bool(ID(CLR_POLARITY
));
1065 port(ID(SET
), param(ID(WIDTH
)));
1066 port(ID(CLR
), param(ID(WIDTH
)));
1067 port(ID(D
), param(ID(WIDTH
)));
1068 port(ID(Q
), param(ID(WIDTH
)));
1073 if (cell
->type
== ID($adff
)) {
1074 param_bool(ID(CLK_POLARITY
));
1075 param_bool(ID(ARST_POLARITY
));
1076 param_bits(ID(ARST_VALUE
), param(ID(WIDTH
)));
1079 port(ID(D
), param(ID(WIDTH
)));
1080 port(ID(Q
), param(ID(WIDTH
)));
1085 if (cell
->type
== ID($dlatch
)) {
1086 param_bool(ID(EN_POLARITY
));
1088 port(ID(D
), param(ID(WIDTH
)));
1089 port(ID(Q
), param(ID(WIDTH
)));
1094 if (cell
->type
== ID($dlatchsr
)) {
1095 param_bool(ID(EN_POLARITY
));
1096 param_bool(ID(SET_POLARITY
));
1097 param_bool(ID(CLR_POLARITY
));
1099 port(ID(SET
), param(ID(WIDTH
)));
1100 port(ID(CLR
), param(ID(WIDTH
)));
1101 port(ID(D
), param(ID(WIDTH
)));
1102 port(ID(Q
), param(ID(WIDTH
)));
1107 if (cell
->type
== ID($fsm
)) {
1109 param_bool(ID(CLK_POLARITY
));
1110 param_bool(ID(ARST_POLARITY
));
1111 param(ID(STATE_BITS
));
1112 param(ID(STATE_NUM
));
1113 param(ID(STATE_NUM_LOG2
));
1114 param(ID(STATE_RST
));
1115 param_bits(ID(STATE_TABLE
), param(ID(STATE_BITS
)) * param(ID(STATE_NUM
)));
1116 param(ID(TRANS_NUM
));
1117 param_bits(ID(TRANS_TABLE
), param(ID(TRANS_NUM
)) * (2*param(ID(STATE_NUM_LOG2
)) + param(ID(CTRL_IN_WIDTH
)) + param(ID(CTRL_OUT_WIDTH
))));
1120 port(ID(CTRL_IN
), param(ID(CTRL_IN_WIDTH
)));
1121 port(ID(CTRL_OUT
), param(ID(CTRL_OUT_WIDTH
)));
1126 if (cell
->type
== ID($memrd
)) {
1128 param_bool(ID(CLK_ENABLE
));
1129 param_bool(ID(CLK_POLARITY
));
1130 param_bool(ID(TRANSPARENT
));
1133 port(ID(ADDR
), param(ID(ABITS
)));
1134 port(ID(DATA
), param(ID(WIDTH
)));
1139 if (cell
->type
== ID($memwr
)) {
1141 param_bool(ID(CLK_ENABLE
));
1142 param_bool(ID(CLK_POLARITY
));
1143 param(ID(PRIORITY
));
1145 port(ID(EN
), param(ID(WIDTH
)));
1146 port(ID(ADDR
), param(ID(ABITS
)));
1147 port(ID(DATA
), param(ID(WIDTH
)));
1152 if (cell
->type
== ID($meminit
)) {
1154 param(ID(PRIORITY
));
1155 port(ID(ADDR
), param(ID(ABITS
)));
1156 port(ID(DATA
), param(ID(WIDTH
)) * param(ID(WORDS
)));
1161 if (cell
->type
== ID($mem
)) {
1166 param_bits(ID(RD_CLK_ENABLE
), max(1, param(ID(RD_PORTS
))));
1167 param_bits(ID(RD_CLK_POLARITY
), max(1, param(ID(RD_PORTS
))));
1168 param_bits(ID(RD_TRANSPARENT
), max(1, param(ID(RD_PORTS
))));
1169 param_bits(ID(WR_CLK_ENABLE
), max(1, param(ID(WR_PORTS
))));
1170 param_bits(ID(WR_CLK_POLARITY
), max(1, param(ID(WR_PORTS
))));
1171 port(ID(RD_CLK
), param(ID(RD_PORTS
)));
1172 port(ID(RD_EN
), param(ID(RD_PORTS
)));
1173 port(ID(RD_ADDR
), param(ID(RD_PORTS
)) * param(ID(ABITS
)));
1174 port(ID(RD_DATA
), param(ID(RD_PORTS
)) * param(ID(WIDTH
)));
1175 port(ID(WR_CLK
), param(ID(WR_PORTS
)));
1176 port(ID(WR_EN
), param(ID(WR_PORTS
)) * param(ID(WIDTH
)));
1177 port(ID(WR_ADDR
), param(ID(WR_PORTS
)) * param(ID(ABITS
)));
1178 port(ID(WR_DATA
), param(ID(WR_PORTS
)) * param(ID(WIDTH
)));
1183 if (cell
->type
== ID($tribuf
)) {
1184 port(ID::A
, param(ID(WIDTH
)));
1185 port(ID::Y
, param(ID(WIDTH
)));
1191 if (cell
->type
.in(ID($
assert), ID($assume
), ID($live
), ID($fair
), ID($cover
))) {
1198 if (cell
->type
== ID($initstate
)) {
1204 if (cell
->type
.in(ID($anyconst
), ID($anyseq
), ID($allconst
), ID($allseq
))) {
1205 port(ID::Y
, param(ID(WIDTH
)));
1210 if (cell
->type
== ID($equiv
)) {
1218 if (cell
->type
.in(ID($specify2
), ID($specify3
))) {
1219 param_bool(ID(FULL
));
1220 param_bool(ID(SRC_DST_PEN
));
1221 param_bool(ID(SRC_DST_POL
));
1222 param(ID(T_RISE_MIN
));
1223 param(ID(T_RISE_TYP
));
1224 param(ID(T_RISE_MAX
));
1225 param(ID(T_FALL_MIN
));
1226 param(ID(T_FALL_TYP
));
1227 param(ID(T_FALL_MAX
));
1229 port(ID(SRC
), param(ID(SRC_WIDTH
)));
1230 port(ID(DST
), param(ID(DST_WIDTH
)));
1231 if (cell
->type
== ID($specify3
)) {
1232 param_bool(ID(EDGE_EN
));
1233 param_bool(ID(EDGE_POL
));
1234 param_bool(ID(DAT_DST_PEN
));
1235 param_bool(ID(DAT_DST_POL
));
1236 port(ID(DAT
), param(ID(DST_WIDTH
)));
1242 if (cell
->type
== ID($specrule
)) {
1244 param_bool(ID(SRC_PEN
));
1245 param_bool(ID(SRC_POL
));
1246 param_bool(ID(DST_PEN
));
1247 param_bool(ID(DST_POL
));
1248 param(ID(T_LIMIT_MIN
));
1249 param(ID(T_LIMIT_TYP
));
1250 param(ID(T_LIMIT_MAX
));
1251 param(ID(T_LIMIT2_MIN
));
1252 param(ID(T_LIMIT2_TYP
));
1253 param(ID(T_LIMIT2_MAX
));
1254 port(ID(SRC_EN
), 1);
1255 port(ID(DST_EN
), 1);
1256 port(ID(SRC
), param(ID(SRC_WIDTH
)));
1257 port(ID(DST
), param(ID(DST_WIDTH
)));
1262 if (cell
->type
== ID($_BUF_
)) { port(ID::A
,1); port(ID::Y
,1); check_expected(); return; }
1263 if (cell
->type
== ID($_NOT_
)) { port(ID::A
,1); port(ID::Y
,1); check_expected(); return; }
1264 if (cell
->type
== ID($_AND_
)) { port(ID::A
,1); port(ID::B
,1); port(ID::Y
,1); check_expected(); return; }
1265 if (cell
->type
== ID($_NAND_
)) { port(ID::A
,1); port(ID::B
,1); port(ID::Y
,1); check_expected(); return; }
1266 if (cell
->type
== ID($_OR_
)) { port(ID::A
,1); port(ID::B
,1); port(ID::Y
,1); check_expected(); return; }
1267 if (cell
->type
== ID($_NOR_
)) { port(ID::A
,1); port(ID::B
,1); port(ID::Y
,1); check_expected(); return; }
1268 if (cell
->type
== ID($_XOR_
)) { port(ID::A
,1); port(ID::B
,1); port(ID::Y
,1); check_expected(); return; }
1269 if (cell
->type
== ID($_XNOR_
)) { port(ID::A
,1); port(ID::B
,1); port(ID::Y
,1); check_expected(); return; }
1270 if (cell
->type
== ID($_ANDNOT_
)) { port(ID::A
,1); port(ID::B
,1); port(ID::Y
,1); check_expected(); return; }
1271 if (cell
->type
== ID($_ORNOT_
)) { port(ID::A
,1); port(ID::B
,1); port(ID::Y
,1); check_expected(); return; }
1272 if (cell
->type
== ID($_MUX_
)) { port(ID::A
,1); port(ID::B
,1); port(ID(S
),1); port(ID::Y
,1); check_expected(); return; }
1273 if (cell
->type
== ID($_NMUX_
)) { port(ID::A
,1); port(ID::B
,1); port(ID(S
),1); port(ID::Y
,1); check_expected(); return; }
1274 if (cell
->type
== ID($_AOI3_
)) { port(ID::A
,1); port(ID::B
,1); port(ID(C
),1); port(ID::Y
,1); check_expected(); return; }
1275 if (cell
->type
== ID($_OAI3_
)) { port(ID::A
,1); port(ID::B
,1); port(ID(C
),1); port(ID::Y
,1); check_expected(); return; }
1276 if (cell
->type
== ID($_AOI4_
)) { port(ID::A
,1); port(ID::B
,1); port(ID(C
),1); port(ID(D
),1); port(ID::Y
,1); check_expected(); return; }
1277 if (cell
->type
== ID($_OAI4_
)) { port(ID::A
,1); port(ID::B
,1); port(ID(C
),1); port(ID(D
),1); port(ID::Y
,1); check_expected(); return; }
1279 if (cell
->type
== ID($_TBUF_
)) { port(ID::A
,1); port(ID::Y
,1); port(ID(E
),1); check_expected(); return; }
1281 if (cell
->type
== ID($_MUX4_
)) { port(ID::A
,1); port(ID::B
,1); port(ID(C
),1); port(ID(D
),1); port(ID(S
),1); port(ID(T
),1); port(ID::Y
,1); check_expected(); return; }
1282 if (cell
->type
== ID($_MUX8_
)) { port(ID::A
,1); port(ID::B
,1); port(ID(C
),1); port(ID(D
),1); port(ID(E
),1); port(ID(F
),1); port(ID(G
),1); port(ID(H
),1); port(ID(S
),1); port(ID(T
),1); port(ID(U
),1); port(ID::Y
,1); check_expected(); return; }
1283 if (cell
->type
== ID($_MUX16_
)) { port(ID::A
,1); port(ID::B
,1); port(ID(C
),1); port(ID(D
),1); port(ID(E
),1); port(ID(F
),1); port(ID(G
),1); port(ID(H
),1); port(ID(I
),1); port(ID(J
),1); port(ID(K
),1); port(ID(L
),1); port(ID(M
),1); port(ID(N
),1); port(ID(O
),1); port(ID(P
),1); port(ID(S
),1); port(ID(T
),1); port(ID(U
),1); port(ID(V
),1); port(ID::Y
,1); check_expected(); return; }
1285 if (cell
->type
== ID($_SR_NN_
)) { port(ID(S
),1); port(ID(R
),1); port(ID(Q
),1); check_expected(); return; }
1286 if (cell
->type
== ID($_SR_NP_
)) { port(ID(S
),1); port(ID(R
),1); port(ID(Q
),1); check_expected(); return; }
1287 if (cell
->type
== ID($_SR_PN_
)) { port(ID(S
),1); port(ID(R
),1); port(ID(Q
),1); check_expected(); return; }
1288 if (cell
->type
== ID($_SR_PP_
)) { port(ID(S
),1); port(ID(R
),1); port(ID(Q
),1); check_expected(); return; }
1290 if (cell
->type
== ID($_FF_
)) { port(ID(D
),1); port(ID(Q
),1); check_expected(); return; }
1291 if (cell
->type
== ID($_DFF_N_
)) { port(ID(D
),1); port(ID(Q
),1); port(ID(C
),1); check_expected(); return; }
1292 if (cell
->type
== ID($_DFF_P_
)) { port(ID(D
),1); port(ID(Q
),1); port(ID(C
),1); check_expected(); return; }
1294 if (cell
->type
== ID($_DFFE_NN_
)) { port(ID(D
),1); port(ID(Q
),1); port(ID(C
),1); port(ID(E
),1); check_expected(); return; }
1295 if (cell
->type
== ID($_DFFE_NP_
)) { port(ID(D
),1); port(ID(Q
),1); port(ID(C
),1); port(ID(E
),1); check_expected(); return; }
1296 if (cell
->type
== ID($_DFFE_PN_
)) { port(ID(D
),1); port(ID(Q
),1); port(ID(C
),1); port(ID(E
),1); check_expected(); return; }
1297 if (cell
->type
== ID($_DFFE_PP_
)) { port(ID(D
),1); port(ID(Q
),1); port(ID(C
),1); port(ID(E
),1); check_expected(); return; }
1299 if (cell
->type
== ID($_DFF_NN0_
)) { port(ID(D
),1); port(ID(Q
),1); port(ID(C
),1); port(ID(R
),1); check_expected(); return; }
1300 if (cell
->type
== ID($_DFF_NN1_
)) { port(ID(D
),1); port(ID(Q
),1); port(ID(C
),1); port(ID(R
),1); check_expected(); return; }
1301 if (cell
->type
== ID($_DFF_NP0_
)) { port(ID(D
),1); port(ID(Q
),1); port(ID(C
),1); port(ID(R
),1); check_expected(); return; }
1302 if (cell
->type
== ID($_DFF_NP1_
)) { port(ID(D
),1); port(ID(Q
),1); port(ID(C
),1); port(ID(R
),1); check_expected(); return; }
1303 if (cell
->type
== ID($_DFF_PN0_
)) { port(ID(D
),1); port(ID(Q
),1); port(ID(C
),1); port(ID(R
),1); check_expected(); return; }
1304 if (cell
->type
== ID($_DFF_PN1_
)) { port(ID(D
),1); port(ID(Q
),1); port(ID(C
),1); port(ID(R
),1); check_expected(); return; }
1305 if (cell
->type
== ID($_DFF_PP0_
)) { port(ID(D
),1); port(ID(Q
),1); port(ID(C
),1); port(ID(R
),1); check_expected(); return; }
1306 if (cell
->type
== ID($_DFF_PP1_
)) { port(ID(D
),1); port(ID(Q
),1); port(ID(C
),1); port(ID(R
),1); check_expected(); return; }
1308 if (cell
->type
== ID($_DFFSR_NNN_
)) { port(ID(C
),1); port(ID(S
),1); port(ID(R
),1); port(ID(D
),1); port(ID(Q
),1); check_expected(); return; }
1309 if (cell
->type
== ID($_DFFSR_NNP_
)) { port(ID(C
),1); port(ID(S
),1); port(ID(R
),1); port(ID(D
),1); port(ID(Q
),1); check_expected(); return; }
1310 if (cell
->type
== ID($_DFFSR_NPN_
)) { port(ID(C
),1); port(ID(S
),1); port(ID(R
),1); port(ID(D
),1); port(ID(Q
),1); check_expected(); return; }
1311 if (cell
->type
== ID($_DFFSR_NPP_
)) { port(ID(C
),1); port(ID(S
),1); port(ID(R
),1); port(ID(D
),1); port(ID(Q
),1); check_expected(); return; }
1312 if (cell
->type
== ID($_DFFSR_PNN_
)) { port(ID(C
),1); port(ID(S
),1); port(ID(R
),1); port(ID(D
),1); port(ID(Q
),1); check_expected(); return; }
1313 if (cell
->type
== ID($_DFFSR_PNP_
)) { port(ID(C
),1); port(ID(S
),1); port(ID(R
),1); port(ID(D
),1); port(ID(Q
),1); check_expected(); return; }
1314 if (cell
->type
== ID($_DFFSR_PPN_
)) { port(ID(C
),1); port(ID(S
),1); port(ID(R
),1); port(ID(D
),1); port(ID(Q
),1); check_expected(); return; }
1315 if (cell
->type
== ID($_DFFSR_PPP_
)) { port(ID(C
),1); port(ID(S
),1); port(ID(R
),1); port(ID(D
),1); port(ID(Q
),1); check_expected(); return; }
1317 if (cell
->type
== ID($_DLATCH_N_
)) { port(ID(E
),1); port(ID(D
),1); port(ID(Q
),1); check_expected(); return; }
1318 if (cell
->type
== ID($_DLATCH_P_
)) { port(ID(E
),1); port(ID(D
),1); port(ID(Q
),1); check_expected(); return; }
1320 if (cell
->type
== ID($_DLATCHSR_NNN_
)) { port(ID(E
),1); port(ID(S
),1); port(ID(R
),1); port(ID(D
),1); port(ID(Q
),1); check_expected(); return; }
1321 if (cell
->type
== ID($_DLATCHSR_NNP_
)) { port(ID(E
),1); port(ID(S
),1); port(ID(R
),1); port(ID(D
),1); port(ID(Q
),1); check_expected(); return; }
1322 if (cell
->type
== ID($_DLATCHSR_NPN_
)) { port(ID(E
),1); port(ID(S
),1); port(ID(R
),1); port(ID(D
),1); port(ID(Q
),1); check_expected(); return; }
1323 if (cell
->type
== ID($_DLATCHSR_NPP_
)) { port(ID(E
),1); port(ID(S
),1); port(ID(R
),1); port(ID(D
),1); port(ID(Q
),1); check_expected(); return; }
1324 if (cell
->type
== ID($_DLATCHSR_PNN_
)) { port(ID(E
),1); port(ID(S
),1); port(ID(R
),1); port(ID(D
),1); port(ID(Q
),1); check_expected(); return; }
1325 if (cell
->type
== ID($_DLATCHSR_PNP_
)) { port(ID(E
),1); port(ID(S
),1); port(ID(R
),1); port(ID(D
),1); port(ID(Q
),1); check_expected(); return; }
1326 if (cell
->type
== ID($_DLATCHSR_PPN_
)) { port(ID(E
),1); port(ID(S
),1); port(ID(R
),1); port(ID(D
),1); port(ID(Q
),1); check_expected(); return; }
1327 if (cell
->type
== ID($_DLATCHSR_PPP_
)) { port(ID(E
),1); port(ID(S
),1); port(ID(R
),1); port(ID(D
),1); port(ID(Q
),1); check_expected(); return; }
1335 void RTLIL::Module::sort()
1337 wires_
.sort(sort_by_id_str());
1338 cells_
.sort(sort_by_id_str());
1339 avail_parameters
.sort(sort_by_id_str());
1340 memories
.sort(sort_by_id_str());
1341 processes
.sort(sort_by_id_str());
1342 for (auto &it
: cells_
)
1344 for (auto &it
: wires_
)
1345 it
.second
->attributes
.sort(sort_by_id_str());
1346 for (auto &it
: memories
)
1347 it
.second
->attributes
.sort(sort_by_id_str());
1350 void RTLIL::Module::check()
1353 std::vector
<bool> ports_declared
;
1354 for (auto &it
: wires_
) {
1355 log_assert(this == it
.second
->module
);
1356 log_assert(it
.first
== it
.second
->name
);
1357 log_assert(!it
.first
.empty());
1358 log_assert(it
.second
->width
>= 0);
1359 log_assert(it
.second
->port_id
>= 0);
1360 for (auto &it2
: it
.second
->attributes
)
1361 log_assert(!it2
.first
.empty());
1362 if (it
.second
->port_id
) {
1363 log_assert(GetSize(ports
) >= it
.second
->port_id
);
1364 log_assert(ports
.at(it
.second
->port_id
-1) == it
.first
);
1365 log_assert(it
.second
->port_input
|| it
.second
->port_output
);
1366 if (GetSize(ports_declared
) < it
.second
->port_id
)
1367 ports_declared
.resize(it
.second
->port_id
);
1368 log_assert(ports_declared
[it
.second
->port_id
-1] == false);
1369 ports_declared
[it
.second
->port_id
-1] = true;
1371 log_assert(!it
.second
->port_input
&& !it
.second
->port_output
);
1373 for (auto port_declared
: ports_declared
)
1374 log_assert(port_declared
== true);
1375 log_assert(GetSize(ports
) == GetSize(ports_declared
));
1377 for (auto &it
: memories
) {
1378 log_assert(it
.first
== it
.second
->name
);
1379 log_assert(!it
.first
.empty());
1380 log_assert(it
.second
->width
>= 0);
1381 log_assert(it
.second
->size
>= 0);
1382 for (auto &it2
: it
.second
->attributes
)
1383 log_assert(!it2
.first
.empty());
1386 for (auto &it
: cells_
) {
1387 log_assert(this == it
.second
->module
);
1388 log_assert(it
.first
== it
.second
->name
);
1389 log_assert(!it
.first
.empty());
1390 log_assert(!it
.second
->type
.empty());
1391 for (auto &it2
: it
.second
->connections()) {
1392 log_assert(!it2
.first
.empty());
1395 for (auto &it2
: it
.second
->attributes
)
1396 log_assert(!it2
.first
.empty());
1397 for (auto &it2
: it
.second
->parameters
)
1398 log_assert(!it2
.first
.empty());
1399 InternalCellChecker
checker(this, it
.second
);
1403 for (auto &it
: processes
) {
1404 log_assert(it
.first
== it
.second
->name
);
1405 log_assert(!it
.first
.empty());
1406 log_assert(it
.second
->root_case
.compare
.empty());
1407 std::vector
<CaseRule
*> all_cases
= {&it
.second
->root_case
};
1408 for (size_t i
= 0; i
< all_cases
.size(); i
++) {
1409 for (auto &switch_it
: all_cases
[i
]->switches
) {
1410 for (auto &case_it
: switch_it
->cases
) {
1411 for (auto &compare_it
: case_it
->compare
) {
1412 log_assert(switch_it
->signal
.size() == compare_it
.size());
1414 all_cases
.push_back(case_it
);
1418 for (auto &sync_it
: it
.second
->syncs
) {
1419 switch (sync_it
->type
) {
1425 log_assert(!sync_it
->signal
.empty());
1430 log_assert(sync_it
->signal
.empty());
1436 for (auto &it
: connections_
) {
1437 log_assert(it
.first
.size() == it
.second
.size());
1438 log_assert(!it
.first
.has_const());
1443 for (auto &it
: attributes
)
1444 log_assert(!it
.first
.empty());
1448 void RTLIL::Module::optimize()
1452 void RTLIL::Module::cloneInto(RTLIL::Module
*new_mod
) const
1454 log_assert(new_mod
->refcount_wires_
== 0);
1455 log_assert(new_mod
->refcount_cells_
== 0);
1457 new_mod
->avail_parameters
= avail_parameters
;
1459 for (auto &conn
: connections_
)
1460 new_mod
->connect(conn
);
1462 for (auto &attr
: attributes
)
1463 new_mod
->attributes
[attr
.first
] = attr
.second
;
1465 for (auto &it
: wires_
)
1466 new_mod
->addWire(it
.first
, it
.second
);
1468 for (auto &it
: memories
)
1469 new_mod
->memories
[it
.first
] = new RTLIL::Memory(*it
.second
);
1471 for (auto &it
: cells_
)
1472 new_mod
->addCell(it
.first
, it
.second
);
1474 for (auto &it
: processes
)
1475 new_mod
->processes
[it
.first
] = it
.second
->clone();
1477 struct RewriteSigSpecWorker
1480 void operator()(RTLIL::SigSpec
&sig
)
1483 for (auto &c
: sig
.chunks_
)
1485 c
.wire
= mod
->wires_
.at(c
.wire
->name
);
1489 RewriteSigSpecWorker rewriteSigSpecWorker
;
1490 rewriteSigSpecWorker
.mod
= new_mod
;
1491 new_mod
->rewrite_sigspecs(rewriteSigSpecWorker
);
1492 new_mod
->fixup_ports();
1495 RTLIL::Module
*RTLIL::Module::clone() const
1497 RTLIL::Module
*new_mod
= new RTLIL::Module
;
1498 new_mod
->name
= name
;
1503 bool RTLIL::Module::has_memories() const
1505 return !memories
.empty();
1508 bool RTLIL::Module::has_processes() const
1510 return !processes
.empty();
1513 bool RTLIL::Module::has_memories_warn() const
1515 if (!memories
.empty())
1516 log_warning("Ignoring module %s because it contains memories (run 'memory' command first).\n", log_id(this));
1517 return !memories
.empty();
1520 bool RTLIL::Module::has_processes_warn() const
1522 if (!processes
.empty())
1523 log_warning("Ignoring module %s because it contains processes (run 'proc' command first).\n", log_id(this));
1524 return !processes
.empty();
1527 std::vector
<RTLIL::Wire
*> RTLIL::Module::selected_wires() const
1529 std::vector
<RTLIL::Wire
*> result
;
1530 result
.reserve(wires_
.size());
1531 for (auto &it
: wires_
)
1532 if (design
->selected(this, it
.second
))
1533 result
.push_back(it
.second
);
1537 std::vector
<RTLIL::Cell
*> RTLIL::Module::selected_cells() const
1539 std::vector
<RTLIL::Cell
*> result
;
1540 result
.reserve(cells_
.size());
1541 for (auto &it
: cells_
)
1542 if (design
->selected(this, it
.second
))
1543 result
.push_back(it
.second
);
1547 void RTLIL::Module::add(RTLIL::Wire
*wire
)
1549 log_assert(!wire
->name
.empty());
1550 log_assert(count_id(wire
->name
) == 0);
1551 log_assert(refcount_wires_
== 0);
1552 wires_
[wire
->name
] = wire
;
1553 wire
->module
= this;
1556 void RTLIL::Module::add(RTLIL::Cell
*cell
)
1558 log_assert(!cell
->name
.empty());
1559 log_assert(count_id(cell
->name
) == 0);
1560 log_assert(refcount_cells_
== 0);
1561 cells_
[cell
->name
] = cell
;
1562 cell
->module
= this;
1565 void RTLIL::Module::remove(const pool
<RTLIL::Wire
*> &wires
)
1567 log_assert(refcount_wires_
== 0);
1569 struct DeleteWireWorker
1571 RTLIL::Module
*module
;
1572 const pool
<RTLIL::Wire
*> *wires_p
;
1574 void operator()(RTLIL::SigSpec
&sig
) {
1576 for (auto &c
: sig
.chunks_
)
1577 if (c
.wire
!= NULL
&& wires_p
->count(c
.wire
)) {
1578 c
.wire
= module
->addWire(NEW_ID
, c
.width
);
1583 void operator()(RTLIL::SigSpec
&lhs
, RTLIL::SigSpec
&rhs
) {
1584 log_assert(GetSize(lhs
) == GetSize(rhs
));
1587 for (int i
= 0; i
< GetSize(lhs
); i
++) {
1588 RTLIL::SigBit
&lhs_bit
= lhs
.bits_
[i
];
1589 RTLIL::SigBit
&rhs_bit
= rhs
.bits_
[i
];
1590 if ((lhs_bit
.wire
!= nullptr && wires_p
->count(lhs_bit
.wire
)) || (rhs_bit
.wire
!= nullptr && wires_p
->count(rhs_bit
.wire
))) {
1591 lhs_bit
= State::Sx
;
1592 rhs_bit
= State::Sx
;
1598 DeleteWireWorker delete_wire_worker
;
1599 delete_wire_worker
.module
= this;
1600 delete_wire_worker
.wires_p
= &wires
;
1601 rewrite_sigspecs2(delete_wire_worker
);
1603 for (auto &it
: wires
) {
1604 log_assert(wires_
.count(it
->name
) != 0);
1605 wires_
.erase(it
->name
);
1610 void RTLIL::Module::remove(RTLIL::Cell
*cell
)
1612 while (!cell
->connections_
.empty())
1613 cell
->unsetPort(cell
->connections_
.begin()->first
);
1615 log_assert(cells_
.count(cell
->name
) != 0);
1616 log_assert(refcount_cells_
== 0);
1617 cells_
.erase(cell
->name
);
1621 void RTLIL::Module::rename(RTLIL::Wire
*wire
, RTLIL::IdString new_name
)
1623 log_assert(wires_
[wire
->name
] == wire
);
1624 log_assert(refcount_wires_
== 0);
1625 wires_
.erase(wire
->name
);
1626 wire
->name
= new_name
;
1630 void RTLIL::Module::rename(RTLIL::Cell
*cell
, RTLIL::IdString new_name
)
1632 log_assert(cells_
[cell
->name
] == cell
);
1633 log_assert(refcount_wires_
== 0);
1634 cells_
.erase(cell
->name
);
1635 cell
->name
= new_name
;
1639 void RTLIL::Module::rename(RTLIL::IdString old_name
, RTLIL::IdString new_name
)
1641 log_assert(count_id(old_name
) != 0);
1642 if (wires_
.count(old_name
))
1643 rename(wires_
.at(old_name
), new_name
);
1644 else if (cells_
.count(old_name
))
1645 rename(cells_
.at(old_name
), new_name
);
1650 void RTLIL::Module::swap_names(RTLIL::Wire
*w1
, RTLIL::Wire
*w2
)
1652 log_assert(wires_
[w1
->name
] == w1
);
1653 log_assert(wires_
[w2
->name
] == w2
);
1654 log_assert(refcount_wires_
== 0);
1656 wires_
.erase(w1
->name
);
1657 wires_
.erase(w2
->name
);
1659 std::swap(w1
->name
, w2
->name
);
1661 wires_
[w1
->name
] = w1
;
1662 wires_
[w2
->name
] = w2
;
1665 void RTLIL::Module::swap_names(RTLIL::Cell
*c1
, RTLIL::Cell
*c2
)
1667 log_assert(cells_
[c1
->name
] == c1
);
1668 log_assert(cells_
[c2
->name
] == c2
);
1669 log_assert(refcount_cells_
== 0);
1671 cells_
.erase(c1
->name
);
1672 cells_
.erase(c2
->name
);
1674 std::swap(c1
->name
, c2
->name
);
1676 cells_
[c1
->name
] = c1
;
1677 cells_
[c2
->name
] = c2
;
1680 RTLIL::IdString
RTLIL::Module::uniquify(RTLIL::IdString name
)
1683 return uniquify(name
, index
);
1686 RTLIL::IdString
RTLIL::Module::uniquify(RTLIL::IdString name
, int &index
)
1689 if (count_id(name
) == 0)
1695 RTLIL::IdString new_name
= stringf("%s_%d", name
.c_str(), index
);
1696 if (count_id(new_name
) == 0)
1702 static bool fixup_ports_compare(const RTLIL::Wire
*a
, const RTLIL::Wire
*b
)
1704 if (a
->port_id
&& !b
->port_id
)
1706 if (!a
->port_id
&& b
->port_id
)
1709 if (a
->port_id
== b
->port_id
)
1710 return a
->name
< b
->name
;
1711 return a
->port_id
< b
->port_id
;
1714 void RTLIL::Module::connect(const RTLIL::SigSig
&conn
)
1716 for (auto mon
: monitors
)
1717 mon
->notify_connect(this, conn
);
1720 for (auto mon
: design
->monitors
)
1721 mon
->notify_connect(this, conn
);
1723 // ignore all attempts to assign constants to other constants
1724 if (conn
.first
.has_const()) {
1725 RTLIL::SigSig new_conn
;
1726 for (int i
= 0; i
< GetSize(conn
.first
); i
++)
1727 if (conn
.first
[i
].wire
) {
1728 new_conn
.first
.append(conn
.first
[i
]);
1729 new_conn
.second
.append(conn
.second
[i
]);
1731 if (GetSize(new_conn
.first
))
1737 log("#X# Connect (SigSig) in %s: %s = %s (%d bits)\n", log_id(this), log_signal(conn
.first
), log_signal(conn
.second
), GetSize(conn
.first
));
1738 log_backtrace("-X- ", yosys_xtrace
-1);
1741 log_assert(GetSize(conn
.first
) == GetSize(conn
.second
));
1742 connections_
.push_back(conn
);
1745 void RTLIL::Module::connect(const RTLIL::SigSpec
&lhs
, const RTLIL::SigSpec
&rhs
)
1747 connect(RTLIL::SigSig(lhs
, rhs
));
1750 void RTLIL::Module::new_connections(const std::vector
<RTLIL::SigSig
> &new_conn
)
1752 for (auto mon
: monitors
)
1753 mon
->notify_connect(this, new_conn
);
1756 for (auto mon
: design
->monitors
)
1757 mon
->notify_connect(this, new_conn
);
1760 log("#X# New connections vector in %s:\n", log_id(this));
1761 for (auto &conn
: new_conn
)
1762 log("#X# %s = %s (%d bits)\n", log_signal(conn
.first
), log_signal(conn
.second
), GetSize(conn
.first
));
1763 log_backtrace("-X- ", yosys_xtrace
-1);
1766 connections_
= new_conn
;
1769 const std::vector
<RTLIL::SigSig
> &RTLIL::Module::connections() const
1771 return connections_
;
1774 void RTLIL::Module::fixup_ports()
1776 std::vector
<RTLIL::Wire
*> all_ports
;
1778 for (auto &w
: wires_
)
1779 if (w
.second
->port_input
|| w
.second
->port_output
)
1780 all_ports
.push_back(w
.second
);
1782 w
.second
->port_id
= 0;
1784 std::sort(all_ports
.begin(), all_ports
.end(), fixup_ports_compare
);
1787 for (size_t i
= 0; i
< all_ports
.size(); i
++) {
1788 ports
.push_back(all_ports
[i
]->name
);
1789 all_ports
[i
]->port_id
= i
+1;
1793 RTLIL::Wire
*RTLIL::Module::addWire(RTLIL::IdString name
, int width
)
1795 RTLIL::Wire
*wire
= new RTLIL::Wire
;
1797 wire
->width
= width
;
1802 RTLIL::Wire
*RTLIL::Module::addWire(RTLIL::IdString name
, const RTLIL::Wire
*other
)
1804 RTLIL::Wire
*wire
= addWire(name
);
1805 wire
->width
= other
->width
;
1806 wire
->start_offset
= other
->start_offset
;
1807 wire
->port_id
= other
->port_id
;
1808 wire
->port_input
= other
->port_input
;
1809 wire
->port_output
= other
->port_output
;
1810 wire
->upto
= other
->upto
;
1811 wire
->attributes
= other
->attributes
;
1815 RTLIL::Cell
*RTLIL::Module::addCell(RTLIL::IdString name
, RTLIL::IdString type
)
1817 RTLIL::Cell
*cell
= new RTLIL::Cell
;
1824 RTLIL::Cell
*RTLIL::Module::addCell(RTLIL::IdString name
, const RTLIL::Cell
*other
)
1826 RTLIL::Cell
*cell
= addCell(name
, other
->type
);
1827 cell
->connections_
= other
->connections_
;
1828 cell
->parameters
= other
->parameters
;
1829 cell
->attributes
= other
->attributes
;
1833 #define DEF_METHOD(_func, _y_size, _type) \
1834 RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_y, bool is_signed, const std::string &src) { \
1835 RTLIL::Cell *cell = addCell(name, _type); \
1836 cell->parameters[ID(A_SIGNED)] = is_signed; \
1837 cell->parameters[ID(A_WIDTH)] = sig_a.size(); \
1838 cell->parameters[ID(Y_WIDTH)] = sig_y.size(); \
1839 cell->setPort(ID::A, sig_a); \
1840 cell->setPort(ID::Y, sig_y); \
1841 cell->set_src_attribute(src); \
1844 RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, bool is_signed, const std::string &src) { \
1845 RTLIL::SigSpec sig_y = addWire(NEW_ID, _y_size); \
1846 add ## _func(name, sig_a, sig_y, is_signed, src); \
1849 DEF_METHOD(Not
, sig_a
.size(), ID($
not))
1850 DEF_METHOD(Pos
, sig_a
.size(), ID($pos
))
1851 DEF_METHOD(Neg
, sig_a
.size(), ID($neg
))
1852 DEF_METHOD(ReduceAnd
, 1, ID($reduce_and
))
1853 DEF_METHOD(ReduceOr
, 1, ID($reduce_or
))
1854 DEF_METHOD(ReduceXor
, 1, ID($reduce_xor
))
1855 DEF_METHOD(ReduceXnor
, 1, ID($reduce_xnor
))
1856 DEF_METHOD(ReduceBool
, 1, ID($reduce_bool
))
1857 DEF_METHOD(LogicNot
, 1, ID($logic_not
))
1860 #define DEF_METHOD(_func, _y_size, _type) \
1861 RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed, const std::string &src) { \
1862 RTLIL::Cell *cell = addCell(name, _type); \
1863 cell->parameters[ID(A_SIGNED)] = is_signed; \
1864 cell->parameters[ID(B_SIGNED)] = is_signed; \
1865 cell->parameters[ID(A_WIDTH)] = sig_a.size(); \
1866 cell->parameters[ID(B_WIDTH)] = sig_b.size(); \
1867 cell->parameters[ID(Y_WIDTH)] = sig_y.size(); \
1868 cell->setPort(ID::A, sig_a); \
1869 cell->setPort(ID::B, sig_b); \
1870 cell->setPort(ID::Y, sig_y); \
1871 cell->set_src_attribute(src); \
1874 RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed, const std::string &src) { \
1875 RTLIL::SigSpec sig_y = addWire(NEW_ID, _y_size); \
1876 add ## _func(name, sig_a, sig_b, sig_y, is_signed, src); \
1879 DEF_METHOD(And
, max(sig_a
.size(), sig_b
.size()), ID($
and))
1880 DEF_METHOD(Or
, max(sig_a
.size(), sig_b
.size()), ID($
or))
1881 DEF_METHOD(Xor
, max(sig_a
.size(), sig_b
.size()), ID($
xor))
1882 DEF_METHOD(Xnor
, max(sig_a
.size(), sig_b
.size()), ID($xnor
))
1883 DEF_METHOD(Shift
, sig_a
.size(), ID($shift
))
1884 DEF_METHOD(Shiftx
, sig_a
.size(), ID($shiftx
))
1885 DEF_METHOD(Lt
, 1, ID($lt
))
1886 DEF_METHOD(Le
, 1, ID($le
))
1887 DEF_METHOD(Eq
, 1, ID($eq
))
1888 DEF_METHOD(Ne
, 1, ID($ne
))
1889 DEF_METHOD(Eqx
, 1, ID($eqx
))
1890 DEF_METHOD(Nex
, 1, ID($nex
))
1891 DEF_METHOD(Ge
, 1, ID($ge
))
1892 DEF_METHOD(Gt
, 1, ID($gt
))
1893 DEF_METHOD(Add
, max(sig_a
.size(), sig_b
.size()), ID($add
))
1894 DEF_METHOD(Sub
, max(sig_a
.size(), sig_b
.size()), ID($sub
))
1895 DEF_METHOD(Mul
, max(sig_a
.size(), sig_b
.size()), ID($mul
))
1896 DEF_METHOD(Div
, max(sig_a
.size(), sig_b
.size()), ID($div
))
1897 DEF_METHOD(Mod
, max(sig_a
.size(), sig_b
.size()), ID($mod
))
1898 DEF_METHOD(LogicAnd
, 1, ID($logic_and
))
1899 DEF_METHOD(LogicOr
, 1, ID($logic_or
))
1902 #define DEF_METHOD(_func, _y_size, _type) \
1903 RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_y, bool is_signed, const std::string &src) { \
1904 RTLIL::Cell *cell = addCell(name, _type); \
1905 cell->parameters[ID(A_SIGNED)] = is_signed; \
1906 cell->parameters[ID(B_SIGNED)] = false; \
1907 cell->parameters[ID(A_WIDTH)] = sig_a.size(); \
1908 cell->parameters[ID(B_WIDTH)] = sig_b.size(); \
1909 cell->parameters[ID(Y_WIDTH)] = sig_y.size(); \
1910 cell->setPort(ID::A, sig_a); \
1911 cell->setPort(ID::B, sig_b); \
1912 cell->setPort(ID::Y, sig_y); \
1913 cell->set_src_attribute(src); \
1916 RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, bool is_signed, const std::string &src) { \
1917 RTLIL::SigSpec sig_y = addWire(NEW_ID, _y_size); \
1918 add ## _func(name, sig_a, sig_b, sig_y, is_signed, src); \
1921 DEF_METHOD(Shl
, sig_a
.size(), ID($shl
))
1922 DEF_METHOD(Shr
, sig_a
.size(), ID($shr
))
1923 DEF_METHOD(Sshl
, sig_a
.size(), ID($sshl
))
1924 DEF_METHOD(Sshr
, sig_a
.size(), ID($sshr
))
1927 #define DEF_METHOD(_func, _type, _pmux) \
1928 RTLIL::Cell* RTLIL::Module::add ## _func(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) { \
1929 RTLIL::Cell *cell = addCell(name, _type); \
1930 cell->parameters[ID(WIDTH)] = sig_a.size(); \
1931 if (_pmux) cell->parameters[ID(S_WIDTH)] = sig_s.size(); \
1932 cell->setPort(ID::A, sig_a); \
1933 cell->setPort(ID::B, sig_b); \
1934 cell->setPort(ID(S), sig_s); \
1935 cell->setPort(ID::Y, sig_y); \
1936 cell->set_src_attribute(src); \
1939 RTLIL::SigSpec RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigSpec &sig_a, const RTLIL::SigSpec &sig_b, const RTLIL::SigSpec &sig_s, const std::string &src) { \
1940 RTLIL::SigSpec sig_y = addWire(NEW_ID, sig_a.size()); \
1941 add ## _func(name, sig_a, sig_b, sig_s, sig_y, src); \
1944 DEF_METHOD(Mux
, ID($mux
), 0)
1945 DEF_METHOD(Pmux
, ID($pmux
), 1)
1948 #define DEF_METHOD_2(_func, _type, _P1, _P2) \
1949 RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const std::string &src) { \
1950 RTLIL::Cell *cell = addCell(name, _type); \
1951 cell->setPort("\\" #_P1, sig1); \
1952 cell->setPort("\\" #_P2, sig2); \
1953 cell->set_src_attribute(src); \
1956 RTLIL::SigBit RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const std::string &src) { \
1957 RTLIL::SigBit sig2 = addWire(NEW_ID); \
1958 add ## _func(name, sig1, sig2, src); \
1961 #define DEF_METHOD_3(_func, _type, _P1, _P2, _P3) \
1962 RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const RTLIL::SigBit &sig3, const std::string &src) { \
1963 RTLIL::Cell *cell = addCell(name, _type); \
1964 cell->setPort("\\" #_P1, sig1); \
1965 cell->setPort("\\" #_P2, sig2); \
1966 cell->setPort("\\" #_P3, sig3); \
1967 cell->set_src_attribute(src); \
1970 RTLIL::SigBit RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const std::string &src) { \
1971 RTLIL::SigBit sig3 = addWire(NEW_ID); \
1972 add ## _func(name, sig1, sig2, sig3, src); \
1975 #define DEF_METHOD_4(_func, _type, _P1, _P2, _P3, _P4) \
1976 RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const RTLIL::SigBit &sig3, const RTLIL::SigBit &sig4, const std::string &src) { \
1977 RTLIL::Cell *cell = addCell(name, _type); \
1978 cell->setPort("\\" #_P1, sig1); \
1979 cell->setPort("\\" #_P2, sig2); \
1980 cell->setPort("\\" #_P3, sig3); \
1981 cell->setPort("\\" #_P4, sig4); \
1982 cell->set_src_attribute(src); \
1985 RTLIL::SigBit RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const RTLIL::SigBit &sig3, const std::string &src) { \
1986 RTLIL::SigBit sig4 = addWire(NEW_ID); \
1987 add ## _func(name, sig1, sig2, sig3, sig4, src); \
1990 #define DEF_METHOD_5(_func, _type, _P1, _P2, _P3, _P4, _P5) \
1991 RTLIL::Cell* RTLIL::Module::add ## _func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const RTLIL::SigBit &sig3, const RTLIL::SigBit &sig4, const RTLIL::SigBit &sig5, const std::string &src) { \
1992 RTLIL::Cell *cell = addCell(name, _type); \
1993 cell->setPort("\\" #_P1, sig1); \
1994 cell->setPort("\\" #_P2, sig2); \
1995 cell->setPort("\\" #_P3, sig3); \
1996 cell->setPort("\\" #_P4, sig4); \
1997 cell->setPort("\\" #_P5, sig5); \
1998 cell->set_src_attribute(src); \
2001 RTLIL::SigBit RTLIL::Module::_func(RTLIL::IdString name, const RTLIL::SigBit &sig1, const RTLIL::SigBit &sig2, const RTLIL::SigBit &sig3, const RTLIL::SigBit &sig4, const std::string &src) { \
2002 RTLIL::SigBit sig5 = addWire(NEW_ID); \
2003 add ## _func(name, sig1, sig2, sig3, sig4, sig5, src); \
2006 DEF_METHOD_2(BufGate
, ID($_BUF_
), A
, Y
)
2007 DEF_METHOD_2(NotGate
, ID($_NOT_
), A
, Y
)
2008 DEF_METHOD_3(AndGate
, ID($_AND_
), A
, B
, Y
)
2009 DEF_METHOD_3(NandGate
, ID($_NAND_
), A
, B
, Y
)
2010 DEF_METHOD_3(OrGate
, ID($_OR_
), A
, B
, Y
)
2011 DEF_METHOD_3(NorGate
, ID($_NOR_
), A
, B
, Y
)
2012 DEF_METHOD_3(XorGate
, ID($_XOR_
), A
, B
, Y
)
2013 DEF_METHOD_3(XnorGate
, ID($_XNOR_
), A
, B
, Y
)
2014 DEF_METHOD_3(AndnotGate
, ID($_ANDNOT_
), A
, B
, Y
)
2015 DEF_METHOD_3(OrnotGate
, ID($_ORNOT_
), A
, B
, Y
)
2016 DEF_METHOD_4(MuxGate
, ID($_MUX_
), A
, B
, S
, Y
)
2017 DEF_METHOD_4(NmuxGate
, ID($_NMUX_
), A
, B
, S
, Y
)
2018 DEF_METHOD_4(Aoi3Gate
, ID($_AOI3_
), A
, B
, C
, Y
)
2019 DEF_METHOD_4(Oai3Gate
, ID($_OAI3_
), A
, B
, C
, Y
)
2020 DEF_METHOD_5(Aoi4Gate
, ID($_AOI4_
), A
, B
, C
, D
, Y
)
2021 DEF_METHOD_5(Oai4Gate
, ID($_OAI4_
), A
, B
, C
, D
, Y
)
2027 RTLIL::Cell
* RTLIL::Module::addPow(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, const RTLIL::SigSpec
&sig_y
, bool a_signed
, bool b_signed
, const std::string
&src
)
2029 RTLIL::Cell
*cell
= addCell(name
, ID($pow
));
2030 cell
->parameters
[ID(A_SIGNED
)] = a_signed
;
2031 cell
->parameters
[ID(B_SIGNED
)] = b_signed
;
2032 cell
->parameters
[ID(A_WIDTH
)] = sig_a
.size();
2033 cell
->parameters
[ID(B_WIDTH
)] = sig_b
.size();
2034 cell
->parameters
[ID(Y_WIDTH
)] = sig_y
.size();
2035 cell
->setPort(ID::A
, sig_a
);
2036 cell
->setPort(ID::B
, sig_b
);
2037 cell
->setPort(ID::Y
, sig_y
);
2038 cell
->set_src_attribute(src
);
2042 RTLIL::Cell
* RTLIL::Module::addSlice(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, RTLIL::Const offset
, const std::string
&src
)
2044 RTLIL::Cell
*cell
= addCell(name
, ID($slice
));
2045 cell
->parameters
[ID(A_WIDTH
)] = sig_a
.size();
2046 cell
->parameters
[ID(Y_WIDTH
)] = sig_y
.size();
2047 cell
->parameters
[ID(OFFSET
)] = offset
;
2048 cell
->setPort(ID::A
, sig_a
);
2049 cell
->setPort(ID::Y
, sig_y
);
2050 cell
->set_src_attribute(src
);
2054 RTLIL::Cell
* RTLIL::Module::addConcat(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, const RTLIL::SigSpec
&sig_y
, const std::string
&src
)
2056 RTLIL::Cell
*cell
= addCell(name
, ID($concat
));
2057 cell
->parameters
[ID(A_WIDTH
)] = sig_a
.size();
2058 cell
->parameters
[ID(B_WIDTH
)] = sig_b
.size();
2059 cell
->setPort(ID::A
, sig_a
);
2060 cell
->setPort(ID::B
, sig_b
);
2061 cell
->setPort(ID::Y
, sig_y
);
2062 cell
->set_src_attribute(src
);
2066 RTLIL::Cell
* RTLIL::Module::addLut(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_y
, RTLIL::Const lut
, const std::string
&src
)
2068 RTLIL::Cell
*cell
= addCell(name
, ID($lut
));
2069 cell
->parameters
[ID(LUT
)] = lut
;
2070 cell
->parameters
[ID(WIDTH
)] = sig_a
.size();
2071 cell
->setPort(ID::A
, sig_a
);
2072 cell
->setPort(ID::Y
, sig_y
);
2073 cell
->set_src_attribute(src
);
2077 RTLIL::Cell
* RTLIL::Module::addTribuf(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_en
, const RTLIL::SigSpec
&sig_y
, const std::string
&src
)
2079 RTLIL::Cell
*cell
= addCell(name
, ID($tribuf
));
2080 cell
->parameters
[ID(WIDTH
)] = sig_a
.size();
2081 cell
->setPort(ID::A
, sig_a
);
2082 cell
->setPort(ID(EN
), sig_en
);
2083 cell
->setPort(ID::Y
, sig_y
);
2084 cell
->set_src_attribute(src
);
2088 RTLIL::Cell
* RTLIL::Module::addAssert(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_en
, const std::string
&src
)
2090 RTLIL::Cell
*cell
= addCell(name
, ID($
assert));
2091 cell
->setPort(ID::A
, sig_a
);
2092 cell
->setPort(ID(EN
), sig_en
);
2093 cell
->set_src_attribute(src
);
2097 RTLIL::Cell
* RTLIL::Module::addAssume(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_en
, const std::string
&src
)
2099 RTLIL::Cell
*cell
= addCell(name
, ID($assume
));
2100 cell
->setPort(ID::A
, sig_a
);
2101 cell
->setPort(ID(EN
), sig_en
);
2102 cell
->set_src_attribute(src
);
2106 RTLIL::Cell
* RTLIL::Module::addLive(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_en
, const std::string
&src
)
2108 RTLIL::Cell
*cell
= addCell(name
, ID($live
));
2109 cell
->setPort(ID::A
, sig_a
);
2110 cell
->setPort(ID(EN
), sig_en
);
2111 cell
->set_src_attribute(src
);
2115 RTLIL::Cell
* RTLIL::Module::addFair(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_en
, const std::string
&src
)
2117 RTLIL::Cell
*cell
= addCell(name
, ID($fair
));
2118 cell
->setPort(ID::A
, sig_a
);
2119 cell
->setPort(ID(EN
), sig_en
);
2120 cell
->set_src_attribute(src
);
2124 RTLIL::Cell
* RTLIL::Module::addCover(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_en
, const std::string
&src
)
2126 RTLIL::Cell
*cell
= addCell(name
, ID($cover
));
2127 cell
->setPort(ID::A
, sig_a
);
2128 cell
->setPort(ID(EN
), sig_en
);
2129 cell
->set_src_attribute(src
);
2133 RTLIL::Cell
* RTLIL::Module::addEquiv(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_a
, const RTLIL::SigSpec
&sig_b
, const RTLIL::SigSpec
&sig_y
, const std::string
&src
)
2135 RTLIL::Cell
*cell
= addCell(name
, ID($equiv
));
2136 cell
->setPort(ID::A
, sig_a
);
2137 cell
->setPort(ID::B
, sig_b
);
2138 cell
->setPort(ID::Y
, sig_y
);
2139 cell
->set_src_attribute(src
);
2143 RTLIL::Cell
* RTLIL::Module::addSr(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_set
, const RTLIL::SigSpec
&sig_clr
, const RTLIL::SigSpec
&sig_q
, bool set_polarity
, bool clr_polarity
, const std::string
&src
)
2145 RTLIL::Cell
*cell
= addCell(name
, ID($sr
));
2146 cell
->parameters
[ID(SET_POLARITY
)] = set_polarity
;
2147 cell
->parameters
[ID(CLR_POLARITY
)] = clr_polarity
;
2148 cell
->parameters
[ID(WIDTH
)] = sig_q
.size();
2149 cell
->setPort(ID(SET
), sig_set
);
2150 cell
->setPort(ID(CLR
), sig_clr
);
2151 cell
->setPort(ID(Q
), sig_q
);
2152 cell
->set_src_attribute(src
);
2156 RTLIL::Cell
* RTLIL::Module::addFf(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_d
, const RTLIL::SigSpec
&sig_q
, const std::string
&src
)
2158 RTLIL::Cell
*cell
= addCell(name
, ID($ff
));
2159 cell
->parameters
[ID(WIDTH
)] = sig_q
.size();
2160 cell
->setPort(ID(D
), sig_d
);
2161 cell
->setPort(ID(Q
), sig_q
);
2162 cell
->set_src_attribute(src
);
2166 RTLIL::Cell
* RTLIL::Module::addDff(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_clk
, const RTLIL::SigSpec
&sig_d
, const RTLIL::SigSpec
&sig_q
, bool clk_polarity
, const std::string
&src
)
2168 RTLIL::Cell
*cell
= addCell(name
, ID($dff
));
2169 cell
->parameters
[ID(CLK_POLARITY
)] = clk_polarity
;
2170 cell
->parameters
[ID(WIDTH
)] = sig_q
.size();
2171 cell
->setPort(ID(CLK
), sig_clk
);
2172 cell
->setPort(ID(D
), sig_d
);
2173 cell
->setPort(ID(Q
), sig_q
);
2174 cell
->set_src_attribute(src
);
2178 RTLIL::Cell
* RTLIL::Module::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
, bool en_polarity
, const std::string
&src
)
2180 RTLIL::Cell
*cell
= addCell(name
, ID($dffe
));
2181 cell
->parameters
[ID(CLK_POLARITY
)] = clk_polarity
;
2182 cell
->parameters
[ID(EN_POLARITY
)] = en_polarity
;
2183 cell
->parameters
[ID(WIDTH
)] = sig_q
.size();
2184 cell
->setPort(ID(CLK
), sig_clk
);
2185 cell
->setPort(ID(EN
), sig_en
);
2186 cell
->setPort(ID(D
), sig_d
);
2187 cell
->setPort(ID(Q
), sig_q
);
2188 cell
->set_src_attribute(src
);
2192 RTLIL::Cell
* RTLIL::Module::addDffsr(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_clk
, const RTLIL::SigSpec
&sig_set
, const RTLIL::SigSpec
&sig_clr
,
2193 RTLIL::SigSpec sig_d
, const RTLIL::SigSpec
&sig_q
, bool clk_polarity
, bool set_polarity
, bool clr_polarity
, const std::string
&src
)
2195 RTLIL::Cell
*cell
= addCell(name
, ID($dffsr
));
2196 cell
->parameters
[ID(CLK_POLARITY
)] = clk_polarity
;
2197 cell
->parameters
[ID(SET_POLARITY
)] = set_polarity
;
2198 cell
->parameters
[ID(CLR_POLARITY
)] = clr_polarity
;
2199 cell
->parameters
[ID(WIDTH
)] = sig_q
.size();
2200 cell
->setPort(ID(CLK
), sig_clk
);
2201 cell
->setPort(ID(SET
), sig_set
);
2202 cell
->setPort(ID(CLR
), sig_clr
);
2203 cell
->setPort(ID(D
), sig_d
);
2204 cell
->setPort(ID(Q
), sig_q
);
2205 cell
->set_src_attribute(src
);
2209 RTLIL::Cell
* RTLIL::Module::addAdff(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_clk
, const RTLIL::SigSpec
&sig_arst
, const RTLIL::SigSpec
&sig_d
, const RTLIL::SigSpec
&sig_q
,
2210 RTLIL::Const arst_value
, bool clk_polarity
, bool arst_polarity
, const std::string
&src
)
2212 RTLIL::Cell
*cell
= addCell(name
, ID($adff
));
2213 cell
->parameters
[ID(CLK_POLARITY
)] = clk_polarity
;
2214 cell
->parameters
[ID(ARST_POLARITY
)] = arst_polarity
;
2215 cell
->parameters
[ID(ARST_VALUE
)] = arst_value
;
2216 cell
->parameters
[ID(WIDTH
)] = sig_q
.size();
2217 cell
->setPort(ID(CLK
), sig_clk
);
2218 cell
->setPort(ID(ARST
), sig_arst
);
2219 cell
->setPort(ID(D
), sig_d
);
2220 cell
->setPort(ID(Q
), sig_q
);
2221 cell
->set_src_attribute(src
);
2225 RTLIL::Cell
* RTLIL::Module::addDlatch(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_en
, const RTLIL::SigSpec
&sig_d
, const RTLIL::SigSpec
&sig_q
, bool en_polarity
, const std::string
&src
)
2227 RTLIL::Cell
*cell
= addCell(name
, ID($dlatch
));
2228 cell
->parameters
[ID(EN_POLARITY
)] = en_polarity
;
2229 cell
->parameters
[ID(WIDTH
)] = sig_q
.size();
2230 cell
->setPort(ID(EN
), sig_en
);
2231 cell
->setPort(ID(D
), sig_d
);
2232 cell
->setPort(ID(Q
), sig_q
);
2233 cell
->set_src_attribute(src
);
2237 RTLIL::Cell
* RTLIL::Module::addDlatchsr(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_en
, const RTLIL::SigSpec
&sig_set
, const RTLIL::SigSpec
&sig_clr
,
2238 RTLIL::SigSpec sig_d
, const RTLIL::SigSpec
&sig_q
, bool en_polarity
, bool set_polarity
, bool clr_polarity
, const std::string
&src
)
2240 RTLIL::Cell
*cell
= addCell(name
, ID($dlatchsr
));
2241 cell
->parameters
[ID(EN_POLARITY
)] = en_polarity
;
2242 cell
->parameters
[ID(SET_POLARITY
)] = set_polarity
;
2243 cell
->parameters
[ID(CLR_POLARITY
)] = clr_polarity
;
2244 cell
->parameters
[ID(WIDTH
)] = sig_q
.size();
2245 cell
->setPort(ID(EN
), sig_en
);
2246 cell
->setPort(ID(SET
), sig_set
);
2247 cell
->setPort(ID(CLR
), sig_clr
);
2248 cell
->setPort(ID(D
), sig_d
);
2249 cell
->setPort(ID(Q
), sig_q
);
2250 cell
->set_src_attribute(src
);
2254 RTLIL::Cell
* RTLIL::Module::addFfGate(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_d
, const RTLIL::SigSpec
&sig_q
, const std::string
&src
)
2256 RTLIL::Cell
*cell
= addCell(name
, ID($_FF_
));
2257 cell
->setPort(ID(D
), sig_d
);
2258 cell
->setPort(ID(Q
), sig_q
);
2259 cell
->set_src_attribute(src
);
2263 RTLIL::Cell
* RTLIL::Module::addDffGate(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_clk
, const RTLIL::SigSpec
&sig_d
, const RTLIL::SigSpec
&sig_q
, bool clk_polarity
, const std::string
&src
)
2265 RTLIL::Cell
*cell
= addCell(name
, stringf("$_DFF_%c_", clk_polarity
? 'P' : 'N'));
2266 cell
->setPort(ID(C
), sig_clk
);
2267 cell
->setPort(ID(D
), sig_d
);
2268 cell
->setPort(ID(Q
), sig_q
);
2269 cell
->set_src_attribute(src
);
2273 RTLIL::Cell
* RTLIL::Module::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
, bool en_polarity
, const std::string
&src
)
2275 RTLIL::Cell
*cell
= addCell(name
, stringf("$_DFFE_%c%c_", clk_polarity
? 'P' : 'N', en_polarity
? 'P' : 'N'));
2276 cell
->setPort(ID(C
), sig_clk
);
2277 cell
->setPort(ID(E
), sig_en
);
2278 cell
->setPort(ID(D
), sig_d
);
2279 cell
->setPort(ID(Q
), sig_q
);
2280 cell
->set_src_attribute(src
);
2284 RTLIL::Cell
* RTLIL::Module::addDffsrGate(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_clk
, const RTLIL::SigSpec
&sig_set
, const RTLIL::SigSpec
&sig_clr
,
2285 RTLIL::SigSpec sig_d
, const RTLIL::SigSpec
&sig_q
, bool clk_polarity
, bool set_polarity
, bool clr_polarity
, const std::string
&src
)
2287 RTLIL::Cell
*cell
= addCell(name
, stringf("$_DFFSR_%c%c%c_", clk_polarity
? 'P' : 'N', set_polarity
? 'P' : 'N', clr_polarity
? 'P' : 'N'));
2288 cell
->setPort(ID(C
), sig_clk
);
2289 cell
->setPort(ID(S
), sig_set
);
2290 cell
->setPort(ID(R
), sig_clr
);
2291 cell
->setPort(ID(D
), sig_d
);
2292 cell
->setPort(ID(Q
), sig_q
);
2293 cell
->set_src_attribute(src
);
2297 RTLIL::Cell
* RTLIL::Module::addAdffGate(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_clk
, const RTLIL::SigSpec
&sig_arst
, const RTLIL::SigSpec
&sig_d
, const RTLIL::SigSpec
&sig_q
,
2298 bool arst_value
, bool clk_polarity
, bool arst_polarity
, const std::string
&src
)
2300 RTLIL::Cell
*cell
= addCell(name
, stringf("$_DFF_%c%c%c_", clk_polarity
? 'P' : 'N', arst_polarity
? 'P' : 'N', arst_value
? '1' : '0'));
2301 cell
->setPort(ID(C
), sig_clk
);
2302 cell
->setPort(ID(R
), sig_arst
);
2303 cell
->setPort(ID(D
), sig_d
);
2304 cell
->setPort(ID(Q
), sig_q
);
2305 cell
->set_src_attribute(src
);
2309 RTLIL::Cell
* RTLIL::Module::addDlatchGate(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_en
, const RTLIL::SigSpec
&sig_d
, const RTLIL::SigSpec
&sig_q
, bool en_polarity
, const std::string
&src
)
2311 RTLIL::Cell
*cell
= addCell(name
, stringf("$_DLATCH_%c_", en_polarity
? 'P' : 'N'));
2312 cell
->setPort(ID(E
), sig_en
);
2313 cell
->setPort(ID(D
), sig_d
);
2314 cell
->setPort(ID(Q
), sig_q
);
2315 cell
->set_src_attribute(src
);
2319 RTLIL::Cell
* RTLIL::Module::addDlatchsrGate(RTLIL::IdString name
, const RTLIL::SigSpec
&sig_en
, const RTLIL::SigSpec
&sig_set
, const RTLIL::SigSpec
&sig_clr
,
2320 RTLIL::SigSpec sig_d
, const RTLIL::SigSpec
&sig_q
, bool en_polarity
, bool set_polarity
, bool clr_polarity
, const std::string
&src
)
2322 RTLIL::Cell
*cell
= addCell(name
, stringf("$_DLATCHSR_%c%c%c_", en_polarity
? 'P' : 'N', set_polarity
? 'P' : 'N', clr_polarity
? 'P' : 'N'));
2323 cell
->setPort(ID(E
), sig_en
);
2324 cell
->setPort(ID(S
), sig_set
);
2325 cell
->setPort(ID(R
), sig_clr
);
2326 cell
->setPort(ID(D
), sig_d
);
2327 cell
->setPort(ID(Q
), sig_q
);
2328 cell
->set_src_attribute(src
);
2332 RTLIL::SigSpec
RTLIL::Module::Anyconst(RTLIL::IdString name
, int width
, const std::string
&src
)
2334 RTLIL::SigSpec sig
= addWire(NEW_ID
, width
);
2335 Cell
*cell
= addCell(name
, ID($anyconst
));
2336 cell
->setParam(ID(WIDTH
), width
);
2337 cell
->setPort(ID::Y
, sig
);
2338 cell
->set_src_attribute(src
);
2342 RTLIL::SigSpec
RTLIL::Module::Anyseq(RTLIL::IdString name
, int width
, const std::string
&src
)
2344 RTLIL::SigSpec sig
= addWire(NEW_ID
, width
);
2345 Cell
*cell
= addCell(name
, ID($anyseq
));
2346 cell
->setParam(ID(WIDTH
), width
);
2347 cell
->setPort(ID::Y
, sig
);
2348 cell
->set_src_attribute(src
);
2352 RTLIL::SigSpec
RTLIL::Module::Allconst(RTLIL::IdString name
, int width
, const std::string
&src
)
2354 RTLIL::SigSpec sig
= addWire(NEW_ID
, width
);
2355 Cell
*cell
= addCell(name
, ID($allconst
));
2356 cell
->setParam(ID(WIDTH
), width
);
2357 cell
->setPort(ID::Y
, sig
);
2358 cell
->set_src_attribute(src
);
2362 RTLIL::SigSpec
RTLIL::Module::Allseq(RTLIL::IdString name
, int width
, const std::string
&src
)
2364 RTLIL::SigSpec sig
= addWire(NEW_ID
, width
);
2365 Cell
*cell
= addCell(name
, ID($allseq
));
2366 cell
->setParam(ID(WIDTH
), width
);
2367 cell
->setPort(ID::Y
, sig
);
2368 cell
->set_src_attribute(src
);
2372 RTLIL::SigSpec
RTLIL::Module::Initstate(RTLIL::IdString name
, const std::string
&src
)
2374 RTLIL::SigSpec sig
= addWire(NEW_ID
);
2375 Cell
*cell
= addCell(name
, ID($initstate
));
2376 cell
->setPort(ID::Y
, sig
);
2377 cell
->set_src_attribute(src
);
2383 static unsigned int hashidx_count
= 123456789;
2384 hashidx_count
= mkhash_xorshift(hashidx_count
);
2385 hashidx_
= hashidx_count
;
2392 port_output
= false;
2396 RTLIL::Wire::get_all_wires()->insert(std::pair
<unsigned int, RTLIL::Wire
*>(hashidx_
, this));
2400 RTLIL::Wire::~Wire()
2403 RTLIL::Wire::get_all_wires()->erase(hashidx_
);
2408 static std::map
<unsigned int, RTLIL::Wire
*> all_wires
;
2409 std::map
<unsigned int, RTLIL::Wire
*> *RTLIL::Wire::get_all_wires(void)
2415 RTLIL::Memory::Memory()
2417 static unsigned int hashidx_count
= 123456789;
2418 hashidx_count
= mkhash_xorshift(hashidx_count
);
2419 hashidx_
= hashidx_count
;
2425 RTLIL::Memory::get_all_memorys()->insert(std::pair
<unsigned int, RTLIL::Memory
*>(hashidx_
, this));
2429 RTLIL::Cell::Cell() : module(nullptr)
2431 static unsigned int hashidx_count
= 123456789;
2432 hashidx_count
= mkhash_xorshift(hashidx_count
);
2433 hashidx_
= hashidx_count
;
2435 // log("#memtrace# %p\n", this);
2439 RTLIL::Cell::get_all_cells()->insert(std::pair
<unsigned int, RTLIL::Cell
*>(hashidx_
, this));
2443 RTLIL::Cell::~Cell()
2446 RTLIL::Cell::get_all_cells()->erase(hashidx_
);
2451 static std::map
<unsigned int, RTLIL::Cell
*> all_cells
;
2452 std::map
<unsigned int, RTLIL::Cell
*> *RTLIL::Cell::get_all_cells(void)
2458 bool RTLIL::Cell::hasPort(RTLIL::IdString portname
) const
2460 return connections_
.count(portname
) != 0;
2463 void RTLIL::Cell::unsetPort(RTLIL::IdString portname
)
2465 RTLIL::SigSpec signal
;
2466 auto conn_it
= connections_
.find(portname
);
2468 if (conn_it
!= connections_
.end())
2470 for (auto mon
: module
->monitors
)
2471 mon
->notify_connect(this, conn_it
->first
, conn_it
->second
, signal
);
2474 for (auto mon
: module
->design
->monitors
)
2475 mon
->notify_connect(this, conn_it
->first
, conn_it
->second
, signal
);
2478 log("#X# Unconnect %s.%s.%s\n", log_id(this->module
), log_id(this), log_id(portname
));
2479 log_backtrace("-X- ", yosys_xtrace
-1);
2482 connections_
.erase(conn_it
);
2486 void RTLIL::Cell::setPort(RTLIL::IdString portname
, RTLIL::SigSpec signal
)
2488 auto r
= connections_
.insert(portname
);
2489 auto conn_it
= r
.first
;
2490 if (!r
.second
&& conn_it
->second
== signal
)
2493 for (auto mon
: module
->monitors
)
2494 mon
->notify_connect(this, conn_it
->first
, conn_it
->second
, signal
);
2497 for (auto mon
: module
->design
->monitors
)
2498 mon
->notify_connect(this, conn_it
->first
, conn_it
->second
, signal
);
2501 log("#X# Connect %s.%s.%s = %s (%d)\n", log_id(this->module
), log_id(this), log_id(portname
), log_signal(signal
), GetSize(signal
));
2502 log_backtrace("-X- ", yosys_xtrace
-1);
2505 conn_it
->second
= std::move(signal
);
2508 const RTLIL::SigSpec
&RTLIL::Cell::getPort(RTLIL::IdString portname
) const
2510 return connections_
.at(portname
);
2513 const dict
<RTLIL::IdString
, RTLIL::SigSpec
> &RTLIL::Cell::connections() const
2515 return connections_
;
2518 bool RTLIL::Cell::known() const
2520 if (yosys_celltypes
.cell_known(type
))
2522 if (module
&& module
->design
&& module
->design
->module(type
))
2527 bool RTLIL::Cell::input(RTLIL::IdString portname
) const
2529 if (yosys_celltypes
.cell_known(type
))
2530 return yosys_celltypes
.cell_input(type
, portname
);
2531 if (module
&& module
->design
) {
2532 RTLIL::Module
*m
= module
->design
->module(type
);
2533 RTLIL::Wire
*w
= m
? m
->wire(portname
) : nullptr;
2534 return w
&& w
->port_input
;
2539 bool RTLIL::Cell::output(RTLIL::IdString portname
) const
2541 if (yosys_celltypes
.cell_known(type
))
2542 return yosys_celltypes
.cell_output(type
, portname
);
2543 if (module
&& module
->design
) {
2544 RTLIL::Module
*m
= module
->design
->module(type
);
2545 RTLIL::Wire
*w
= m
? m
->wire(portname
) : nullptr;
2546 return w
&& w
->port_output
;
2551 bool RTLIL::Cell::hasParam(RTLIL::IdString paramname
) const
2553 return parameters
.count(paramname
) != 0;
2556 void RTLIL::Cell::unsetParam(RTLIL::IdString paramname
)
2558 parameters
.erase(paramname
);
2561 void RTLIL::Cell::setParam(RTLIL::IdString paramname
, RTLIL::Const value
)
2563 parameters
[paramname
] = std::move(value
);
2566 const RTLIL::Const
&RTLIL::Cell::getParam(RTLIL::IdString paramname
) const
2568 return parameters
.at(paramname
);
2571 void RTLIL::Cell::sort()
2573 connections_
.sort(sort_by_id_str());
2574 parameters
.sort(sort_by_id_str());
2575 attributes
.sort(sort_by_id_str());
2578 void RTLIL::Cell::check()
2581 InternalCellChecker
checker(NULL
, this);
2586 void RTLIL::Cell::fixup_parameters(bool set_a_signed
, bool set_b_signed
)
2588 if (!type
.begins_with("$") || type
.begins_with("$_") || type
.begins_with("$paramod") || type
.begins_with("$fmcombine") ||
2589 type
.begins_with("$verific$") || type
.begins_with("$array:") || type
.begins_with("$extern:"))
2592 if (type
== ID($mux
) || type
== ID($pmux
)) {
2593 parameters
[ID(WIDTH
)] = GetSize(connections_
[ID::Y
]);
2594 if (type
== ID($pmux
))
2595 parameters
[ID(S_WIDTH
)] = GetSize(connections_
[ID(S
)]);
2600 if (type
== ID($lut
) || type
== ID($sop
)) {
2601 parameters
[ID(WIDTH
)] = GetSize(connections_
[ID::A
]);
2605 if (type
== ID($fa
)) {
2606 parameters
[ID(WIDTH
)] = GetSize(connections_
[ID::Y
]);
2610 if (type
== ID($lcu
)) {
2611 parameters
[ID(WIDTH
)] = GetSize(connections_
[ID(CO
)]);
2615 bool signedness_ab
= !type
.in(ID($slice
), ID($concat
), ID($macc
));
2617 if (connections_
.count(ID::A
)) {
2618 if (signedness_ab
) {
2620 parameters
[ID(A_SIGNED
)] = true;
2621 else if (parameters
.count(ID(A_SIGNED
)) == 0)
2622 parameters
[ID(A_SIGNED
)] = false;
2624 parameters
[ID(A_WIDTH
)] = GetSize(connections_
[ID::A
]);
2627 if (connections_
.count(ID::B
)) {
2628 if (signedness_ab
) {
2630 parameters
[ID(B_SIGNED
)] = true;
2631 else if (parameters
.count(ID(B_SIGNED
)) == 0)
2632 parameters
[ID(B_SIGNED
)] = false;
2634 parameters
[ID(B_WIDTH
)] = GetSize(connections_
[ID::B
]);
2637 if (connections_
.count(ID::Y
))
2638 parameters
[ID(Y_WIDTH
)] = GetSize(connections_
[ID::Y
]);
2640 if (connections_
.count(ID(Q
)))
2641 parameters
[ID(WIDTH
)] = GetSize(connections_
[ID(Q
)]);
2646 RTLIL::SigChunk::SigChunk()
2653 RTLIL::SigChunk::SigChunk(const RTLIL::Const
&value
)
2657 width
= GetSize(data
);
2661 RTLIL::SigChunk::SigChunk(RTLIL::Wire
*wire
)
2663 log_assert(wire
!= nullptr);
2665 this->width
= wire
->width
;
2669 RTLIL::SigChunk::SigChunk(RTLIL::Wire
*wire
, int offset
, int width
)
2671 log_assert(wire
!= nullptr);
2673 this->width
= width
;
2674 this->offset
= offset
;
2677 RTLIL::SigChunk::SigChunk(const std::string
&str
)
2680 data
= RTLIL::Const(str
).bits
;
2681 width
= GetSize(data
);
2685 RTLIL::SigChunk::SigChunk(int val
, int width
)
2688 data
= RTLIL::Const(val
, width
).bits
;
2689 this->width
= GetSize(data
);
2693 RTLIL::SigChunk::SigChunk(RTLIL::State bit
, int width
)
2696 data
= RTLIL::Const(bit
, width
).bits
;
2697 this->width
= GetSize(data
);
2701 RTLIL::SigChunk::SigChunk(const RTLIL::SigBit
&bit
)
2706 data
= RTLIL::Const(bit
.data
).bits
;
2708 offset
= bit
.offset
;
2712 RTLIL::SigChunk::SigChunk(const RTLIL::SigChunk
&sigchunk
)
2717 RTLIL::SigChunk
RTLIL::SigChunk::extract(int offset
, int length
) const
2719 RTLIL::SigChunk ret
;
2722 ret
.offset
= this->offset
+ offset
;
2725 for (int i
= 0; i
< length
; i
++)
2726 ret
.data
.push_back(data
[offset
+i
]);
2732 bool RTLIL::SigChunk::operator <(const RTLIL::SigChunk
&other
) const
2734 if (wire
&& other
.wire
)
2735 if (wire
->name
!= other
.wire
->name
)
2736 return wire
->name
< other
.wire
->name
;
2738 if (wire
!= other
.wire
)
2739 return wire
< other
.wire
;
2741 if (offset
!= other
.offset
)
2742 return offset
< other
.offset
;
2744 if (width
!= other
.width
)
2745 return width
< other
.width
;
2747 return data
< other
.data
;
2750 bool RTLIL::SigChunk::operator ==(const RTLIL::SigChunk
&other
) const
2752 return wire
== other
.wire
&& width
== other
.width
&& offset
== other
.offset
&& data
== other
.data
;
2755 bool RTLIL::SigChunk::operator !=(const RTLIL::SigChunk
&other
) const
2762 RTLIL::SigSpec::SigSpec()
2768 RTLIL::SigSpec::SigSpec(const RTLIL::SigSpec
&other
)
2773 RTLIL::SigSpec::SigSpec(std::initializer_list
<RTLIL::SigSpec
> parts
)
2775 cover("kernel.rtlil.sigspec.init.list");
2780 log_assert(parts
.size() > 0);
2781 auto ie
= parts
.begin();
2782 auto it
= ie
+ parts
.size() - 1;
2787 RTLIL::SigSpec
&RTLIL::SigSpec::operator=(const RTLIL::SigSpec
&other
)
2789 cover("kernel.rtlil.sigspec.assign");
2791 width_
= other
.width_
;
2792 hash_
= other
.hash_
;
2793 chunks_
= other
.chunks_
;
2794 bits_
= other
.bits_
;
2798 RTLIL::SigSpec::SigSpec(const RTLIL::Const
&value
)
2800 cover("kernel.rtlil.sigspec.init.const");
2802 chunks_
.emplace_back(value
);
2803 width_
= chunks_
.back().width
;
2808 RTLIL::SigSpec::SigSpec(const RTLIL::SigChunk
&chunk
)
2810 cover("kernel.rtlil.sigspec.init.chunk");
2812 chunks_
.emplace_back(chunk
);
2813 width_
= chunks_
.back().width
;
2818 RTLIL::SigSpec::SigSpec(RTLIL::Wire
*wire
)
2820 cover("kernel.rtlil.sigspec.init.wire");
2822 chunks_
.emplace_back(wire
);
2823 width_
= chunks_
.back().width
;
2828 RTLIL::SigSpec::SigSpec(RTLIL::Wire
*wire
, int offset
, int width
)
2830 cover("kernel.rtlil.sigspec.init.wire_part");
2832 chunks_
.emplace_back(wire
, offset
, width
);
2833 width_
= chunks_
.back().width
;
2838 RTLIL::SigSpec::SigSpec(const std::string
&str
)
2840 cover("kernel.rtlil.sigspec.init.str");
2842 chunks_
.emplace_back(str
);
2843 width_
= chunks_
.back().width
;
2848 RTLIL::SigSpec::SigSpec(int val
, int width
)
2850 cover("kernel.rtlil.sigspec.init.int");
2852 chunks_
.emplace_back(val
, width
);
2858 RTLIL::SigSpec::SigSpec(RTLIL::State bit
, int width
)
2860 cover("kernel.rtlil.sigspec.init.state");
2862 chunks_
.emplace_back(bit
, width
);
2868 RTLIL::SigSpec::SigSpec(const RTLIL::SigBit
&bit
, int width
)
2870 cover("kernel.rtlil.sigspec.init.bit");
2872 if (bit
.wire
== NULL
)
2873 chunks_
.emplace_back(bit
.data
, width
);
2875 for (int i
= 0; i
< width
; i
++)
2876 chunks_
.push_back(bit
);
2882 RTLIL::SigSpec::SigSpec(const std::vector
<RTLIL::SigChunk
> &chunks
)
2884 cover("kernel.rtlil.sigspec.init.stdvec_chunks");
2888 for (const auto &c
: chunks
)
2893 RTLIL::SigSpec::SigSpec(const std::vector
<RTLIL::SigBit
> &bits
)
2895 cover("kernel.rtlil.sigspec.init.stdvec_bits");
2899 for (const auto &bit
: bits
)
2904 RTLIL::SigSpec::SigSpec(const pool
<RTLIL::SigBit
> &bits
)
2906 cover("kernel.rtlil.sigspec.init.pool_bits");
2910 for (const auto &bit
: bits
)
2915 RTLIL::SigSpec::SigSpec(const std::set
<RTLIL::SigBit
> &bits
)
2917 cover("kernel.rtlil.sigspec.init.stdset_bits");
2921 for (const auto &bit
: bits
)
2926 RTLIL::SigSpec::SigSpec(bool bit
)
2928 cover("kernel.rtlil.sigspec.init.bool");
2932 append(SigBit(bit
));
2936 void RTLIL::SigSpec::pack() const
2938 RTLIL::SigSpec
*that
= (RTLIL::SigSpec
*)this;
2940 if (that
->bits_
.empty())
2943 cover("kernel.rtlil.sigspec.convert.pack");
2944 log_assert(that
->chunks_
.empty());
2946 std::vector
<RTLIL::SigBit
> old_bits
;
2947 old_bits
.swap(that
->bits_
);
2949 RTLIL::SigChunk
*last
= NULL
;
2950 int last_end_offset
= 0;
2952 for (auto &bit
: old_bits
) {
2953 if (last
&& bit
.wire
== last
->wire
) {
2954 if (bit
.wire
== NULL
) {
2955 last
->data
.push_back(bit
.data
);
2958 } else if (last_end_offset
== bit
.offset
) {
2964 that
->chunks_
.push_back(bit
);
2965 last
= &that
->chunks_
.back();
2966 last_end_offset
= bit
.offset
+ 1;
2972 void RTLIL::SigSpec::unpack() const
2974 RTLIL::SigSpec
*that
= (RTLIL::SigSpec
*)this;
2976 if (that
->chunks_
.empty())
2979 cover("kernel.rtlil.sigspec.convert.unpack");
2980 log_assert(that
->bits_
.empty());
2982 that
->bits_
.reserve(that
->width_
);
2983 for (auto &c
: that
->chunks_
)
2984 for (int i
= 0; i
< c
.width
; i
++)
2985 that
->bits_
.emplace_back(c
, i
);
2987 that
->chunks_
.clear();
2991 void RTLIL::SigSpec::updhash() const
2993 RTLIL::SigSpec
*that
= (RTLIL::SigSpec
*)this;
2995 if (that
->hash_
!= 0)
2998 cover("kernel.rtlil.sigspec.hash");
3001 that
->hash_
= mkhash_init
;
3002 for (auto &c
: that
->chunks_
)
3003 if (c
.wire
== NULL
) {
3004 for (auto &v
: c
.data
)
3005 that
->hash_
= mkhash(that
->hash_
, v
);
3007 that
->hash_
= mkhash(that
->hash_
, c
.wire
->name
.index_
);
3008 that
->hash_
= mkhash(that
->hash_
, c
.offset
);
3009 that
->hash_
= mkhash(that
->hash_
, c
.width
);
3012 if (that
->hash_
== 0)
3016 void RTLIL::SigSpec::sort()
3019 cover("kernel.rtlil.sigspec.sort");
3020 std::sort(bits_
.begin(), bits_
.end());
3023 void RTLIL::SigSpec::sort_and_unify()
3026 cover("kernel.rtlil.sigspec.sort_and_unify");
3028 // A copy of the bits vector is used to prevent duplicating the logic from
3029 // SigSpec::SigSpec(std::vector<SigBit>). This incurrs an extra copy but
3030 // that isn't showing up as significant in profiles.
3031 std::vector
<SigBit
> unique_bits
= bits_
;
3032 std::sort(unique_bits
.begin(), unique_bits
.end());
3033 auto last
= std::unique(unique_bits
.begin(), unique_bits
.end());
3034 unique_bits
.erase(last
, unique_bits
.end());
3036 *this = unique_bits
;
3039 void RTLIL::SigSpec::replace(const RTLIL::SigSpec
&pattern
, const RTLIL::SigSpec
&with
)
3041 replace(pattern
, with
, this);
3044 void RTLIL::SigSpec::replace(const RTLIL::SigSpec
&pattern
, const RTLIL::SigSpec
&with
, RTLIL::SigSpec
*other
) const
3046 log_assert(other
!= NULL
);
3047 log_assert(width_
== other
->width_
);
3048 log_assert(pattern
.width_
== with
.width_
);
3055 for (int i
= 0; i
< GetSize(pattern
.bits_
); i
++) {
3056 if (pattern
.bits_
[i
].wire
!= NULL
) {
3057 for (int j
= 0; j
< GetSize(bits_
); j
++) {
3058 if (bits_
[j
] == pattern
.bits_
[i
]) {
3059 other
->bits_
[j
] = with
.bits_
[i
];
3068 void RTLIL::SigSpec::replace(const dict
<RTLIL::SigBit
, RTLIL::SigBit
> &rules
)
3070 replace(rules
, this);
3073 void RTLIL::SigSpec::replace(const dict
<RTLIL::SigBit
, RTLIL::SigBit
> &rules
, RTLIL::SigSpec
*other
) const
3075 cover("kernel.rtlil.sigspec.replace_dict");
3077 log_assert(other
!= NULL
);
3078 log_assert(width_
== other
->width_
);
3080 if (rules
.empty()) return;
3084 for (int i
= 0; i
< GetSize(bits_
); i
++) {
3085 auto it
= rules
.find(bits_
[i
]);
3086 if (it
!= rules
.end())
3087 other
->bits_
[i
] = it
->second
;
3093 void RTLIL::SigSpec::replace(const std::map
<RTLIL::SigBit
, RTLIL::SigBit
> &rules
)
3095 replace(rules
, this);
3098 void RTLIL::SigSpec::replace(const std::map
<RTLIL::SigBit
, RTLIL::SigBit
> &rules
, RTLIL::SigSpec
*other
) const
3100 cover("kernel.rtlil.sigspec.replace_map");
3102 log_assert(other
!= NULL
);
3103 log_assert(width_
== other
->width_
);
3105 if (rules
.empty()) return;
3109 for (int i
= 0; i
< GetSize(bits_
); i
++) {
3110 auto it
= rules
.find(bits_
[i
]);
3111 if (it
!= rules
.end())
3112 other
->bits_
[i
] = it
->second
;
3118 void RTLIL::SigSpec::remove(const RTLIL::SigSpec
&pattern
)
3120 remove2(pattern
, NULL
);
3123 void RTLIL::SigSpec::remove(const RTLIL::SigSpec
&pattern
, RTLIL::SigSpec
*other
) const
3125 RTLIL::SigSpec tmp
= *this;
3126 tmp
.remove2(pattern
, other
);
3129 void RTLIL::SigSpec::remove2(const RTLIL::SigSpec
&pattern
, RTLIL::SigSpec
*other
)
3132 cover("kernel.rtlil.sigspec.remove_other");
3134 cover("kernel.rtlil.sigspec.remove");
3137 if (other
!= NULL
) {
3138 log_assert(width_
== other
->width_
);
3142 for (int i
= GetSize(bits_
) - 1; i
>= 0; i
--)
3144 if (bits_
[i
].wire
== NULL
) continue;
3146 for (auto &pattern_chunk
: pattern
.chunks())
3147 if (bits_
[i
].wire
== pattern_chunk
.wire
&&
3148 bits_
[i
].offset
>= pattern_chunk
.offset
&&
3149 bits_
[i
].offset
< pattern_chunk
.offset
+ pattern_chunk
.width
) {
3150 bits_
.erase(bits_
.begin() + i
);
3152 if (other
!= NULL
) {
3153 other
->bits_
.erase(other
->bits_
.begin() + i
);
3163 void RTLIL::SigSpec::remove(const pool
<RTLIL::SigBit
> &pattern
)
3165 remove2(pattern
, NULL
);
3168 void RTLIL::SigSpec::remove(const pool
<RTLIL::SigBit
> &pattern
, RTLIL::SigSpec
*other
) const
3170 RTLIL::SigSpec tmp
= *this;
3171 tmp
.remove2(pattern
, other
);
3174 void RTLIL::SigSpec::remove2(const pool
<RTLIL::SigBit
> &pattern
, RTLIL::SigSpec
*other
)
3177 cover("kernel.rtlil.sigspec.remove_other");
3179 cover("kernel.rtlil.sigspec.remove");
3183 if (other
!= NULL
) {
3184 log_assert(width_
== other
->width_
);
3188 for (int i
= GetSize(bits_
) - 1; i
>= 0; i
--) {
3189 if (bits_
[i
].wire
!= NULL
&& pattern
.count(bits_
[i
])) {
3190 bits_
.erase(bits_
.begin() + i
);
3192 if (other
!= NULL
) {
3193 other
->bits_
.erase(other
->bits_
.begin() + i
);
3202 void RTLIL::SigSpec::remove2(const std::set
<RTLIL::SigBit
> &pattern
, RTLIL::SigSpec
*other
)
3205 cover("kernel.rtlil.sigspec.remove_other");
3207 cover("kernel.rtlil.sigspec.remove");
3211 if (other
!= NULL
) {
3212 log_assert(width_
== other
->width_
);
3216 for (int i
= GetSize(bits_
) - 1; i
>= 0; i
--) {
3217 if (bits_
[i
].wire
!= NULL
&& pattern
.count(bits_
[i
])) {
3218 bits_
.erase(bits_
.begin() + i
);
3220 if (other
!= NULL
) {
3221 other
->bits_
.erase(other
->bits_
.begin() + i
);
3230 RTLIL::SigSpec
RTLIL::SigSpec::extract(const RTLIL::SigSpec
&pattern
, const RTLIL::SigSpec
*other
) const
3233 cover("kernel.rtlil.sigspec.extract_other");
3235 cover("kernel.rtlil.sigspec.extract");
3237 log_assert(other
== NULL
|| width_
== other
->width_
);
3240 std::vector
<RTLIL::SigBit
> bits_match
= to_sigbit_vector();
3242 for (auto& pattern_chunk
: pattern
.chunks()) {
3244 std::vector
<RTLIL::SigBit
> bits_other
= other
->to_sigbit_vector();
3245 for (int i
= 0; i
< width_
; i
++)
3246 if (bits_match
[i
].wire
&&
3247 bits_match
[i
].wire
== pattern_chunk
.wire
&&
3248 bits_match
[i
].offset
>= pattern_chunk
.offset
&&
3249 bits_match
[i
].offset
< pattern_chunk
.offset
+ pattern_chunk
.width
)
3250 ret
.append(bits_other
[i
]);
3252 for (int i
= 0; i
< width_
; i
++)
3253 if (bits_match
[i
].wire
&&
3254 bits_match
[i
].wire
== pattern_chunk
.wire
&&
3255 bits_match
[i
].offset
>= pattern_chunk
.offset
&&
3256 bits_match
[i
].offset
< pattern_chunk
.offset
+ pattern_chunk
.width
)
3257 ret
.append(bits_match
[i
]);
3265 RTLIL::SigSpec
RTLIL::SigSpec::extract(const pool
<RTLIL::SigBit
> &pattern
, const RTLIL::SigSpec
*other
) const
3268 cover("kernel.rtlil.sigspec.extract_other");
3270 cover("kernel.rtlil.sigspec.extract");
3272 log_assert(other
== NULL
|| width_
== other
->width_
);
3274 std::vector
<RTLIL::SigBit
> bits_match
= to_sigbit_vector();
3278 std::vector
<RTLIL::SigBit
> bits_other
= other
->to_sigbit_vector();
3279 for (int i
= 0; i
< width_
; i
++)
3280 if (bits_match
[i
].wire
&& pattern
.count(bits_match
[i
]))
3281 ret
.append(bits_other
[i
]);
3283 for (int i
= 0; i
< width_
; i
++)
3284 if (bits_match
[i
].wire
&& pattern
.count(bits_match
[i
]))
3285 ret
.append(bits_match
[i
]);
3292 void RTLIL::SigSpec::replace(int offset
, const RTLIL::SigSpec
&with
)
3294 cover("kernel.rtlil.sigspec.replace_pos");
3299 log_assert(offset
>= 0);
3300 log_assert(with
.width_
>= 0);
3301 log_assert(offset
+with
.width_
<= width_
);
3303 for (int i
= 0; i
< with
.width_
; i
++)
3304 bits_
.at(offset
+ i
) = with
.bits_
.at(i
);
3309 void RTLIL::SigSpec::remove_const()
3313 cover("kernel.rtlil.sigspec.remove_const.packed");
3315 std::vector
<RTLIL::SigChunk
> new_chunks
;
3316 new_chunks
.reserve(GetSize(chunks_
));
3319 for (auto &chunk
: chunks_
)
3320 if (chunk
.wire
!= NULL
) {
3321 new_chunks
.push_back(chunk
);
3322 width_
+= chunk
.width
;
3325 chunks_
.swap(new_chunks
);
3329 cover("kernel.rtlil.sigspec.remove_const.unpacked");
3331 std::vector
<RTLIL::SigBit
> new_bits
;
3332 new_bits
.reserve(width_
);
3334 for (auto &bit
: bits_
)
3335 if (bit
.wire
!= NULL
)
3336 new_bits
.push_back(bit
);
3338 bits_
.swap(new_bits
);
3339 width_
= bits_
.size();
3345 void RTLIL::SigSpec::remove(int offset
, int length
)
3347 cover("kernel.rtlil.sigspec.remove_pos");
3351 log_assert(offset
>= 0);
3352 log_assert(length
>= 0);
3353 log_assert(offset
+ length
<= width_
);
3355 bits_
.erase(bits_
.begin() + offset
, bits_
.begin() + offset
+ length
);
3356 width_
= bits_
.size();
3361 RTLIL::SigSpec
RTLIL::SigSpec::extract(int offset
, int length
) const
3364 cover("kernel.rtlil.sigspec.extract_pos");
3365 return std::vector
<RTLIL::SigBit
>(bits_
.begin() + offset
, bits_
.begin() + offset
+ length
);
3368 void RTLIL::SigSpec::append(const RTLIL::SigSpec
&signal
)
3370 if (signal
.width_
== 0)
3378 cover("kernel.rtlil.sigspec.append");
3380 if (packed() != signal
.packed()) {
3386 for (auto &other_c
: signal
.chunks_
)
3388 auto &my_last_c
= chunks_
.back();
3389 if (my_last_c
.wire
== NULL
&& other_c
.wire
== NULL
) {
3390 auto &this_data
= my_last_c
.data
;
3391 auto &other_data
= other_c
.data
;
3392 this_data
.insert(this_data
.end(), other_data
.begin(), other_data
.end());
3393 my_last_c
.width
+= other_c
.width
;
3395 if (my_last_c
.wire
== other_c
.wire
&& my_last_c
.offset
+ my_last_c
.width
== other_c
.offset
) {
3396 my_last_c
.width
+= other_c
.width
;
3398 chunks_
.push_back(other_c
);
3401 bits_
.insert(bits_
.end(), signal
.bits_
.begin(), signal
.bits_
.end());
3403 width_
+= signal
.width_
;
3407 void RTLIL::SigSpec::append(const RTLIL::SigBit
&bit
)
3411 cover("kernel.rtlil.sigspec.append_bit.packed");
3413 if (chunks_
.size() == 0)
3414 chunks_
.push_back(bit
);
3416 if (bit
.wire
== NULL
)
3417 if (chunks_
.back().wire
== NULL
) {
3418 chunks_
.back().data
.push_back(bit
.data
);
3419 chunks_
.back().width
++;
3421 chunks_
.push_back(bit
);
3423 if (chunks_
.back().wire
== bit
.wire
&& chunks_
.back().offset
+ chunks_
.back().width
== bit
.offset
)
3424 chunks_
.back().width
++;
3426 chunks_
.push_back(bit
);
3430 cover("kernel.rtlil.sigspec.append_bit.unpacked");
3431 bits_
.push_back(bit
);
3438 void RTLIL::SigSpec::extend_u0(int width
, bool is_signed
)
3440 cover("kernel.rtlil.sigspec.extend_u0");
3445 remove(width
, width_
- width
);
3447 if (width_
< width
) {
3448 RTLIL::SigBit padding
= width_
> 0 ? (*this)[width_
- 1] : RTLIL::State::Sx
;
3450 padding
= RTLIL::State::S0
;
3451 while (width_
< width
)
3457 RTLIL::SigSpec
RTLIL::SigSpec::repeat(int num
) const
3459 cover("kernel.rtlil.sigspec.repeat");
3462 for (int i
= 0; i
< num
; i
++)
3468 void RTLIL::SigSpec::check() const
3472 cover("kernel.rtlil.sigspec.check.skip");
3476 cover("kernel.rtlil.sigspec.check.packed");
3479 for (size_t i
= 0; i
< chunks_
.size(); i
++) {
3480 const RTLIL::SigChunk
&chunk
= chunks_
[i
];
3481 if (chunk
.wire
== NULL
) {
3483 log_assert(chunks_
[i
-1].wire
!= NULL
);
3484 log_assert(chunk
.offset
== 0);
3485 log_assert(chunk
.data
.size() == (size_t)chunk
.width
);
3487 if (i
> 0 && chunks_
[i
-1].wire
== chunk
.wire
)
3488 log_assert(chunk
.offset
!= chunks_
[i
-1].offset
+ chunks_
[i
-1].width
);
3489 log_assert(chunk
.offset
>= 0);
3490 log_assert(chunk
.width
>= 0);
3491 log_assert(chunk
.offset
+ chunk
.width
<= chunk
.wire
->width
);
3492 log_assert(chunk
.data
.size() == 0);
3496 log_assert(w
== width_
);
3497 log_assert(bits_
.empty());
3501 cover("kernel.rtlil.sigspec.check.unpacked");
3503 log_assert(width_
== GetSize(bits_
));
3504 log_assert(chunks_
.empty());
3509 bool RTLIL::SigSpec::operator <(const RTLIL::SigSpec
&other
) const
3511 cover("kernel.rtlil.sigspec.comp_lt");
3516 if (width_
!= other
.width_
)
3517 return width_
< other
.width_
;
3522 if (chunks_
.size() != other
.chunks_
.size())
3523 return chunks_
.size() < other
.chunks_
.size();
3528 if (hash_
!= other
.hash_
)
3529 return hash_
< other
.hash_
;
3531 for (size_t i
= 0; i
< chunks_
.size(); i
++)
3532 if (chunks_
[i
] != other
.chunks_
[i
]) {
3533 cover("kernel.rtlil.sigspec.comp_lt.hash_collision");
3534 return chunks_
[i
] < other
.chunks_
[i
];
3537 cover("kernel.rtlil.sigspec.comp_lt.equal");
3541 bool RTLIL::SigSpec::operator ==(const RTLIL::SigSpec
&other
) const
3543 cover("kernel.rtlil.sigspec.comp_eq");
3548 if (width_
!= other
.width_
)
3551 // Without this, SigSpec() == SigSpec(State::S0, 0) will fail
3552 // since the RHS will contain one SigChunk of width 0 causing
3553 // the size check below to fail
3560 if (chunks_
.size() != other
.chunks_
.size())
3566 if (hash_
!= other
.hash_
)
3569 for (size_t i
= 0; i
< chunks_
.size(); i
++)
3570 if (chunks_
[i
] != other
.chunks_
[i
]) {
3571 cover("kernel.rtlil.sigspec.comp_eq.hash_collision");
3575 cover("kernel.rtlil.sigspec.comp_eq.equal");
3579 bool RTLIL::SigSpec::is_wire() const
3581 cover("kernel.rtlil.sigspec.is_wire");
3584 return GetSize(chunks_
) == 1 && chunks_
[0].wire
&& chunks_
[0].wire
->width
== width_
;
3587 bool RTLIL::SigSpec::is_chunk() const
3589 cover("kernel.rtlil.sigspec.is_chunk");
3592 return GetSize(chunks_
) == 1;
3595 bool RTLIL::SigSpec::is_fully_const() const
3597 cover("kernel.rtlil.sigspec.is_fully_const");
3600 for (auto it
= chunks_
.begin(); it
!= chunks_
.end(); it
++)
3601 if (it
->width
> 0 && it
->wire
!= NULL
)
3606 bool RTLIL::SigSpec::is_fully_zero() const
3608 cover("kernel.rtlil.sigspec.is_fully_zero");
3611 for (auto it
= chunks_
.begin(); it
!= chunks_
.end(); it
++) {
3612 if (it
->width
> 0 && it
->wire
!= NULL
)
3614 for (size_t i
= 0; i
< it
->data
.size(); i
++)
3615 if (it
->data
[i
] != RTLIL::State::S0
)
3621 bool RTLIL::SigSpec::is_fully_ones() const
3623 cover("kernel.rtlil.sigspec.is_fully_ones");
3626 for (auto it
= chunks_
.begin(); it
!= chunks_
.end(); it
++) {
3627 if (it
->width
> 0 && it
->wire
!= NULL
)
3629 for (size_t i
= 0; i
< it
->data
.size(); i
++)
3630 if (it
->data
[i
] != RTLIL::State::S1
)
3636 bool RTLIL::SigSpec::is_fully_def() const
3638 cover("kernel.rtlil.sigspec.is_fully_def");
3641 for (auto it
= chunks_
.begin(); it
!= chunks_
.end(); it
++) {
3642 if (it
->width
> 0 && it
->wire
!= NULL
)
3644 for (size_t i
= 0; i
< it
->data
.size(); i
++)
3645 if (it
->data
[i
] != RTLIL::State::S0
&& it
->data
[i
] != RTLIL::State::S1
)
3651 bool RTLIL::SigSpec::is_fully_undef() const
3653 cover("kernel.rtlil.sigspec.is_fully_undef");
3656 for (auto it
= chunks_
.begin(); it
!= chunks_
.end(); it
++) {
3657 if (it
->width
> 0 && it
->wire
!= NULL
)
3659 for (size_t i
= 0; i
< it
->data
.size(); i
++)
3660 if (it
->data
[i
] != RTLIL::State::Sx
&& it
->data
[i
] != RTLIL::State::Sz
)
3666 bool RTLIL::SigSpec::has_const() const
3668 cover("kernel.rtlil.sigspec.has_const");
3671 for (auto it
= chunks_
.begin(); it
!= chunks_
.end(); it
++)
3672 if (it
->width
> 0 && it
->wire
== NULL
)
3677 bool RTLIL::SigSpec::has_marked_bits() const
3679 cover("kernel.rtlil.sigspec.has_marked_bits");
3682 for (auto it
= chunks_
.begin(); it
!= chunks_
.end(); it
++)
3683 if (it
->width
> 0 && it
->wire
== NULL
) {
3684 for (size_t i
= 0; i
< it
->data
.size(); i
++)
3685 if (it
->data
[i
] == RTLIL::State::Sm
)
3691 bool RTLIL::SigSpec::as_bool() const
3693 cover("kernel.rtlil.sigspec.as_bool");
3696 log_assert(is_fully_const() && GetSize(chunks_
) <= 1);
3698 return RTLIL::Const(chunks_
[0].data
).as_bool();
3702 int RTLIL::SigSpec::as_int(bool is_signed
) const
3704 cover("kernel.rtlil.sigspec.as_int");
3707 log_assert(is_fully_const() && GetSize(chunks_
) <= 1);
3709 return RTLIL::Const(chunks_
[0].data
).as_int(is_signed
);
3713 std::string
RTLIL::SigSpec::as_string() const
3715 cover("kernel.rtlil.sigspec.as_string");
3719 str
.reserve(size());
3720 for (size_t i
= chunks_
.size(); i
> 0; i
--) {
3721 const RTLIL::SigChunk
&chunk
= chunks_
[i
-1];
3722 if (chunk
.wire
!= NULL
)
3723 str
.append(chunk
.width
, '?');
3725 str
+= RTLIL::Const(chunk
.data
).as_string();
3730 RTLIL::Const
RTLIL::SigSpec::as_const() const
3732 cover("kernel.rtlil.sigspec.as_const");
3735 log_assert(is_fully_const() && GetSize(chunks_
) <= 1);
3737 return chunks_
[0].data
;
3738 return RTLIL::Const();
3741 RTLIL::Wire
*RTLIL::SigSpec::as_wire() const
3743 cover("kernel.rtlil.sigspec.as_wire");
3746 log_assert(is_wire());
3747 return chunks_
[0].wire
;
3750 RTLIL::SigChunk
RTLIL::SigSpec::as_chunk() const
3752 cover("kernel.rtlil.sigspec.as_chunk");
3755 log_assert(is_chunk());
3759 RTLIL::SigBit
RTLIL::SigSpec::as_bit() const
3761 cover("kernel.rtlil.sigspec.as_bit");
3763 log_assert(width_
== 1);
3765 return RTLIL::SigBit(*chunks_
.begin());
3770 bool RTLIL::SigSpec::match(const char* pattern
) const
3772 cover("kernel.rtlil.sigspec.match");
3775 log_assert(int(strlen(pattern
)) == GetSize(bits_
));
3777 for (auto it
= bits_
.rbegin(); it
!= bits_
.rend(); it
++, pattern
++) {
3778 if (*pattern
== ' ')
3780 if (*pattern
== '*') {
3781 if (*it
!= State::Sz
&& *it
!= State::Sx
)
3785 if (*pattern
== '0') {
3786 if (*it
!= State::S0
)
3789 if (*pattern
== '1') {
3790 if (*it
!= State::S1
)
3799 std::set
<RTLIL::SigBit
> RTLIL::SigSpec::to_sigbit_set() const
3801 cover("kernel.rtlil.sigspec.to_sigbit_set");
3804 std::set
<RTLIL::SigBit
> sigbits
;
3805 for (auto &c
: chunks_
)
3806 for (int i
= 0; i
< c
.width
; i
++)
3807 sigbits
.insert(RTLIL::SigBit(c
, i
));
3811 pool
<RTLIL::SigBit
> RTLIL::SigSpec::to_sigbit_pool() const
3813 cover("kernel.rtlil.sigspec.to_sigbit_pool");
3816 pool
<RTLIL::SigBit
> sigbits
;
3817 sigbits
.reserve(size());
3818 for (auto &c
: chunks_
)
3819 for (int i
= 0; i
< c
.width
; i
++)
3820 sigbits
.insert(RTLIL::SigBit(c
, i
));
3824 std::vector
<RTLIL::SigBit
> RTLIL::SigSpec::to_sigbit_vector() const
3826 cover("kernel.rtlil.sigspec.to_sigbit_vector");
3832 std::map
<RTLIL::SigBit
, RTLIL::SigBit
> RTLIL::SigSpec::to_sigbit_map(const RTLIL::SigSpec
&other
) const
3834 cover("kernel.rtlil.sigspec.to_sigbit_map");
3839 log_assert(width_
== other
.width_
);
3841 std::map
<RTLIL::SigBit
, RTLIL::SigBit
> new_map
;
3842 for (int i
= 0; i
< width_
; i
++)
3843 new_map
[bits_
[i
]] = other
.bits_
[i
];
3848 dict
<RTLIL::SigBit
, RTLIL::SigBit
> RTLIL::SigSpec::to_sigbit_dict(const RTLIL::SigSpec
&other
) const
3850 cover("kernel.rtlil.sigspec.to_sigbit_dict");
3855 log_assert(width_
== other
.width_
);
3857 dict
<RTLIL::SigBit
, RTLIL::SigBit
> new_map
;
3858 new_map
.reserve(size());
3859 for (int i
= 0; i
< width_
; i
++)
3860 new_map
[bits_
[i
]] = other
.bits_
[i
];
3865 static void sigspec_parse_split(std::vector
<std::string
> &tokens
, const std::string
&text
, char sep
)
3867 size_t start
= 0, end
= 0;
3868 while ((end
= text
.find(sep
, start
)) != std::string::npos
) {
3869 tokens
.push_back(text
.substr(start
, end
- start
));
3872 tokens
.push_back(text
.substr(start
));
3875 static int sigspec_parse_get_dummy_line_num()
3880 bool RTLIL::SigSpec::parse(RTLIL::SigSpec
&sig
, RTLIL::Module
*module
, std::string str
)
3882 cover("kernel.rtlil.sigspec.parse");
3884 AST::current_filename
= "input";
3886 std::vector
<std::string
> tokens
;
3887 sigspec_parse_split(tokens
, str
, ',');
3889 sig
= RTLIL::SigSpec();
3890 for (int tokidx
= int(tokens
.size())-1; tokidx
>= 0; tokidx
--)
3892 std::string netname
= tokens
[tokidx
];
3893 std::string indices
;
3895 if (netname
.size() == 0)
3898 if (('0' <= netname
[0] && netname
[0] <= '9') || netname
[0] == '\'') {
3899 cover("kernel.rtlil.sigspec.parse.const");
3900 AST::get_line_num
= sigspec_parse_get_dummy_line_num
;
3901 AST::AstNode
*ast
= VERILOG_FRONTEND::const2ast(netname
);
3904 sig
.append(RTLIL::Const(ast
->bits
));
3912 cover("kernel.rtlil.sigspec.parse.net");
3914 if (netname
[0] != '$' && netname
[0] != '\\')
3915 netname
= "\\" + netname
;
3917 if (module
->wires_
.count(netname
) == 0) {
3918 size_t indices_pos
= netname
.size()-1;
3919 if (indices_pos
> 2 && netname
[indices_pos
] == ']')
3922 while (indices_pos
> 0 && ('0' <= netname
[indices_pos
] && netname
[indices_pos
] <= '9')) indices_pos
--;
3923 if (indices_pos
> 0 && netname
[indices_pos
] == ':') {
3925 while (indices_pos
> 0 && ('0' <= netname
[indices_pos
] && netname
[indices_pos
] <= '9')) indices_pos
--;
3927 if (indices_pos
> 0 && netname
[indices_pos
] == '[') {
3928 indices
= netname
.substr(indices_pos
);
3929 netname
= netname
.substr(0, indices_pos
);
3934 if (module
->wires_
.count(netname
) == 0)
3937 RTLIL::Wire
*wire
= module
->wires_
.at(netname
);
3938 if (!indices
.empty()) {
3939 std::vector
<std::string
> index_tokens
;
3940 sigspec_parse_split(index_tokens
, indices
.substr(1, indices
.size()-2), ':');
3941 if (index_tokens
.size() == 1) {
3942 cover("kernel.rtlil.sigspec.parse.bit_sel");
3943 int a
= atoi(index_tokens
.at(0).c_str());
3944 if (a
< 0 || a
>= wire
->width
)
3946 sig
.append(RTLIL::SigSpec(wire
, a
));
3948 cover("kernel.rtlil.sigspec.parse.part_sel");
3949 int a
= atoi(index_tokens
.at(0).c_str());
3950 int b
= atoi(index_tokens
.at(1).c_str());
3955 if (a
< 0 || a
>= wire
->width
)
3957 if (b
< 0 || b
>= wire
->width
)
3959 sig
.append(RTLIL::SigSpec(wire
, a
, b
-a
+1));
3968 bool RTLIL::SigSpec::parse_sel(RTLIL::SigSpec
&sig
, RTLIL::Design
*design
, RTLIL::Module
*module
, std::string str
)
3970 if (str
.empty() || str
[0] != '@')
3971 return parse(sig
, module
, str
);
3973 cover("kernel.rtlil.sigspec.parse.sel");
3975 str
= RTLIL::escape_id(str
.substr(1));
3976 if (design
->selection_vars
.count(str
) == 0)
3979 sig
= RTLIL::SigSpec();
3980 RTLIL::Selection
&sel
= design
->selection_vars
.at(str
);
3981 for (auto &it
: module
->wires_
)
3982 if (sel
.selected_member(module
->name
, it
.first
))
3983 sig
.append(it
.second
);
3988 bool RTLIL::SigSpec::parse_rhs(const RTLIL::SigSpec
&lhs
, RTLIL::SigSpec
&sig
, RTLIL::Module
*module
, std::string str
)
3991 cover("kernel.rtlil.sigspec.parse.rhs_zeros");
3992 sig
= RTLIL::SigSpec(RTLIL::State::S0
, lhs
.width_
);
3997 cover("kernel.rtlil.sigspec.parse.rhs_ones");
3998 sig
= RTLIL::SigSpec(RTLIL::State::S1
, lhs
.width_
);
4002 if (lhs
.chunks_
.size() == 1) {
4003 char *p
= (char*)str
.c_str(), *endptr
;
4004 long int val
= strtol(p
, &endptr
, 10);
4005 if (endptr
&& endptr
!= p
&& *endptr
== 0) {
4006 sig
= RTLIL::SigSpec(val
, lhs
.width_
);
4007 cover("kernel.rtlil.sigspec.parse.rhs_dec");
4012 return parse(sig
, module
, str
);
4015 RTLIL::CaseRule::~CaseRule()
4017 for (auto it
= switches
.begin(); it
!= switches
.end(); it
++)
4021 bool RTLIL::CaseRule::empty() const
4023 return actions
.empty() && switches
.empty();
4026 RTLIL::CaseRule
*RTLIL::CaseRule::clone() const
4028 RTLIL::CaseRule
*new_caserule
= new RTLIL::CaseRule
;
4029 new_caserule
->compare
= compare
;
4030 new_caserule
->actions
= actions
;
4031 for (auto &it
: switches
)
4032 new_caserule
->switches
.push_back(it
->clone());
4033 return new_caserule
;
4036 RTLIL::SwitchRule::~SwitchRule()
4038 for (auto it
= cases
.begin(); it
!= cases
.end(); it
++)
4042 bool RTLIL::SwitchRule::empty() const
4044 return cases
.empty();
4047 RTLIL::SwitchRule
*RTLIL::SwitchRule::clone() const
4049 RTLIL::SwitchRule
*new_switchrule
= new RTLIL::SwitchRule
;
4050 new_switchrule
->signal
= signal
;
4051 new_switchrule
->attributes
= attributes
;
4052 for (auto &it
: cases
)
4053 new_switchrule
->cases
.push_back(it
->clone());
4054 return new_switchrule
;
4058 RTLIL::SyncRule
*RTLIL::SyncRule::clone() const
4060 RTLIL::SyncRule
*new_syncrule
= new RTLIL::SyncRule
;
4061 new_syncrule
->type
= type
;
4062 new_syncrule
->signal
= signal
;
4063 new_syncrule
->actions
= actions
;
4064 return new_syncrule
;
4067 RTLIL::Process::~Process()
4069 for (auto it
= syncs
.begin(); it
!= syncs
.end(); it
++)
4073 RTLIL::Process
*RTLIL::Process::clone() const
4075 RTLIL::Process
*new_proc
= new RTLIL::Process
;
4077 new_proc
->name
= name
;
4078 new_proc
->attributes
= attributes
;
4080 RTLIL::CaseRule
*rc_ptr
= root_case
.clone();
4081 new_proc
->root_case
= *rc_ptr
;
4082 rc_ptr
->switches
.clear();
4085 for (auto &it
: syncs
)
4086 new_proc
->syncs
.push_back(it
->clone());
4092 RTLIL::Memory::~Memory()
4094 RTLIL::Memory::get_all_memorys()->erase(hashidx_
);
4096 static std::map
<unsigned int, RTLIL::Memory
*> all_memorys
;
4097 std::map
<unsigned int, RTLIL::Memory
*> *RTLIL::Memory::get_all_memorys(void)
4099 return &all_memorys
;