From 3e21f894f4cbf843fbf3c9d1603886e63f2a8d5b Mon Sep 17 00:00:00 2001 From: David Shah Date: Fri, 15 Nov 2019 18:04:02 +0000 Subject: [PATCH] frontend: Improved error handling and fixes Signed-off-by: David Shah --- frontend/frontend_base.h | 9 ++++++++- frontend/json_frontend.cc | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/frontend_base.h b/frontend/frontend_base.h index 3484b5b4..40d03863 100644 --- a/frontend/frontend_base.h +++ b/frontend/frontend_base.h @@ -104,6 +104,7 @@ #include "design_utils.h" #include "log.h" #include "nextpnr.h" +#include "util.h" NEXTPNR_NAMESPACE_BEGIN namespace { @@ -193,8 +194,14 @@ template struct GenericFrontend for (auto &mod : mods) for (auto &c : mod.second.instantiated_celltypes) candidate_top.erase(c); - if (candidate_top.size() != 1) + if (candidate_top.size() != 1) { + if (candidate_top.size() == 0) + log_info("No candidate top level modules.\n"); + else + for (auto ctp : sorted(candidate_top)) + log_info("Candidate top module: '%s'\n", ctx->nameOf(ctp)); log_error("Failed to autodetect top module, please specify using --top.\n"); + } top = *(candidate_top.begin()); } diff --git a/frontend/json_frontend.cc b/frontend/json_frontend.cc index 37c1dabd..2eb0a39b 100644 --- a/frontend/json_frontend.cc +++ b/frontend/json_frontend.cc @@ -181,6 +181,10 @@ bool parse_json(std::istream &in, const std::string &filename, Context *ctx) root = Json::parse(json_str, error, JsonParse::COMMENTS); if (root.is_null()) log_error("Failed to parse JSON file '%s': %s.\n", filename.c_str(), error.c_str()); + root = root["modules"]; + if (root.is_null()) + log_error("JSON file '%s' doesn't look like a netlist (doesn't contain \"modules\" key)\n", + filename.c_str()); } GenericFrontend(ctx, JsonFrontendImpl(root))(); return true;