aboutsummaryrefslogtreecommitdiffstats
path: root/json
diff options
context:
space:
mode:
authorMiodrag Milanovic <mmicko@gmail.com>2019-06-13 20:42:11 +0200
committerMiodrag Milanovic <mmicko@gmail.com>2019-06-13 20:42:11 +0200
commit03dff10cbde4c55e4ac9b53a01ba84f4bdac169b (patch)
tree9777bd23e29585b8dbf10cfb64f41823c4c1f67c /json
parent4de147d9e42d7c932773544011a36e4550530a9e (diff)
downloadnextpnr-03dff10cbde4c55e4ac9b53a01ba84f4bdac169b.tar.gz
nextpnr-03dff10cbde4c55e4ac9b53a01ba84f4bdac169b.tar.bz2
nextpnr-03dff10cbde4c55e4ac9b53a01ba84f4bdac169b.zip
Load properties from json and propagate to context create
Diffstat (limited to 'json')
-rw-r--r--json/jsonparse.cc49
-rw-r--r--json/jsonparse.h2
2 files changed, 50 insertions, 1 deletions
diff --git a/json/jsonparse.cc b/json/jsonparse.cc
index df8f45db..a6b45282 100644
--- a/json/jsonparse.cc
+++ b/json/jsonparse.cc
@@ -914,4 +914,53 @@ bool parse_json_file(std::istream &f, std::string &filename, Context *ctx)
}
}
+bool load_json_settings(std::istream &f, std::string &filename, std::unordered_map<std::string,Property> &values)
+{
+ try {
+ using namespace JsonParser;
+
+ if (!f)
+ log_error("failed to open JSON file.\n");
+
+ int lineno = 1;
+
+ JsonNode root(f, lineno);
+
+ 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 (modules->type != 'D')
+ log_error("JSON modules node is not a dictionary.\n");
+
+ for (auto &it : modules->data_dict) {
+ JsonNode *node = it.second;
+ if (is_blackbox(node))
+ continue;
+
+ if (node->data_dict.count("settings")) {
+ JsonNode *attr_node = node->data_dict.at("settings");
+ for (int attrid = 0; attrid < GetSize(attr_node->data_dict_keys); attrid++) {
+ JsonNode *param = attr_node->data_dict.at(attr_node->data_dict_keys[attrid]);
+ std::string pId = attr_node->data_dict_keys[attrid];
+ if (param->type == 'N') {
+ values[pId].setNumber(param->data_number);
+ } else if (param->type == 'S')
+ values[pId].setString(param->data_string);
+ else
+ log_error("JSON parameter type of \"%s\' of module not supported\n", pId.c_str());
+
+ }
+ }
+ }
+ }
+
+ return true;
+ } catch (log_execution_error_exception) {
+ return false;
+ }
+}
+
NEXTPNR_NAMESPACE_END
diff --git a/json/jsonparse.h b/json/jsonparse.h
index fe71444f..ca971e5f 100644
--- a/json/jsonparse.h
+++ b/json/jsonparse.h
@@ -27,7 +27,7 @@
NEXTPNR_NAMESPACE_BEGIN
extern bool parse_json_file(std::istream &, std::string &, Context *);
-
+extern bool load_json_settings(std::istream &f, std::string &filename, std::unordered_map<std::string,Property> &values);
NEXTPNR_NAMESPACE_END
#endif