566 std::string arg_mod, arg_memb;
584 log_cmd_error(
"Must have at least one element on the stack for operator %%n.\n");
589 log_cmd_error(
"Must have at least two elements on the stack for operator %%u.\n");
595 log_cmd_error(
"Must have at least two elements on the stack for operator %%d.\n");
601 log_cmd_error(
"Must have at least two elements on the stack for operator %%d.\n");
604 work_stack.pop_back();
607 if (work_stack.size() < 2)
608 log_cmd_error(
"Must have at least two elements on the stack for operator %%i.\n");
609 select_op_intersect(design, work_stack[work_stack.size()-2], work_stack[work_stack.size()-1]);
610 work_stack.pop_back();
613 if (work_stack.size() < 1)
614 log_cmd_error(
"Must have at least one element on the stack for operator %%s.\n");
618 if (work_stack.size() < 1)
619 log_cmd_error(
"Must have at least one element on the stack for operator %%c.\n");
620 work_stack.push_back(work_stack.back());
623 if (work_stack.size() < 1)
624 log_cmd_error(
"Must have at least one element on the stack for operator %%m.\n");
628 if (work_stack.size() < 1)
629 log_cmd_error(
"Must have at least one element on the stack for operator %%a.\n");
632 if (arg ==
"%x" || (arg.size() > 2 && arg.substr(0, 2) ==
"%x" && (arg[2] ==
':' || arg[2] ==
'*' || arg[2] ==
'.' || (
'0' <= arg[2] && arg[2] <=
'9')))) {
633 if (work_stack.size() < 1)
634 log_cmd_error(
"Must have at least one element on the stack for operator %%x.\n");
637 if (arg ==
"%ci" || (arg.size() > 3 && arg.substr(0, 3) ==
"%ci" && (arg[3] ==
':' || arg[3] ==
'*' || arg[3] ==
'.' || (
'0' <= arg[3] && arg[3] <=
'9')))) {
638 if (work_stack.size() < 1)
639 log_cmd_error(
"Must have at least one element on the stack for operator %%ci.\n");
642 if (arg ==
"%co" || (arg.size() > 3 && arg.substr(0, 3) ==
"%co" && (arg[3] ==
':' || arg[3] ==
'*' || arg[3] ==
'.' || (
'0' <= arg[3] && arg[3] <=
'9')))) {
643 if (work_stack.size() < 1)
644 log_cmd_error(
"Must have at least one element on the stack for operator %%co.\n");
647 log_cmd_error(
"Unknown selection operator '%s'.\n", arg.c_str());
648 if (work_stack.size() >= 1)
667 size_t pos = arg.find(
'/');
668 if (pos == std::string::npos) {
669 if (arg.find(
':') == std::string::npos || arg.substr(0, 1) ==
"A")
672 arg_mod =
"*", arg_memb = arg;
674 arg_mod = arg.substr(0, pos);
675 arg_memb = arg.substr(pos+1);
682 if (arg ==
"*" && arg_mod ==
"*") {
688 for (
auto &mod_it : design->
modules_)
690 if (arg_mod.substr(0, 2) ==
"A:") {
691 if (!
match_attr(mod_it.second->attributes, arg_mod.substr(2)))
697 if (arg_memb ==
"") {
703 if (arg_memb.substr(0, 2) ==
"w:") {
704 for (
auto &it : mod->
wires_)
705 if (
match_ids(it.first, arg_memb.substr(2)))
708 if (arg_memb.substr(0, 2) ==
"i:") {
709 for (
auto &it : mod->
wires_)
710 if (it.second->port_input &&
match_ids(it.first, arg_memb.substr(2)))
713 if (arg_memb.substr(0, 2) ==
"o:") {
714 for (
auto &it : mod->
wires_)
715 if (it.second->port_output &&
match_ids(it.first, arg_memb.substr(2)))
718 if (arg_memb.substr(0, 2) ==
"x:") {
719 for (
auto &it : mod->
wires_)
720 if ((it.second->port_input || it.second->port_output) &&
match_ids(it.first, arg_memb.substr(2)))
723 if (arg_memb.substr(0, 2) ==
"s:") {
724 size_t delim = arg_memb.substr(2).find(
':');
725 if (delim == std::string::npos) {
726 int width = atoi(arg_memb.substr(2).c_str());
727 for (
auto &it : mod->
wires_)
728 if (it.second->width == width)
731 std::string min_str = arg_memb.substr(2, delim);
732 std::string max_str = arg_memb.substr(2+delim+1);
733 int min_width = min_str.empty() ? 0 : atoi(min_str.c_str());
734 int max_width = max_str.empty() ? -1 : atoi(max_str.c_str());
735 for (
auto &it : mod->
wires_)
736 if (min_width <= it.second->width && (it.second->width <= max_width || max_width == -1))
740 if (arg_memb.substr(0, 2) ==
"m:") {
742 if (
match_ids(it.first, arg_memb.substr(2)))
745 if (arg_memb.substr(0, 2) ==
"c:") {
746 for (
auto &it : mod->
cells_)
747 if (
match_ids(it.first, arg_memb.substr(2)))
750 if (arg_memb.substr(0, 2) ==
"t:") {
751 for (
auto &it : mod->
cells_)
752 if (
match_ids(it.second->type, arg_memb.substr(2)))
755 if (arg_memb.substr(0, 2) ==
"p:") {
757 if (
match_ids(it.first, arg_memb.substr(2)))
760 if (arg_memb.substr(0, 2) ==
"a:") {
761 for (
auto &it : mod->
wires_)
762 if (
match_attr(it.second->attributes, arg_memb.substr(2)))
765 if (
match_attr(it.second->attributes, arg_memb.substr(2)))
767 for (
auto &it : mod->
cells_)
768 if (
match_attr(it.second->attributes, arg_memb.substr(2)))
771 if (
match_attr(it.second->attributes, arg_memb.substr(2)))
774 if (arg_memb.substr(0, 2) ==
"r:") {
775 for (
auto &it : mod->
cells_)
776 if (
match_attr(it.second->parameters, arg_memb.substr(2)))
779 if (arg_memb.substr(0, 2) ==
"n:")
780 arg_memb = arg_memb.substr(2);
781 for (
auto &it : mod->
wires_)
787 for (
auto &it : mod->
cells_)
static void select_op_intersect(RTLIL::Design *design, RTLIL::Selection &lhs, const RTLIL::Selection &rhs)
static void select_filter_active_mod(RTLIL::Design *design, RTLIL::Selection &sel)
std::vector< RTLIL::Selection > selection_stack
static std::vector< RTLIL::Selection > work_stack
std::set< RTLIL::IdString > selected_modules
static bool match_ids(RTLIL::IdString id, std::string pattern)
std::map< RTLIL::IdString, std::set< RTLIL::IdString > > selected_members
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
static std::string unescape_id(std::string str)
std::map< RTLIL::IdString, RTLIL::Memory * > memories
static std::string escape_id(std::string str)
static int select_op_expand(RTLIL::Design *design, RTLIL::Selection &lhs, std::vector< expand_rule_t > &rules, std::set< RTLIL::IdString > &limits, int max_objects, char mode, CellTypes &ct)
static void select_op_alias(RTLIL::Design *design, RTLIL::Selection &lhs)
std::map< RTLIL::IdString, RTLIL::Selection > selection_vars
static void select_op_neg(RTLIL::Design *design, RTLIL::Selection &lhs)
static void select_op_fullmod(RTLIL::Design *design, RTLIL::Selection &lhs)
void log_cmd_error(const char *format,...)
std::map< RTLIL::IdString, RTLIL::Process * > processes
std::map< RTLIL::IdString, RTLIL::Module * > modules_
static bool match_attr(const std::map< RTLIL::IdString, RTLIL::Const > &attributes, std::string name_pat, std::string value_pat, char match_op)
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
static void select_op_diff(RTLIL::Design *design, RTLIL::Selection &lhs, const RTLIL::Selection &rhs)
std::string selected_active_module
static void select_op_submod(RTLIL::Design *design, RTLIL::Selection &lhs)
static void select_op_union(RTLIL::Design *, RTLIL::Selection &lhs, const RTLIL::Selection &rhs)