Merge pull request #281 from whitequark/prefer-ports-as-netlabel

When choosing between labels for one net, always prefer ports
This commit is contained in:
David Shah 2019-05-29 21:35:15 +01:00 committed by GitHub
commit 150004e393
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -692,11 +692,22 @@ void json_import(Context *ctx, string modname, JsonNode *node)
log_info("Importing module %s\n", modname.c_str()); log_info("Importing module %s\n", modname.c_str());
JsonNode *ports_parent = nullptr;
if (node->data_dict.count("ports") > 0)
ports_parent = node->data_dict.at("ports");
// Multiple labels might refer to the same net. For now we resolve conflicts thus: // Multiple labels might refer to the same net. For now we resolve conflicts thus:
// - (toplevel) ports are always preferred
// - names with fewer $ are always prefered // - names with fewer $ are always prefered
// - between equal $ counts, fewer .s are prefered // - between equal $ counts, fewer .s are prefered
// - ties are resolved alphabetically // - ties are resolved alphabetically
auto prefer_netlabel = [](const std::string &a, const std::string &b) { auto prefer_netlabel = [ports_parent](const std::string &a, const std::string &b) {
if (ports_parent != nullptr) {
if (ports_parent->data_dict.count(a))
return true;
if (ports_parent->data_dict.count(b))
return false;
}
if (b.empty()) if (b.empty())
return true; return true;
long a_dollars = std::count(a.begin(), a.end(), '$'), b_dollars = std::count(b.begin(), b.end(), '$'); long a_dollars = std::count(a.begin(), a.end(), '$'), b_dollars = std::count(b.begin(), b.end(), '$');
@ -753,9 +764,7 @@ void json_import(Context *ctx, string modname, JsonNode *node)
} }
} }
if (node->data_dict.count("ports")) { if (ports_parent != nullptr) {
JsonNode *ports_parent = node->data_dict.at("ports");
// N.B. ports must be imported after cells for tristate behaviour // N.B. ports must be imported after cells for tristate behaviour
// to be correct // to be correct
// Loop through all ports, first non-tristate then tristate to handle // Loop through all ports, first non-tristate then tristate to handle

2
tests

@ -1 +1 @@
Subproject commit 0d369eb3fe3425fa74c0f6309268a012aac50409 Subproject commit 5182fd4bec49a568cc3fa37d62d9f9a82f280917