37 if (
id.size() > 0 &&
id[0] ==
'\\' &&
id.substr(1) == pattern)
39 if (
patmatch(pattern.c_str(),
id.c_str()))
41 if (
id.size() > 0 &&
id[0] ==
'\\' &&
patmatch(pattern.c_str(),
id.substr(1).c_str()))
43 if (
id.size() > 0 &&
id[0] ==
'$' && pattern.size() > 0 && pattern[0] ==
'$') {
44 const char *p =
id.c_str();
45 const char *q = strrchr(p,
'$');
67 return value == pattern_value;
69 return value != pattern_value;
88 return value_str == pattern;
90 return value_str != pattern;
92 return value_str < pattern;
94 return value_str > pattern;
96 return value_str <= pattern;
98 return value_str >= pattern;
104 static bool match_attr(
const std::map<RTLIL::IdString, RTLIL::Const> &attributes, std::string name_pat, std::string value_pat,
char match_op)
106 if (name_pat.find(
'*') != std::string::npos || name_pat.find(
'?') != std::string::npos || name_pat.find(
'[') != std::string::npos) {
107 for (
auto &it : attributes) {
110 if (it.first.size() > 0 && it.first[0] ==
'\\' &&
patmatch(name_pat.c_str(), it.first.substr(1).c_str()) &&
match_attr_val(it.second, value_pat, match_op))
114 if (name_pat.size() > 0 && (name_pat[0] ==
'\\' || name_pat[0] ==
'$') && attributes.count(name_pat) &&
match_attr_val(attributes.at(name_pat), value_pat, match_op))
116 if (attributes.count(
"\\" + name_pat) &&
match_attr_val(attributes.at(
"\\" + name_pat), value_pat, match_op))
122 static bool match_attr(
const std::map<RTLIL::IdString, RTLIL::Const> &attributes, std::string match_expr)
124 size_t pos = match_expr.find_first_of(
"<!=>");
126 if (pos != std::string::npos) {
127 if (match_expr.substr(pos, 2) ==
"!=")
128 return match_attr(attributes, match_expr.substr(0, pos), match_expr.substr(pos+2),
'!');
129 if (match_expr.substr(pos, 2) ==
"<=")
130 return match_attr(attributes, match_expr.substr(0, pos), match_expr.substr(pos+2),
'[');
131 if (match_expr.substr(pos, 2) ==
">=")
132 return match_attr(attributes, match_expr.substr(0, pos), match_expr.substr(pos+2),
']');
133 return match_attr(attributes, match_expr.substr(0, pos), match_expr.substr(pos+1), match_expr[pos]);
136 return match_attr(attributes, match_expr, std::string(), 0);
155 for (
auto &mod_it : design->
modules_)
165 for (
auto &it : mod->
wires_)
171 for (
auto &it : mod->
cells_)
185 for (
auto &mod_it : design->
modules_)
189 for (
auto &cell_it : mod_it.second->cells_)
191 if (design->
modules_.count(cell_it.second->type) == 0)
209 for (
auto &mod_it : design->
modules_)
216 SigMap sigmap(mod_it.second);
219 for (
auto &it : mod_it.second->wires_)
221 selected_bits.
add(sigmap(it.second));
223 for (
auto &it : mod_it.second->wires_)
242 for (
auto &it2 : it.second)
275 if (design->
modules_.count(it.first) == 0)
282 for (
auto &it : mod->
wires_)
286 for (
auto &it : mod->
cells_)
296 for (
auto &it2 : it.second)
312 std::vector<RTLIL::IdString> del_list;
319 del_list.push_back(it);
321 for (
auto &it : del_list)
329 del_list.push_back(it.first);
332 std::vector<RTLIL::IdString> del_list2;
333 for (
auto &it2 : it.second)
335 del_list2.push_back(it2);
336 for (
auto &it2 : del_list2)
337 it.second.erase(it2);
338 if (it.second.size() == 0)
339 del_list.push_back(it.first);
341 for (
auto &it : del_list)
346 struct expand_rule_t {
348 std::set<RTLIL::IdString> cell_types, port_names;
352 static int parse_comma_list(std::set<RTLIL::IdString> &tokens, std::string str,
size_t pos, std::string stopchar)
356 size_t endpos = str.find_first_of(stopchar, pos);
357 if (endpos == std::string::npos)
362 if (pos == str.size() || str[pos] !=
',')
371 bool is_input, is_output;
372 for (
auto &mod_it : design->
modules_)
378 std::set<RTLIL::Wire*> selected_wires;
380 for (
auto &it : mod->
wires_)
381 if (lhs.
selected_member(mod_it.first, it.first) && limits.count(it.first) == 0)
382 selected_wires.insert(it.second);
386 std::vector<RTLIL::SigBit> conn_lhs = conn.first.to_sigbit_vector();
387 std::vector<RTLIL::SigBit> conn_rhs = conn.second.to_sigbit_vector();
389 for (
size_t i = 0; i < conn_lhs.size(); i++) {
390 if (conn_lhs[i].wire ==
NULL || conn_rhs[i].wire ==
NULL)
392 if (mode !=
'i' && selected_wires.count(conn_rhs[i].wire) && lhs.
selected_members[mod->
name].count(conn_lhs[i].wire->name) == 0)
394 if (mode !=
'o' && selected_wires.count(conn_lhs[i].wire) && lhs.
selected_members[mod->
name].count(conn_rhs[i].wire->name) == 0)
399 for (
auto &cell : mod->
cells_)
400 for (
auto &conn : cell.second->connections())
402 char last_mode =
'-';
403 for (
auto &rule : rules) {
404 last_mode = rule.mode;
405 if (rule.cell_types.size() > 0 && rule.cell_types.count(cell.second->type) == 0)
407 if (rule.port_names.size() > 0 && rule.port_names.count(conn.first) == 0)
409 if (rule.mode ==
'+')
414 if (last_mode ==
'+')
417 is_input = mode ==
'x' || ct.
cell_input(cell.second->type, conn.first);
418 is_output = mode ==
'x' || ct.
cell_output(cell.second->type, conn.first);
419 for (
auto &chunk : conn.second.chunks())
420 if (chunk.wire !=
NULL) {
421 if (max_objects != 0 && selected_wires.count(chunk.wire) > 0 && lhs.
selected_members[mod->
name].count(cell.first) == 0)
422 if (mode ==
'x' || (mode ==
'i' && is_output) || (mode ==
'o' && is_input))
425 if (mode ==
'x' || (mode ==
'i' && is_input) || (mode ==
'o' && is_output))
437 int pos = mode ==
'x' ? 2 : 3, levels = 1, rem_objects = -1;
438 std::vector<expand_rule_t> rules;
439 std::set<RTLIL::IdString> limits;
446 if (pos <
int(arg.size()) && arg[pos] ==
'*') {
450 if (pos <
int(arg.size()) &&
'0' <= arg[pos] && arg[pos] <=
'9') {
451 size_t endpos = arg.find_first_not_of(
"0123456789", pos);
452 if (endpos == std::string::npos)
454 levels = atoi(arg.substr(pos, endpos-pos).c_str());
458 if (pos <
int(arg.size()) && arg[pos] ==
'.') {
459 size_t endpos = arg.find_first_not_of(
"0123456789", ++pos);
460 if (endpos == std::string::npos)
462 if (
int(endpos) > pos)
463 rem_objects = atoi(arg.substr(pos, endpos-pos).c_str());
467 while (pos <
int(arg.size())) {
468 if (arg[pos] !=
':' || pos+1 ==
int(arg.size()))
469 log_cmd_error(
"Syntax error in expand operator '%s'.\n", arg.c_str());
471 if (arg[pos] ==
'+' || arg[pos] ==
'-') {
473 rule.mode = arg[pos++];
475 if (pos <
int(arg.size()) && arg[pos] ==
'[') {
477 if (pos <
int(arg.size()) && arg[pos] ==
']')
480 rules.push_back(rule);
482 size_t endpos = arg.find(
':', pos);
483 if (endpos == std::string::npos)
485 if (
int(endpos) > pos) {
486 std::string str = arg.substr(pos, endpos-pos);
491 for (
auto i2 : i1.second)
503 log(
"expand by %d levels (max. %d objects):\n", levels, rem_objects);
504 for (
auto &rule : rules) {
505 log(
" rule (%c):\n", rule.mode);
506 if (rule.cell_types.size() > 0) {
508 for (
auto &it : rule.cell_types)
509 log(
" %s", it.c_str());
512 if (rule.port_names.size() > 0) {
514 for (
auto &it : rule.port_names)
515 log(
" %s", it.c_str());
519 if (limits.size() > 0) {
521 for (
auto &it : limits)
522 log(
" %s", it.c_str());
527 while (levels-- > 0 && rem_objects != 0) {
529 if (num_objects == 0)
531 rem_objects -= num_objects;
534 if (rem_objects == 0)
535 log_warning(
"reached configured limit at `%s'.\n", arg.c_str());
551 std::vector<RTLIL::IdString> del_list;
554 del_list.push_back(mod_name);
557 del_list.push_back(it.first);
558 for (
auto mod_name : del_list) {
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();
608 log_cmd_error(
"Must have at least two elements on the stack for operator %%i.\n");
614 log_cmd_error(
"Must have at least one element on the stack for operator %%s.\n");
619 log_cmd_error(
"Must have at least one element on the stack for operator %%c.\n");
624 log_cmd_error(
"Must have at least one element on the stack for operator %%m.\n");
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')))) {
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')))) {
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')))) {
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());
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_)
806 for (; argidx < args_size; argidx++) {
807 if (args[argidx].substr(0, 1) ==
"-") {
809 pass->
cmd_error(args, argidx,
"Unexpected option in selection arguments.");
829 SelectPass() :
Pass(
"select",
"modify and view the list of selected objects") { }
834 log(
" select [ -add | -del | -set <name> ] <selection>\n");
835 log(
" select [ -assert-none | -assert-any ] <selection>\n");
836 log(
" select [ -list | -write <filename> | -count | -clear ]\n");
837 log(
" select -module <modname>\n");
839 log(
"Most commands use the list of currently selected objects to determine which part\n");
840 log(
"of the design to operate on. This command can be used to modify and view this\n");
841 log(
"list of selected objects.\n");
843 log(
"Note that many commands support an optional [selection] argument that can be\n");
844 log(
"used to override the global selection for the command. The syntax of this\n");
845 log(
"optional argument is identical to the syntax of the <selection> argument\n");
846 log(
"described here.\n");
848 log(
" -add, -del\n");
849 log(
" add or remove the given objects to the current selection.\n");
850 log(
" without this options the current selection is replaced.\n");
852 log(
" -set <name>\n");
853 log(
" do not modify the current selection. instead save the new selection\n");
854 log(
" under the given name (see @<name> below). to save the current selection,\n");
855 log(
" use \"select -set <name> %%\"\n");
857 log(
" -assert-none\n");
858 log(
" do not modify the current selection. instead assert that the given\n");
859 log(
" selection is empty. i.e. produce an error if any object matching the\n");
860 log(
" selection is found.\n");
862 log(
" -assert-any\n");
863 log(
" do not modify the current selection. instead assert that the given\n");
864 log(
" selection is non-empty. i.e. produce an error if no object matching\n");
865 log(
" the selection is found.\n");
867 log(
" -assert-count N\n");
868 log(
" do not modify the current selection. instead assert that the given\n");
869 log(
" selection contains exactly N objects.\n");
872 log(
" list all objects in the current selection\n");
874 log(
" -write <filename>\n");
875 log(
" like -list but write the output to the specified file\n");
878 log(
" count all objects in the current selection\n");
881 log(
" clear the current selection. this effectively selects the whole\n");
882 log(
" design. it also resets the selected module (see -module). use the\n");
883 log(
" command 'select *' to select everything but stay in the current module.\n");
886 log(
" create an empty selection. the current module is unchanged.\n");
888 log(
" -module <modname>\n");
889 log(
" limit the current scope to the specified module.\n");
890 log(
" the difference between this and simply selecting the module\n");
891 log(
" is that all object names are interpreted relative to this\n");
892 log(
" module after this command until the selection is cleared again.\n");
894 log(
"When this command is called without an argument, the current selection\n");
895 log(
"is displayed in a compact form (i.e. only the module name when a whole module\n");
896 log(
"is selected).\n");
898 log(
"The <selection> argument itself is a series of commands for a simple stack\n");
899 log(
"machine. Each element on the stack represents a set of selected objects.\n");
900 log(
"After this commands have been executed, the union of all remaining sets\n");
901 log(
"on the stack is computed and used as selection for the command.\n");
903 log(
"Pushing (selecting) object when not in -module mode:\n");
905 log(
" <mod_pattern>\n");
906 log(
" select the specified module(s)\n");
908 log(
" <mod_pattern>/<obj_pattern>\n");
909 log(
" select the specified object(s) from the module(s)\n");
911 log(
"Pushing (selecting) object when in -module mode:\n");
913 log(
" <obj_pattern>\n");
914 log(
" select the specified object(s) from the current module\n");
916 log(
"A <mod_pattern> can be a module name, wildcard expression (*, ?, [..])\n");
917 log(
"matching module names, or one of the following:\n");
919 log(
" A:<pattern>, A:<pattern>=<pattern>\n");
920 log(
" all modules with an attribute matching the given pattern\n");
921 log(
" in addition to = also <, <=, >=, and > are supported\n");
923 log(
"An <obj_pattern> can be an object name, wildcard expression, or one of\n");
924 log(
"the following:\n");
926 log(
" w:<pattern>\n");
927 log(
" all wires with a name matching the given wildcard pattern\n");
929 log(
" i:<pattern>, o:<pattern>, x:<pattern>\n");
930 log(
" all inputs (i:), outputs (o:) or any ports (x:) with matching names\n");
932 log(
" s:<size>, s:<min>:<max>\n");
933 log(
" all wires with a matching width\n");
935 log(
" m:<pattern>\n");
936 log(
" all memories with a name matching the given pattern\n");
938 log(
" c:<pattern>\n");
939 log(
" all cells with a name matching the given pattern\n");
941 log(
" t:<pattern>\n");
942 log(
" all cells with a type matching the given pattern\n");
944 log(
" p:<pattern>\n");
945 log(
" all processes with a name matching the given pattern\n");
947 log(
" a:<pattern>\n");
948 log(
" all objects with an attribute name matching the given pattern\n");
950 log(
" a:<pattern>=<pattern>\n");
951 log(
" all objects with a matching attribute name-value-pair.\n");
952 log(
" in addition to = also <, <=, >=, and > are supported\n");
954 log(
" r:<pattern>, r:<pattern>=<pattern>\n");
955 log(
" cells with matching parameters. also with <, <=, >= and >.\n");
957 log(
" n:<pattern>\n");
958 log(
" all objects with a name matching the given pattern\n");
959 log(
" (i.e. 'n:' is optional as it is the default matching rule)\n");
962 log(
" push the selection saved prior with 'select -set <name> ...'\n");
964 log(
"The following actions can be performed on the top sets on the stack:\n");
967 log(
" push a copy of the current selection to the stack\n");
970 log(
" replace the stack with a union of all elements on it\n");
973 log(
" replace top set with its invert\n");
976 log(
" replace the two top sets on the stack with their union\n");
979 log(
" replace the two top sets on the stack with their intersection\n");
982 log(
" pop the top set from the stack and subtract it from the new top\n");
985 log(
" like %%d but swap the roles of two top sets on the stack\n");
988 log(
" create a copy of the top set rom the stack and push it\n");
990 log(
" %%x[<num1>|*][.<num2>][:<rule>[:<rule>..]]\n");
991 log(
" expand top set <num1> num times according to the specified rules.\n");
992 log(
" (i.e. select all cells connected to selected wires and select all\n");
993 log(
" wires connected to selected cells) The rules specify which cell\n");
994 log(
" ports to use for this. the syntax for a rule is a '-' for exclusion\n");
995 log(
" and a '+' for inclusion, followed by an optional comma separated\n");
996 log(
" list of cell types followed by an optional comma separated list of\n");
997 log(
" cell ports in square brackets. a rule can also be just a cell or wire\n");
998 log(
" name that limits the expansion (is included but does not go beyond).\n");
999 log(
" select at most <num2> objects. a warning message is printed when this\n");
1000 log(
" limit is reached. When '*' is used instead of <num1> then the process\n");
1001 log(
" is repeated until no further object are selected.\n");
1003 log(
" %%ci[<num1>|*][.<num2>][:<rule>[:<rule>..]]\n");
1004 log(
" %%co[<num1>|*][.<num2>][:<rule>[:<rule>..]]\n");
1005 log(
" simmilar to %%x, but only select input (%%ci) or output cones (%%co)\n");
1008 log(
" expand top set by selecting all wires that are (at least in part)\n");
1009 log(
" aliases for selected wires.\n");
1012 log(
" expand top set by adding all modules of instantiated cells in selected\n");
1016 log(
" expand top set by selecting all modules that contain selected objects\n");
1018 log(
"Example: the following command selects all wires that are connected to a\n");
1019 log(
"'GATE' input of a 'SWITCH' cell:\n");
1021 log(
" select */t:SWITCH %%x:+[GATE] */t:SWITCH %%d\n");
1026 bool add_mode =
false;
1027 bool del_mode =
false;
1028 bool clear_mode =
false;
1029 bool none_mode =
false;
1030 bool list_mode =
false;
1031 bool count_mode =
false;
1032 bool got_module =
false;
1033 bool assert_none =
false;
1034 bool assert_any =
false;
1035 int assert_count = -1;
1036 std::string write_file;
1037 std::string set_name;
1038 std::string sel_str;
1043 for (argidx = 1; argidx < args.size(); argidx++)
1045 std::string arg = args[argidx];
1046 if (arg ==
"-add") {
1050 if (arg ==
"-del") {
1054 if (arg ==
"-assert-none") {
1058 if (arg ==
"-assert-any") {
1062 if (arg ==
"-assert-count" && argidx+1 < args.size()) {
1063 assert_count = atoi(args[++argidx].c_str());
1066 if (arg ==
"-clear") {
1070 if (arg ==
"-none") {
1074 if (arg ==
"-list") {
1078 if (arg ==
"-write" && argidx+1 < args.size()) {
1079 write_file = args[++argidx];
1082 if (arg ==
"-count") {
1086 if (arg ==
"-module" && argidx+1 < args.size()) {
1088 if (design->
modules_.count(mod_name) == 0)
1094 if (arg ==
"-set" && argidx+1 < args.size()) {
1098 if (arg.size() > 0 && arg[0] ==
'-')
1101 sel_str +=
" " + arg;
1104 if (clear_mode && args.size() != 2)
1105 log_cmd_error(
"Option -clear can not be combined with any other options.\n");
1107 if (none_mode && args.size() != 2)
1108 log_cmd_error(
"Option -none can not be combined with any other options.\n");
1110 if (add_mode + del_mode + assert_none + assert_any + (assert_count >= 0) > 1)
1111 log_cmd_error(
"Options -add, -del, -assert-none, -assert-any or -assert-count can not be combined.\n");
1113 if ((list_mode || !write_file.empty() || count_mode) && (add_mode || del_mode || assert_none || assert_any || assert_count >= 0))
1114 log_cmd_error(
"Options -list, -write and -count can not be combined with -add, -del, -assert-none, -assert-any or -assert-count.\n");
1116 if (!set_name.empty() && (list_mode || !write_file.empty() || count_mode || add_mode || del_mode || assert_none || assert_any || assert_count >= 0))
1117 log_cmd_error(
"Option -set can not be combined with -list, -write, -count, -add, -del, -assert-none, -assert-any or -assert-count.\n");
1143 if (list_mode || count_mode || !write_file.empty())
1145 #define LOG_OBJECT(...) { if (list_mode) log(__VA_ARGS__); if (f != NULL) fprintf(f, __VA_ARGS__); total_count++; }
1146 int total_count = 0;
1148 if (!write_file.empty()) {
1149 f = fopen(write_file.c_str(),
"w");
1151 log_error(
"Can't open '%s' for writing: %s\n", write_file.c_str(), strerror(errno));
1157 for (
auto mod_it : design->
modules_)
1162 for (
auto &it : mod_it.second->wires_)
1165 for (
auto &it : mod_it.second->memories)
1168 for (
auto &it : mod_it.second->cells_)
1171 for (
auto &it : mod_it.second->processes)
1177 log(
"%d objects.\n", total_count);
1207 log_error(
"Assertation failed: selection is not empty:%s\n", sel_str.c_str());
1216 log_error(
"Assertation failed: selection is empty:%s\n", sel_str.c_str());
1220 if (assert_count >= 0)
1222 int total_count = 0;
1227 for (
auto mod_it : design->
modules_)
1229 for (
auto &it : mod_it.second->wires_)
1232 for (
auto &it : mod_it.second->memories)
1235 for (
auto &it : mod_it.second->cells_)
1238 for (
auto &it : mod_it.second->processes)
1242 if (assert_count != total_count)
1243 log_error(
"Assertation failed: selection contains %d elements instead of the asserted %d:%s\n",
1244 total_count, assert_count, sel_str.c_str());
1248 if (!set_name.empty())
1264 for (
auto &it2 : it.second)
1275 CdPass() :
Pass(
"cd",
"a shortcut for 'select -module <name>'") { }
1280 log(
" cd <modname>\n");
1282 log(
"This is just a shortcut for 'select -module <modname>'.\n");
1285 log(
" cd <cellname>\n");
1287 log(
"When no module with the specified name is found, but there is a cell\n");
1288 log(
"with the specified name in the current module, then this is equivialent\n");
1289 log(
"to 'cd <celltype>'.\n");
1293 log(
"This is just a shortcut for 'select -clear'.\n");
1298 if (args.size() != 2)
1301 if (args[1] ==
"..") {
1313 if (module !=
NULL && module->
cells_.count(modname) > 0)
1314 modname = module->
cells_.at(modname)->type.str();
1317 if (design->
modules_.count(modname) > 0) {
1329 template<
typename T>
1330 static int log_matches(
const char *title, std::string pattern, T list)
1332 std::vector<RTLIL::IdString> matches;
1334 for (
auto &it : list)
1335 if (pattern.empty() ||
match_ids(it.first, pattern))
1336 matches.push_back(it.first);
1338 if (matches.empty())
1341 log(
"\n%d %s:\n",
int(matches.size()), title);
1342 for (
auto &
id : matches)
1344 return matches.size();
1353 log(
" ls [pattern]\n");
1355 log(
"When no active module is selected, this prints a list of all modules.\n");
1357 log(
"When an active module is selected, this prints a list of objects in the module.\n");
1359 log(
"If a pattern is given, the objects matching the pattern are printed\n");
1361 log(
"Note that this command does not use the selection mechanism and always operates\n");
1362 log(
"on the whole design or whole active module. Use 'select -list' to show a list\n");
1363 log(
"of currently selected objects.\n");
1368 std::string pattern;
1371 if (args.size() != 1 && args.size() != 2)
1373 if (args.size() == 2)
1374 pattern = args.at(1);
bool selected_module(RTLIL::IdString mod_name) const
static void select_op_intersect(RTLIL::Design *design, RTLIL::Selection &lhs, const RTLIL::Selection &rhs)
void cmd_error(const std::vector< std::string > &args, size_t argidx, std::string msg)
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
static int parse_comma_list(std::set< RTLIL::IdString > &tokens, std::string str, size_t pos, std::string stopchar)
static void select_filter_active_mod(RTLIL::Design *design, RTLIL::Selection &sel)
bool selected_whole_module(RTLIL::IdString mod_name) const
std::vector< RTLIL::Selection > selection_stack
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
void log_warning(const char *format,...)
static std::vector< RTLIL::Selection > work_stack
bool selected_member(RTLIL::IdString mod_name, RTLIL::IdString memb_name) const
std::set< RTLIL::IdString > selected_modules
void setup(RTLIL::Design *design=NULL)
const std::vector< RTLIL::SigSig > & connections() const
static bool match_ids(RTLIL::IdString id, std::string pattern)
static int log_matches(const char *title, std::string pattern, T list)
#define YOSYS_NAMESPACE_END
std::map< RTLIL::IdString, std::set< RTLIL::IdString > > selected_members
RTLIL::Const as_const() const
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
static std::string unescape_id(std::string str)
std::map< RTLIL::IdString, RTLIL::Memory * > memories
void log_error(const char *format,...)
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)
bool check_any(RTLIL::SigSpec sig)
bool patmatch(const char *pattern, const char *string)
std::map< RTLIL::IdString, RTLIL::Selection > selection_vars
static void select_op_neg(RTLIL::Design *design, RTLIL::Selection &lhs)
#define PRIVATE_NAMESPACE_BEGIN
bool cell_output(RTLIL::IdString type, RTLIL::IdString port)
static void select_op_fullmod(RTLIL::Design *design, RTLIL::Selection &lhs)
std::string decode_string() const
#define log_assert(_assert_expr_)
static void select_stmt(RTLIL::Design *design, std::string arg)
#define PRIVATE_NAMESPACE_END
static const char * id2cstr(const RTLIL::IdString &str)
void log_cmd_error(const char *format,...)
int as_int(bool is_signed=false) const
std::map< RTLIL::IdString, RTLIL::Process * > processes
void add(RTLIL::SigSpec sig)
#define USING_YOSYS_NAMESPACE
std::map< RTLIL::IdString, RTLIL::Module * > modules_
PRIVATE_NAMESPACE_END YOSYS_NAMESPACE_BEGIN void handle_extra_select_args(Pass *pass, std::vector< std::string > args, size_t argidx, size_t args_size, RTLIL::Design *design)
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_
#define YOSYS_NAMESPACE_BEGIN
void log(const char *format,...)
static void select_op_diff(RTLIL::Design *design, RTLIL::Selection &lhs, const RTLIL::Selection &rhs)
void optimize(RTLIL::Design *design)
static bool match_attr_val(const RTLIL::Const &value, std::string pattern, char match_op)
bool cell_input(RTLIL::IdString type, RTLIL::IdString port)
std::string selected_active_module
static bool parse(RTLIL::SigSpec &sig, RTLIL::Module *module, std::string str)
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)