From d49eb2ba40a4c1eb429d67c811c5a5ebc1c22015 Mon Sep 17 00:00:00 2001 From: Eddie Hung Date: Fri, 19 Apr 2019 09:27:34 -0700 Subject: Changes to cope with YosysHQ/yosys#943 --- json/jsonparse.cc | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'json') diff --git a/json/jsonparse.cc b/json/jsonparse.cc index a0479c2e..5d77c101 100644 --- a/json/jsonparse.cc +++ b/json/jsonparse.cc @@ -285,7 +285,7 @@ void vcc_net(Context *ctx, NetInfo *net) // true, false otherwise bool is_blackbox(JsonNode *node) { - JsonNode *attr_node, *bbox_node; + JsonNode *attr_node, *bbox_node = nullptr, *wbox_node = nullptr; if (node->data_dict.count("attributes") == 0) return false; @@ -296,14 +296,19 @@ bool is_blackbox(JsonNode *node) return false; if (GetSize(attr_node->data_dict) == 0) return false; - if (attr_node->data_dict.count("blackbox") == 0) + if (attr_node->data_dict.count("blackbox")) + bbox_node = attr_node->data_dict.at("blackbox"); + if (attr_node->data_dict.count("whitebox")) + wbox_node = attr_node->data_dict.at("whitebox"); + if (bbox_node == NULL && wbox_node == NULL) return false; - bbox_node = attr_node->data_dict.at("blackbox"); - if (bbox_node == NULL) + if (bbox_node && bbox_node->type != 'N') + log_error("JSON module blackbox attribute value is not a number\n"); + if (bbox_node && bbox_node->data_number == 0) return false; - if (bbox_node->type != 'N') - log_error("JSON module blackbox is not a number\n"); - if (bbox_node->data_number == 0) + if (wbox_node && wbox_node->type != 'N') + log_error("JSON module whitebox attribute value is not a number\n"); + if (wbox_node && wbox_node->data_number == 0) return false; return true; } -- cgit v1.2.3 From 5cb9735735ae3a3e93a08951d59578f6104da9a9 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 21 Jun 2019 20:12:24 +0200 Subject: Add support for upto and offset in JSON files --- json/jsonparse.cc | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'json') diff --git a/json/jsonparse.cc b/json/jsonparse.cc index eec7041c..6b6c6317 100644 --- a/json/jsonparse.cc +++ b/json/jsonparse.cc @@ -337,7 +337,7 @@ static int const_net_idx = 0; template void json_import_ports(Context *ctx, const string &modname, const std::vector &netnames, const string &obj_name, const string &port_name, JsonNode *dir_node, JsonNode *wire_group_node, - F visitor) + bool upto, int start_offset, F visitor) { // Examine a port of a cell or the design. For every bit of the port, // the connected net will be processed and `visitor` will be called @@ -406,8 +406,11 @@ void json_import_ports(Context *ctx, const string &modname, const std::vectordata_array[index]; // // Pick a name for this port + int ndx = index + start_offset; + if (!upto) + ndx = start_offset + wire_group_node->data_array.size() - index - 1; if (is_bus) - this_port.name = ctx->id(port_info.name.str(ctx) + "[" + std::to_string(index) + "]"); + this_port.name = ctx->id(port_info.name.str(ctx) + "[" + std::to_string(ndx) + "]"); else this_port.name = port_info.name; this_port.type = port_info.type; @@ -584,7 +587,7 @@ void json_import_cell(Context *ctx, string modname, const std::vector dir_node = pdir_node->data_dict.at(port_name); wire_group_node = connections->data_dict.at(port_name); - json_import_ports(ctx, modname, netnames, cell->name.str(ctx), port_name, dir_node, wire_group_node, + json_import_ports(ctx, modname, netnames, cell->name.str(ctx), port_name, dir_node, wire_group_node, false, 0, [&cell, ctx](PortType type, const std::string &name, NetInfo *net) { cell->ports[ctx->id(name)] = PortInfo{ctx->id(name), net, type}; PortRef pr; @@ -680,8 +683,20 @@ void json_import_toplevel_port(Context *ctx, const string &modname, const std::v { JsonNode *dir_node = node->data_dict.at("direction"); JsonNode *nets_node = node->data_dict.at("bits"); + bool upto = false; + int start_offset = 0; + if (node->data_dict.count("upto") != 0) { + JsonNode *val = node->data_dict.at("upto"); + if (val->type == 'N') + upto = val->data_number != 0; + } + if (node->data_dict.count("offset") != 0) { + JsonNode *val = node->data_dict.at("offset"); + if (val->type == 'N') + start_offset = val->data_number; + } json_import_ports( - ctx, modname, netnames, "Top Level IO", portname, dir_node, nets_node, + ctx, modname, netnames, "Top Level IO", portname, dir_node, nets_node, upto, start_offset, [ctx](PortType type, const std::string &name, NetInfo *net) { insert_iobuf(ctx, net, type, name); }); } @@ -732,6 +747,18 @@ void json_import(Context *ctx, string modname, JsonNode *node) here = cell_parent->data_dict.at(cell_parent->data_dict_keys[nnid]); std::string basename = cell_parent->data_dict_keys[nnid]; + bool upto = false; + int start_offset = 0; + if (here->data_dict.count("upto") != 0) { + JsonNode *val = here->data_dict.at("upto"); + if (val->type == 'N') + upto = val->data_number != 0; + } + if (here->data_dict.count("offset") != 0) { + JsonNode *val = here->data_dict.at("offset"); + if (val->type == 'N') + start_offset = val->data_number; + } if (here->data_dict.count("bits")) { JsonNode *bits = here->data_dict.at("bits"); assert(bits->type == 'A'); @@ -740,8 +767,11 @@ void json_import(Context *ctx, string modname, JsonNode *node) int netid = bits->data_array.at(i)->data_number; if (netid >= int(netlabels.size())) netlabels.resize(netid + 1); + int ndx = i + start_offset; + if (!upto) + ndx = start_offset + num_bits - i - 1; std::string name = - basename + (num_bits == 1 ? "" : std::string("[") + std::to_string(i) + std::string("]")); + basename + (num_bits == 1 ? "" : std::string("[") + std::to_string(ndx) + std::string("]")); if (prefer_netlabel(name, netlabels.at(netid))) netlabels.at(netid) = name; } -- cgit v1.2.3 From bc1450a5cdc55abbc20775c9372131f97f66afd7 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sat, 22 Jun 2019 09:30:35 +0200 Subject: Reversed logic --- json/jsonparse.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'json') diff --git a/json/jsonparse.cc b/json/jsonparse.cc index 6b6c6317..1a98f53f 100644 --- a/json/jsonparse.cc +++ b/json/jsonparse.cc @@ -407,7 +407,7 @@ void json_import_ports(Context *ctx, const string &modname, const std::vectordata_array.size() - index - 1; if (is_bus) this_port.name = ctx->id(port_info.name.str(ctx) + "[" + std::to_string(ndx) + "]"); @@ -768,7 +768,7 @@ void json_import(Context *ctx, string modname, JsonNode *node) if (netid >= int(netlabels.size())) netlabels.resize(netid + 1); int ndx = i + start_offset; - if (!upto) + if (upto) ndx = start_offset + num_bits - i - 1; std::string name = basename + (num_bits == 1 ? "" : std::string("[") + std::to_string(ndx) + std::string("]")); -- cgit v1.2.3 From 560e3899d8ffe8952cd61067c3b42a4a0b885638 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Mon, 24 Jun 2019 10:09:25 +0200 Subject: Fix formatting --- json/jsonparse.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'json') diff --git a/json/jsonparse.cc b/json/jsonparse.cc index 1a98f53f..0f229aca 100644 --- a/json/jsonparse.cc +++ b/json/jsonparse.cc @@ -750,15 +750,15 @@ void json_import(Context *ctx, string modname, JsonNode *node) bool upto = false; int start_offset = 0; if (here->data_dict.count("upto") != 0) { - JsonNode *val = here->data_dict.at("upto"); - if (val->type == 'N') - upto = val->data_number != 0; - } - if (here->data_dict.count("offset") != 0) { - JsonNode *val = here->data_dict.at("offset"); - if (val->type == 'N') - start_offset = val->data_number; - } + JsonNode *val = here->data_dict.at("upto"); + if (val->type == 'N') + upto = val->data_number != 0; + } + if (here->data_dict.count("offset") != 0) { + JsonNode *val = here->data_dict.at("offset"); + if (val->type == 'N') + start_offset = val->data_number; + } if (here->data_dict.count("bits")) { JsonNode *bits = here->data_dict.at("bits"); assert(bits->type == 'A'); -- cgit v1.2.3