mirror of https://github.com/YosysHQ/yosys.git
Added "select -assert-count"
This commit is contained in:
parent
e9506bb2da
commit
1ce5e83555
|
@ -857,6 +857,10 @@ struct SelectPass : public Pass {
|
||||||
log(" selection is non-empty. i.e. produce an error if no object matching\n");
|
log(" selection is non-empty. i.e. produce an error if no object matching\n");
|
||||||
log(" the selection is found.\n");
|
log(" the selection is found.\n");
|
||||||
log("\n");
|
log("\n");
|
||||||
|
log(" -assert-count N\n");
|
||||||
|
log(" do not modify the current selection. instead assert that the given\n");
|
||||||
|
log(" selection contains exactly N objects.\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");
|
||||||
log("\n");
|
log("\n");
|
||||||
|
@ -1021,6 +1025,7 @@ struct SelectPass : public Pass {
|
||||||
bool got_module = false;
|
bool got_module = false;
|
||||||
bool assert_none = false;
|
bool assert_none = false;
|
||||||
bool assert_any = false;
|
bool assert_any = false;
|
||||||
|
int assert_count = -1;
|
||||||
std::string write_file;
|
std::string write_file;
|
||||||
std::string set_name;
|
std::string set_name;
|
||||||
std::string sel_str;
|
std::string sel_str;
|
||||||
|
@ -1047,6 +1052,10 @@ struct SelectPass : public Pass {
|
||||||
assert_any = true;
|
assert_any = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (arg == "-assert-count" && argidx+1 < args.size()) {
|
||||||
|
assert_count = atoi(args[++argidx].c_str());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (arg == "-clear") {
|
if (arg == "-clear") {
|
||||||
clear_mode = true;
|
clear_mode = true;
|
||||||
continue;
|
continue;
|
||||||
|
@ -1091,14 +1100,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 > 1)
|
if (add_mode + del_mode + assert_none + assert_any + (assert_count >= 0) > 1)
|
||||||
log_cmd_error("Options -add, -del, -assert-none or -assert-any can not be combined.\n");
|
log_cmd_error("Options -add, -del, -assert-none, -assert-any or -assert-count can not be combined.\n");
|
||||||
|
|
||||||
if ((list_mode || !write_file.empty() || count_mode) && (add_mode || del_mode || assert_none || assert_any))
|
if ((list_mode || !write_file.empty() || count_mode) && (add_mode || del_mode || assert_none || assert_any || assert_count >= 0))
|
||||||
log_cmd_error("Options -list, -write and -count can not be combined with -add, -del, -assert-none or -assert-any.\n");
|
log_cmd_error("Options -list, -write and -count can not be combined with -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))
|
if (!set_name.empty() && (list_mode || !write_file.empty() || count_mode || add_mode || del_mode || assert_none || assert_any || assert_count >= 0))
|
||||||
log_cmd_error("Option -set can not be combined with -list, -write, -count, -add, -del, -assert-none or -assert-any.\n");
|
log_cmd_error("Option -set can not be combined with -list, -write, -count, -add, -del, -assert-none, -assert-any or -assert-count.\n");
|
||||||
|
|
||||||
if (work_stack.size() == 0 && got_module) {
|
if (work_stack.size() == 0 && got_module) {
|
||||||
RTLIL::Selection sel;
|
RTLIL::Selection sel;
|
||||||
|
@ -1201,6 +1210,34 @@ struct SelectPass : public Pass {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (assert_count >= 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_count != total_count)
|
||||||
|
log_error("Assertation failed: selection contains %d elements instead of the asserted %d:%s\n",
|
||||||
|
total_count, assert_count, sel_str.c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!set_name.empty())
|
if (!set_name.empty())
|
||||||
{
|
{
|
||||||
if (work_stack.size() == 0)
|
if (work_stack.size() == 0)
|
||||||
|
|
Loading…
Reference in New Issue