From a0c9a70a5e6717aea37092720c899a463e482922 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sun, 26 May 2019 16:44:34 +0000 Subject: When choosing between labels for one net, always prefer ports. 1. Ports are already used in PCF and LPF files, so it is natural that the developer would use them for constraints as well. 2. Unpredictable (the set of netlabels nextpnr looks at depends on the optimizations during synthesis) net naming makes it impossible for code generators like nMigen to reliably apply clock constraints. --- json/jsonparse.cc | 17 +++++++++++++---- tests | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/json/jsonparse.cc b/json/jsonparse.cc index a0479c2e..eec7041c 100644 --- a/json/jsonparse.cc +++ b/json/jsonparse.cc @@ -692,11 +692,22 @@ void json_import(Context *ctx, string modname, JsonNode *node) 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: + // - (toplevel) ports are always preferred // - names with fewer $ are always prefered // - between equal $ counts, fewer .s are prefered // - 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()) return true; 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")) { - JsonNode *ports_parent = node->data_dict.at("ports"); - + if (ports_parent != nullptr) { // N.B. ports must be imported after cells for tristate behaviour // to be correct // Loop through all ports, first non-tristate then tristate to handle diff --git a/tests b/tests index 0d369eb3..5182fd4b 160000 --- a/tests +++ b/tests @@ -1 +1 @@ -Subproject commit 0d369eb3fe3425fa74c0f6309268a012aac50409 +Subproject commit 5182fd4bec49a568cc3fa37d62d9f9a82f280917 -- cgit v1.2.3