diff options
author | Miodrag Milanovic <mmicko@gmail.com> | 2019-06-07 16:11:11 +0200 |
---|---|---|
committer | Miodrag Milanovic <mmicko@gmail.com> | 2019-06-07 16:11:11 +0200 |
commit | d9b0bac248a12466cd2b62d02ec11b2e60d25019 (patch) | |
tree | 2ab86f7b951134cda53cf24d31c3007a0c218d25 /json | |
parent | ef1a5fa60653a89fe008288aa4da00c481db2c46 (diff) | |
download | nextpnr-d9b0bac248a12466cd2b62d02ec11b2e60d25019.tar.gz nextpnr-d9b0bac248a12466cd2b62d02ec11b2e60d25019.tar.bz2 nextpnr-d9b0bac248a12466cd2b62d02ec11b2e60d25019.zip |
Save top level attrs and store current step
Diffstat (limited to 'json')
-rw-r--r-- | json/jsonparse.cc | 30 | ||||
-rw-r--r-- | json/jsonwrite.cc | 8 |
2 files changed, 35 insertions, 3 deletions
diff --git a/json/jsonparse.cc b/json/jsonparse.cc index 1ff4f5af..a36f891d 100644 --- a/json/jsonparse.cc +++ b/json/jsonparse.cc @@ -355,6 +355,27 @@ void json_import_net_attrib(Context *ctx, string &modname, NetInfo *net, JsonNod pId.c_str(ctx), net->attrs[pId].c_str(), net->name.c_str(ctx), modname.c_str()); } +void json_import_top_attrib(Context *ctx, string &modname, JsonNode *param_node, + std::unordered_map<IdString, Property> *dest, int param_id) +{ + // + JsonNode *param; + IdString pId; + // + param = param_node->data_dict.at(param_node->data_dict_keys[param_id]); + + pId = ctx->id(param_node->data_dict_keys[param_id]); + if (param->type == 'N') { + (*dest)[pId].setNumber(param->data_number); + } else if (param->type == 'S') + (*dest)[pId].setString(param->data_string); + else + log_error("JSON parameter type of \"%s\' of module not supported\n", pId.c_str(ctx)); + if (json_debug) + log_info(" Added parameter \'%s\'=%s module \'%s\'\n", + pId.c_str(ctx), (*dest)[pId].c_str(), modname.c_str()); +} + static int const_net_idx = 0; template <typename F> @@ -714,7 +735,14 @@ void json_import(Context *ctx, string modname, JsonNode *node) return; log_info("Importing module %s\n", modname.c_str()); - + ctx->attrs[ctx->id("module")] = modname; + JsonNode *attr_node = node->data_dict.at("attributes"); + for (int attrid = 0; attrid < GetSize(attr_node->data_dict_keys); attrid++) { + json_import_top_attrib(ctx, modname, attr_node, &ctx->attrs, attrid); + } + if (ctx->attrs.find(ctx->id("step")) == ctx->attrs.end()) + ctx->attrs[ctx->id("step")] = "synth"; + JsonNode *ports_parent = nullptr; if (node->data_dict.count("ports") > 0) ports_parent = node->data_dict.at("ports"); diff --git a/json/jsonwrite.cc b/json/jsonwrite.cc index 811a2eec..19c43d7c 100644 --- a/json/jsonwrite.cc +++ b/json/jsonwrite.cc @@ -64,13 +64,17 @@ void write_parameters(std::ostream &f, Context *ctx, const std::unordered_map<Id void write_module(std::ostream &f, Context *ctx) { - f << stringf(" %s: {\n", get_string("top").c_str()); + auto val = ctx->attrs.find(ctx->id("module")); + if (val != ctx->attrs.end()) + f << stringf(" %s: {\n", get_string(val->second.str).c_str()); + else + f << stringf(" %s: {\n", get_string("top").c_str()); // TODO: check if this is better to be separate /*f << stringf(" \"settings\": {"); write_parameters(f, ctx, ctx->settings, true); f << stringf("\n },\n");*/ f << stringf(" \"attributes\": {"); - // TODO: Top level attributes + write_parameters(f, ctx, ctx->attrs, true); f << stringf("\n },\n"); f << stringf(" \"ports\": {"); // TODO: Top level ports |