From 81b176e1504a05da65fd5989c3a2d2f389786ab0 Mon Sep 17 00:00:00 2001 From: David Shah Date: Mon, 25 Feb 2019 14:40:38 +0000 Subject: [PATCH 1/3] ecp5: Improve error handling and warning generation in LPF parser Signed-off-by: David Shah --- ecp5/lpf.cc | 50 +++++++++++++++++++++++++++++++------------------- ecp5/main.cc | 5 ++++- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/ecp5/lpf.cc b/ecp5/lpf.cc index df3687cf..b561807d 100644 --- a/ecp5/lpf.cc +++ b/ecp5/lpf.cc @@ -41,7 +41,9 @@ bool Arch::applyLPF(std::string filename, std::istream &in) log_error("failed to open LPF file\n"); std::string line; std::string linebuf; + int lineno = 0; while (std::getline(in, line)) { + ++lineno; size_t cstart = line.find('#'); if (cstart != std::string::npos) line = line.substr(0, cstart); @@ -61,15 +63,18 @@ bool Arch::applyLPF(std::string filename, std::istream &in) if (words.size() >= 0) { std::string verb = words.at(0); if (verb == "BLOCK" || verb == "SYSCONFIG") { - log_warning(" ignoring unsupported LPF command '%s'\n", command.c_str()); + if (words.size() != 2 || (words.at(1) != "ASYNCPATHS" && words.at(1) != "RESETPATHS")) + log_warning(" ignoring unsupported LPF command '%s' (on line %d)\n", command.c_str(), + lineno); } else if (verb == "FREQUENCY") { + if (words.size() < 2) + log_error("expected object type after FREQUENCY (on line %d)\n", lineno); std::string etype = words.at(1); if (etype == "PORT" || etype == "NET") { - std::string target = words.at(2); - if (target.at(0) == '\"') { - NPNR_ASSERT(target.back() == '\"'); - target = target.substr(1, target.length() - 2); - } + if (words.size() < 4) + log_error("expected frequency value and unit after 'FREQUENCY %s' (on line %d)\n", + etype.c_str(), lineno); + std::string target = strip_quotes(words.at(2)); float freq = std::stof(words.at(3)); std::string unit = words.at(4); if (unit == "MHz") @@ -79,33 +84,40 @@ bool Arch::applyLPF(std::string filename, std::istream &in) else if (unit == "Hz") freq /= 1.0e6; else - log_error("unsupported frequency unit '%s'\n", unit.c_str()); + log_error("unsupported frequency unit '%s' (on line %d)\n", unit.c_str(), lineno); addClock(id(target), freq); } else { - log_warning(" ignoring unsupported LPF command '%s %s'\n", command.c_str(), - etype.c_str()); + log_warning(" ignoring unsupported LPF command '%s %s' (on line %d)\n", command.c_str(), + etype.c_str(), lineno); } } else if (verb == "LOCATE") { - NPNR_ASSERT(words.at(1) == "COMP"); + if (words.size() < 5) + log_error("expected syntax 'LOCATE COMP SITE ' (on line %d)\n", lineno); + if (words.at(1) != "COMP") + log_error("expected 'COMP' after 'LOCATE' (on line %d)\n", lineno); std::string cell = strip_quotes(words.at(2)); - NPNR_ASSERT(words.at(3) == "SITE"); + if (words.at(3) != "SITE") + log_error("expected 'SITE' after 'LOCATE COMP %s' (on line %d)\n", cell.c_str(), lineno); auto fnd_cell = cells.find(id(cell)); - if (fnd_cell == cells.end()) { - log_warning("unmatched LPF 'LOCATE COMP' '%s'\n", cell.c_str()); - } else { + if (fnd_cell != cells.end()) { fnd_cell->second->attrs[id("LOC")] = strip_quotes(words.at(4)); } } else if (verb == "IOBUF") { - NPNR_ASSERT(words.at(1) == "PORT"); + if (words.size() < 3) + log_error("expected syntax 'IOBUF PORT =...' (on line %d)\n", + lineno); + if (words.at(1) != "PORT") + log_error("expected 'PORT' after 'IOBUF' (on line %d)\n", lineno); std::string cell = strip_quotes(words.at(2)); auto fnd_cell = cells.find(id(cell)); - if (fnd_cell == cells.end()) { - log_warning("unmatched LPF 'IOBUF PORT' '%s'\n", cell.c_str()); - } else { + if (fnd_cell != cells.end()) { for (size_t i = 3; i < words.size(); i++) { std::string setting = words.at(i); size_t eqpos = setting.find('='); - NPNR_ASSERT(eqpos != std::string::npos); + if (eqpos == std::string::npos) + log_error( + "expected syntax 'IOBUF PORT =...' (on line %d)\n", + lineno); std::string key = setting.substr(0, eqpos), value = setting.substr(eqpos + 1); fnd_cell->second->attrs[id(key)] = value; } diff --git a/ecp5/main.cc b/ecp5/main.cc index 4f9ac3da..98b6b901 100644 --- a/ecp5/main.cc +++ b/ecp5/main.cc @@ -157,7 +157,10 @@ void ECP5CommandHandler::customAfterLoad(Context *ctx) std::vector files = vm["lpf"].as>(); for (const auto &filename : files) { std::ifstream in(filename); - ctx->applyLPF(filename, in); + if (!in) + log_error("failed to open LPF file '%s'\n", filename.c_str()); + if (!ctx->applyLPF(filename, in)) + log_error("failed to parse LPF file '%s'\n", filename.c_str()); } } } From ba4150aeccb0f0dbdfb9f23d1459077d38b15553 Mon Sep 17 00:00:00 2001 From: David Shah Date: Mon, 25 Feb 2019 14:45:43 +0000 Subject: [PATCH 2/3] ecp5: Add an error for mixed constrained/unconstrained IO Signed-off-by: David Shah --- ecp5/main.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ecp5/main.cc b/ecp5/main.cc index 98b6b901..15027a5a 100644 --- a/ecp5/main.cc +++ b/ecp5/main.cc @@ -25,6 +25,7 @@ #include "design_utils.h" #include "log.h" #include "timing.h" +#include "util.h" USING_NEXTPNR_NAMESPACE @@ -68,6 +69,7 @@ po::options_description ECP5CommandHandler::getArchOptions() specific.add_options()("textcfg", po::value(), "textual configuration in Trellis format to write"); specific.add_options()("lpf", po::value>(), "LPF pin constraint file(s)"); + specific.add_options()("lpf-allow-unconstrained", "don't require LPF file(s) to constrain all IO"); return specific; } @@ -162,6 +164,22 @@ void ECP5CommandHandler::customAfterLoad(Context *ctx) if (!ctx->applyLPF(filename, in)) log_error("failed to parse LPF file '%s'\n", filename.c_str()); } + + for (auto cell : sorted(ctx->cells)) { + CellInfo *ci = cell.second; + if (ci->type == ctx->id("$nextpnr_ibuf") || ci->type == ctx->id("$nextpnr_obuf") || + ci->type == ctx->id("$nextpnr_iobuf")) { + if (!ci->attrs.count(ctx->id("LOC"))) { + if (vm.count("lpf-allow-unconstrained")) + log_warning("IO '%s' is unconstrained in LPF and will be automatically placed\n", + cell.first.c_str(ctx)); + else + log_error("IO '%s' is unconstrained in LPF (override this error with " + "--lpf-allow-unconstrained)\n", + cell.first.c_str(ctx)); + } + } + } } } From 8744c46ea0fb5c6428927867447dbe491f340f5b Mon Sep 17 00:00:00 2001 From: David Shah Date: Wed, 27 Feb 2019 22:54:32 +0000 Subject: [PATCH 3/3] ecp5: Fix handling of CRLFs and uppercase frequency units in LPF Signed-off-by: David Shah --- ecp5/lpf.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ecp5/lpf.cc b/ecp5/lpf.cc index b561807d..4ac70fc9 100644 --- a/ecp5/lpf.cc +++ b/ecp5/lpf.cc @@ -17,6 +17,7 @@ * */ +#include #include #include "log.h" @@ -25,7 +26,7 @@ NEXTPNR_NAMESPACE_BEGIN bool Arch::applyLPF(std::string filename, std::istream &in) { auto isempty = [](const std::string &str) { - return std::all_of(str.begin(), str.end(), [](char c) { return isblank(c); }); + return std::all_of(str.begin(), str.end(), [](char c) { return isblank(c) || c == '\r' || c == '\n'; }); }; auto strip_quotes = [](const std::string &str) { if (str.at(0) == '"') { @@ -77,11 +78,12 @@ bool Arch::applyLPF(std::string filename, std::istream &in) std::string target = strip_quotes(words.at(2)); float freq = std::stof(words.at(3)); std::string unit = words.at(4); - if (unit == "MHz") + boost::algorithm::to_upper(unit); + if (unit == "MHZ") ; - else if (unit == "kHz") + else if (unit == "KHZ") freq /= 1.0e3; - else if (unit == "Hz") + else if (unit == "HZ") freq /= 1.0e6; else log_error("unsupported frequency unit '%s' (on line %d)\n", unit.c_str(), lineno);