mirror of https://github.com/YosysHQ/yosys.git
connect: Add -assert option, fix non-working sigmap.
Should be useful for writing tests.
This commit is contained in:
parent
5c1e6a0e20
commit
a6081b46ce
|
@ -60,7 +60,7 @@ struct ConnectPass : public Pass {
|
|||
log("Unconnect all existing drivers for the specified expression.\n");
|
||||
log("\n");
|
||||
log("\n");
|
||||
log(" connect [-nomap] -port <cell> <port> <expr>\n");
|
||||
log(" connect [-nomap] [-assert] -port <cell> <port> <expr>\n");
|
||||
log("\n");
|
||||
log("Connect the specified cell port to the specified cell port.\n");
|
||||
log("\n");
|
||||
|
@ -72,6 +72,9 @@ struct ConnectPass : public Pass {
|
|||
log("The connect command operates in one module only. Either only one module must\n");
|
||||
log("be selected or an active module must be set using the 'cd' command.\n");
|
||||
log("\n");
|
||||
log("The -assert option verifies that the connection already exists, instead of\n");
|
||||
log("making it.\n");
|
||||
log("\n");
|
||||
log("This command does not operate on module with processes.\n");
|
||||
log("\n");
|
||||
}
|
||||
|
@ -88,7 +91,7 @@ struct ConnectPass : public Pass {
|
|||
if (!module->processes.empty())
|
||||
log_cmd_error("Found processes in selected module.\n");
|
||||
|
||||
bool flag_nounset = false, flag_nomap = false;
|
||||
bool flag_nounset = false, flag_nomap = false, flag_assert = false;
|
||||
std::string set_lhs, set_rhs, unset_expr;
|
||||
std::string port_cell, port_port, port_expr;
|
||||
|
||||
|
@ -104,6 +107,10 @@ struct ConnectPass : public Pass {
|
|||
flag_nomap = true;
|
||||
continue;
|
||||
}
|
||||
if (arg == "-assert") {
|
||||
flag_assert = true;
|
||||
continue;
|
||||
}
|
||||
if (arg == "-set" && argidx+2 < args.size()) {
|
||||
set_lhs = args[++argidx];
|
||||
set_rhs = args[++argidx];
|
||||
|
@ -126,7 +133,7 @@ struct ConnectPass : public Pass {
|
|||
if (!flag_nomap)
|
||||
for (auto &it : module->connections()) {
|
||||
std::vector<RTLIL::SigBit> lhs = it.first.to_sigbit_vector();
|
||||
std::vector<RTLIL::SigBit> rhs = it.first.to_sigbit_vector();
|
||||
std::vector<RTLIL::SigBit> rhs = it.second.to_sigbit_vector();
|
||||
for (size_t i = 0; i < lhs.size(); i++)
|
||||
if (rhs[i].wire != nullptr)
|
||||
sigmap.add(lhs[i], rhs[i]);
|
||||
|
@ -137,6 +144,9 @@ struct ConnectPass : public Pass {
|
|||
if (!unset_expr.empty() || !port_cell.empty())
|
||||
log_cmd_error("Can't use -set together with -unset and/or -port.\n");
|
||||
|
||||
if (flag_assert)
|
||||
log_cmd_error("The -assert option is only supported with -port.\n");
|
||||
|
||||
RTLIL::SigSpec sig_lhs, sig_rhs;
|
||||
if (!RTLIL::SigSpec::parse_sel(sig_lhs, design, module, set_lhs))
|
||||
log_cmd_error("Failed to parse set lhs expression `%s'.\n", set_lhs.c_str());
|
||||
|
@ -157,6 +167,9 @@ struct ConnectPass : public Pass {
|
|||
if (!port_cell.empty() || flag_nounset)
|
||||
log_cmd_error("Can't use -unset together with -port and/or -nounset.\n");
|
||||
|
||||
if (flag_assert)
|
||||
log_cmd_error("The -assert option is only supported with -port.\n");
|
||||
|
||||
RTLIL::SigSpec sig;
|
||||
if (!RTLIL::SigSpec::parse_sel(sig, design, module, unset_expr))
|
||||
log_cmd_error("Failed to parse unset expression `%s'.\n", unset_expr.c_str());
|
||||
|
@ -177,7 +190,14 @@ struct ConnectPass : public Pass {
|
|||
if (!RTLIL::SigSpec::parse_sel(sig, design, module, port_expr))
|
||||
log_cmd_error("Failed to parse port expression `%s'.\n", port_expr.c_str());
|
||||
|
||||
module->cell(RTLIL::escape_id(port_cell))->setPort(RTLIL::escape_id(port_port), sigmap(sig));
|
||||
if (!flag_assert) {
|
||||
module->cell(RTLIL::escape_id(port_cell))->setPort(RTLIL::escape_id(port_port), sigmap(sig));
|
||||
} else {
|
||||
SigSpec cur = module->cell(RTLIL::escape_id(port_cell))->getPort(RTLIL::escape_id(port_port));
|
||||
if (sigmap(sig) != sigmap(cur)) {
|
||||
log_cmd_error("Expected connection not present: expected %s, found %s.\n", log_signal(sig), log_signal(cur));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
log_cmd_error("Expected -set, -unset, or -port.\n");
|
||||
|
|
Loading…
Reference in New Issue