Replaced "select -assert-limit" with -assert-max and -assert-min

This commit is contained in:
Clifford Wolf 2016-07-01 12:24:13 +02:00
parent 9a742f4069
commit 6ed6b3cb6d
1 changed files with 29 additions and 42 deletions

View File

@ -952,7 +952,7 @@ struct SelectPass : public Pass {
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---| // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
log("\n"); log("\n");
log(" select [ -add | -del | -set <name> ] {-read <filename> | <selection>}\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 [ -list | -write <filename> | -count | -clear ]\n");
log(" select -module <modname>\n"); log(" select -module <modname>\n");
log("\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(" do not modify the current selection. instead assert that the given\n");
log(" selection contains exactly N objects.\n"); log(" selection contains exactly N objects.\n");
log("\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(" 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("\n");
log(" -list\n"); log(" -list\n");
log(" list all objects in the current selection\n"); log(" list all objects in the current selection\n");
@ -1172,7 +1176,8 @@ struct SelectPass : public Pass {
bool assert_none = false; bool assert_none = false;
bool assert_any = false; bool assert_any = false;
int assert_count = -1; int assert_count = -1;
int assert_limit = -1; int assert_max = -1;
int assert_min = -1;
std::string write_file, read_file; std::string write_file, read_file;
std::string set_name, sel_str; std::string set_name, sel_str;
@ -1202,8 +1207,12 @@ struct SelectPass : public Pass {
assert_count = atoi(args[++argidx].c_str()); assert_count = atoi(args[++argidx].c_str());
continue; continue;
} }
if (arg == "-assert-limit" && argidx+1 < args.size()) { if (arg == "-assert-max" && argidx+1 < args.size()) {
assert_limit = atoi(args[++argidx].c_str()); assert_max = atoi(args[++argidx].c_str());
continue;
}
if (arg == "-assert-min" && argidx+1 < args.size()) {
assert_min = atoi(args[++argidx].c_str());
continue; continue;
} }
if (arg == "-clear") { if (arg == "-clear") {
@ -1282,14 +1291,14 @@ struct SelectPass : public Pass {
if (none_mode && args.size() != 2) if (none_mode && args.size() != 2)
log_cmd_error("Option -none can not be combined with any other options.\n"); 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) 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 or -assert-limit can not be combined.\n"); 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)) 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, or -assert-limit.\n"); 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)) 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 or -assert-count.\n"); 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) { if (work_stack.size() == 0 && got_module) {
RTLIL::Selection sel; RTLIL::Selection sel;
@ -1394,7 +1403,7 @@ struct SelectPass : public Pass {
return; return;
} }
if (assert_count >= 0) if (assert_count >= 0 || assert_max >= 0 || assert_min >= 0)
{ {
int total_count = 0; int total_count = 0;
if (work_stack.size() == 0) if (work_stack.size() == 0)
@ -1416,37 +1425,15 @@ struct SelectPass : public Pass {
if (sel->selected_member(mod_it.first, it.first)) if (sel->selected_member(mod_it.first, it.first))
total_count++; 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", log_error("Assertion failed: selection contains %d elements instead of the asserted %d:%s\n",
total_count, assert_count, sel_str.c_str()); total_count, assert_count, sel_str.c_str());
return; 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_limit >= 0) if (assert_min >= 0 && assert_min > total_count)
{ log_error("Assertion failed: selection contains %d elements, less than the minimum number %d:%s\n",
int total_count = 0; total_count, assert_min, sel_str.c_str());
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());
return; return;
} }