From c33a039ac388bfcb5e068a04a7cb1b05ebec7d7f Mon Sep 17 00:00:00 2001
From: Miodrag Milanovic <mmicko@gmail.com>
Date: Thu, 21 Jun 2018 18:08:28 +0200
Subject: Added return code to json parsing  and pcf reading

---
 frontend/json/jsonparse.cc | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

(limited to 'frontend/json/jsonparse.cc')

diff --git a/frontend/json/jsonparse.cc b/frontend/json/jsonparse.cc
index 7d9e9dcf..a832e9e5 100644
--- a/frontend/json/jsonparse.cc
+++ b/frontend/json/jsonparse.cc
@@ -797,27 +797,32 @@ void json_import(Context *ctx, string modname, JsonNode *node)
 }
 }; // End Namespace JsonParser
 
-void parse_json_file(std::istream &f, std::string &filename, Context *ctx)
+bool parse_json_file(std::istream &f, std::string &filename, Context *ctx)
 {
-    using namespace JsonParser;
+    try {
+        using namespace JsonParser;
 
-    JsonNode root(f);
+        JsonNode root(f);
 
-    if (root.type != 'D')
-        log_error("JSON root node is not a dictionary.\n");
+        if (root.type != 'D')
+            log_error("JSON root node is not a dictionary.\n");
 
-    if (root.data_dict.count("modules") != 0) {
-        JsonNode *modules = root.data_dict.at("modules");
+        if (root.data_dict.count("modules") != 0) {
+            JsonNode *modules = root.data_dict.at("modules");
 
-        if (modules->type != 'D')
-            log_error("JSON modules node is not a dictionary.\n");
+            if (modules->type != 'D')
+                log_error("JSON modules node is not a dictionary.\n");
 
-        for (auto &it : modules->data_dict)
-            json_import(ctx, it.first, it.second);
-    }
+            for (auto &it : modules->data_dict)
+                json_import(ctx, it.first, it.second);
+        }
 
-    log_info("Checksum: 0x%08x\n", ctx->checksum());
-    log_break();
+        log_info("Checksum: 0x%08x\n", ctx->checksum());
+        log_break();
+        return true;
+    } catch (log_execution_error_exception) {
+        return false;
+    }
 }
 
 NEXTPNR_NAMESPACE_END
-- 
cgit v1.2.3