Replaced "select -assert-limit" with -assert-max and -assert-min
authorClifford Wolf <clifford@clifford.at>
Fri, 1 Jul 2016 10:24:13 +0000 (12:24 +0200)
committerClifford Wolf <clifford@clifford.at>
Fri, 1 Jul 2016 10:24:13 +0000 (12:24 +0200)
passes/cmds/select.cc

index 9e0f953deb1a6a45ad0e919fc5f3ea755992bcc8..d2e1a2e2b787c47bacac9ca8aa11a4ce0ca484a1 100644 (file)
@@ -952,7 +952,7 @@ struct SelectPass : public Pass {
                //   |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
                log("\n");
                log("    select [ -add | -del | -set <name> ] {-read <filename> | <selection>}\n");
-               log("    select [ -assert-none | -assert-any ] {-read <filename> | <selection>}\n");
+               log("    select [ <assert_option> ] {-read <filename> | <selection>}\n");
                log("    select [ -list | -write <filename> | -count | -clear ]\n");
                log("    select -module <modname>\n");
                log("\n");
@@ -988,9 +988,13 @@ struct SelectPass : public Pass {
                log("        do not modify the current selection. instead assert that the given\n");
                log("        selection contains exactly N objects.\n");
                log("\n");
-               log("    -assert-limit N\n");
+               log("    -assert-max N\n");
                log("        do not modify the current selection. instead assert that the given\n");
-               log("        selection contains more than N objects.\n");
+               log("        selection contains less than or exactly N objects.\n");
+               log("\n");
+               log("    -assert-min N\n");
+               log("        do not modify the current selection. instead assert that the given\n");
+               log("        selection contains at least N objects.\n");
                log("\n");
                log("    -list\n");
                log("        list all objects in the current selection\n");
@@ -1172,7 +1176,8 @@ struct SelectPass : public Pass {
                bool assert_none = false;
                bool assert_any = false;
                int assert_count = -1;
-               int assert_limit = -1;
+               int assert_max = -1;
+               int assert_min = -1;
                std::string write_file, read_file;
                std::string set_name, sel_str;
 
@@ -1202,8 +1207,12 @@ struct SelectPass : public Pass {
                                assert_count = atoi(args[++argidx].c_str());
                                continue;
                        }
-                       if (arg == "-assert-limit" && argidx+1 < args.size()) {
-                               assert_limit = atoi(args[++argidx].c_str());
+                       if (arg == "-assert-max" && argidx+1 < args.size()) {
+                               assert_max = atoi(args[++argidx].c_str());
+                               continue;
+                       }
+                       if (arg == "-assert-min" && argidx+1 < args.size()) {
+                               assert_min = atoi(args[++argidx].c_str());
                                continue;
                        }
                        if (arg == "-clear") {
@@ -1282,14 +1291,14 @@ struct SelectPass : public Pass {
                if (none_mode && args.size() != 2)
                        log_cmd_error("Option -none can not be combined with any other options.\n");
 
-               if (add_mode + del_mode + assert_none + assert_any + (assert_count >= 0) + (assert_limit >= 0) > 1)
-                       log_cmd_error("Options -add, -del, -assert-none, -assert-any, assert-count or -assert-limit can not be combined.\n");
+               if (add_mode + del_mode + assert_none + assert_any + (assert_count >= 0) + (assert_max >= 0) + (assert_min >= 0) > 1)
+                       log_cmd_error("Options -add, -del, -assert-none, -assert-any, assert-count, -assert-max or -assert-min can not be combined.\n");
 
-               if ((list_mode || !write_file.empty() || count_mode) && (add_mode || del_mode || assert_none || assert_any || assert_count >= 0 || assert_limit >= 0))
-                       log_cmd_error("Options -list, -write and -count can not be combined with -add, -del, -assert-none, -assert-any, assert-count, or -assert-limit.\n");
+               if ((list_mode || !write_file.empty() || count_mode) && (add_mode || del_mode || assert_none || assert_any || assert_count >= 0 || assert_max >= 0 || assert_min >= 0))
+                       log_cmd_error("Options -list, -write and -count can not be combined with -add, -del, -assert-none, -assert-any, assert-count, -assert-max, or -assert-min.\n");
 
-               if (!set_name.empty() && (list_mode || !write_file.empty() || count_mode || add_mode || del_mode || assert_none || assert_any || assert_count >= 0 || assert_limit >= 0))
-                       log_cmd_error("Option -set can not be combined with -list, -write, -count, -add, -del, -assert-none, -assert-any or -assert-count.\n");
+               if (!set_name.empty() && (list_mode || !write_file.empty() || count_mode || add_mode || del_mode || assert_none || assert_any || assert_count >= 0 || assert_max >= 0 || assert_min >= 0))
+                       log_cmd_error("Option -set can not be combined with -list, -write, -count, -add, -del, -assert-none, -assert-any, -assert-count, -assert-max, or -assert-min.\n");
 
                if (work_stack.size() == 0 && got_module) {
                        RTLIL::Selection sel;
@@ -1394,7 +1403,7 @@ struct SelectPass : public Pass {
                        return;
                }
 
-               if (assert_count >= 0)
+               if (assert_count >= 0 || assert_max >= 0 || assert_min >= 0)
                {
                        int total_count = 0;
                        if (work_stack.size() == 0)
@@ -1416,37 +1425,15 @@ struct SelectPass : public Pass {
                                                if (sel->selected_member(mod_it.first, it.first))
                                                        total_count++;
                                }
-                       if (assert_count != total_count)
+                       if (assert_count >= 0 && assert_count != total_count)
                                log_error("Assertion failed: selection contains %d elements instead of the asserted %d:%s\n",
                                                total_count, assert_count, sel_str.c_str());
-                       return;
-               }
-
-               if (assert_limit >= 0)
-               {
-                       int total_count = 0;
-                       if (work_stack.size() == 0)
-                               log_cmd_error("No selection to check.\n");
-                       RTLIL::Selection *sel = &work_stack.back();
-                       sel->optimize(design);
-                       for (auto mod_it : design->modules_)
-                               if (sel->selected_module(mod_it.first)) {
-                                       for (auto &it : mod_it.second->wires_)
-                                               if (sel->selected_member(mod_it.first, it.first))
-                                                       total_count++;
-                                       for (auto &it : mod_it.second->memories)
-                                               if (sel->selected_member(mod_it.first, it.first))
-                                                       total_count++;
-                                       for (auto &it : mod_it.second->cells_)
-                                               if (sel->selected_member(mod_it.first, it.first))
-                                                       total_count++;
-                                       for (auto &it : mod_it.second->processes)
-                                               if (sel->selected_member(mod_it.first, it.first))
-                                                       total_count++;
-                               }
-                       if (assert_limit < total_count)
-                               log_error("Assertion failed: selection contains %d elements instead of the maximum number %d:%s\n",
-                                               total_count, assert_limit, sel_str.c_str());
+                       if (assert_max >= 0 && assert_max < total_count)
+                               log_error("Assertion failed: selection contains %d elements, more than the maximum number %d:%s\n",
+                                               total_count, assert_max, sel_str.c_str());
+                       if (assert_min >= 0 && assert_min > total_count)
+                               log_error("Assertion failed: selection contains %d elements, less than the minimum number %d:%s\n",
+                                               total_count, assert_min, sel_str.c_str());
                        return;
                }