From 545068dec4a0433d17741b508965a391029e3283 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 31 May 2019 11:09:13 +0200 Subject: Initial work on jsonwrite --- json/jsonwrite.cc | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 json/jsonwrite.cc (limited to 'json/jsonwrite.cc') diff --git a/json/jsonwrite.cc b/json/jsonwrite.cc new file mode 100644 index 00000000..b35a61cf --- /dev/null +++ b/json/jsonwrite.cc @@ -0,0 +1,167 @@ +/* + * nextpnr -- Next Generation Place and Route + * + * Copyright (C) 2018 Miodrag Milanovic + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#include "jsonwrite.h" +#include +#include +#include +#include +#include +#include +#include +#include "nextpnr.h" +#include "version.h" + +NEXTPNR_NAMESPACE_BEGIN + +namespace JsonWriter { + +std::string get_string(std::string str) +{ + std::string newstr = "\""; + for (char c : str) { + if (c == '\\') + newstr += c; + newstr += c; + } + return newstr + "\""; +} + +std::string get_name(IdString name, Context *ctx) +{ + return get_string(name.c_str(ctx)); +} + +void write_parameters(std::ostream &f, Context *ctx, const std::unordered_map ¶meters, bool for_module=false) +{ + bool first = true; + for (auto ¶m : parameters) { + f << stringf("%s\n", first ? "" : ","); + f << stringf(" %s%s: ", for_module ? "" : " ", get_name(param.first,ctx).c_str()); + f << get_string(param.second); + first = false; + } +} +void write_module(std::ostream &f, Context *ctx) +{ + 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 + f << stringf("\n },\n"); + f << stringf(" \"ports\": {"); + // TODO: Top level ports + f << stringf("\n },\n"); + + auto fn = ctx->nets.hash_function(); + + f << stringf(" \"cells\": {"); + bool first = true; + for (auto &pair : ctx->cells) { + auto &c = pair.second; + f << stringf("%s\n", first ? "" : ","); + f << stringf(" %s: {\n", get_name(c->name, ctx).c_str()); + f << stringf(" \"hide_name\": %s,\n", c->name.c_str(ctx)[0] == '$' ? "1" : "0"); + f << stringf(" \"type\": %s,\n", get_name(c->type, ctx).c_str()); + f << stringf(" \"parameters\": {"); + write_parameters(f, ctx, c->params); + f << stringf("\n },\n"); + f << stringf(" \"attributes\": {"); + write_parameters(f, ctx, c->attrs); + f << stringf("\n },\n"); + f << stringf(" \"port_directions\": {"); + bool first2 = true; + for (auto &conn : c->ports) { + auto &p = conn.second; + if (p.net) { + std::string direction = (p.type == PORT_IN) ? "input" : (p.type == PORT_OUT) ? "output" : "inout"; + f << stringf("%s\n", first2 ? "" : ","); + f << stringf(" %s: \"%s\"", get_name(conn.first, ctx).c_str(), direction.c_str()); + first2 = false; + } + } + f << stringf("\n },\n"); + f << stringf(" \"connections\": {"); + first2 = true; + + for (auto &conn : c->ports) { + auto &p = conn.second; + if (p.net) { + f << stringf("%s\n", first2 ? "" : ","); + f << stringf(" %s: %d", get_name(conn.first,ctx).c_str(), fn(p.net->name)); + first2 = false; + } + } + f << stringf("\n }\n"); + + f << stringf(" }"); + first = false; + } + + f << stringf("\n },\n"); + + f << stringf(" \"netnames\": {"); + first = true; + for (auto &pair : ctx->nets) { + auto &w = pair.second; + f << stringf("%s\n", first ? "" : ","); + f << stringf(" %s: {\n", get_name(w->name, ctx).c_str()); + f << stringf(" \"hide_name\": %s,\n", w->name.c_str(ctx)[0] == '$' ? "1" : "0"); + f << stringf(" \"bits\": [ %d ] ,\n", fn(pair.first)); + f << stringf(" \"attributes\": {"); + write_parameters(f, ctx, w->attrs); + f << stringf("\n }\n"); + f << stringf(" }"); + first = false; + } + + f << stringf("\n }\n"); + f << stringf(" }"); +} + +void write_context(std::ostream &f, Context *ctx) +{ + f << stringf("{\n"); + f << stringf(" \"creator\": %s,\n", get_string( "Next Generation Place and Route (git sha1 " GIT_COMMIT_HASH_STR ")").c_str()); + f << stringf(" \"modules\": {\n"); + write_module(f, ctx); + f << stringf("\n }"); + f << stringf("\n}\n"); +} + +}; // End Namespace JsonWriter + +bool write_json_file(std::ostream &f, std::string &filename, Context *ctx) +{ + try { + using namespace JsonWriter; + if (!f) + log_error("failed to open JSON file.\n"); + write_context(f, ctx); + log_break(); + return true; + } catch (log_execution_error_exception) { + return false; + } +} + +NEXTPNR_NAMESPACE_END -- cgit v1.2.3 From 1657479c8153199cbe008aad552ce07b8170293a Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 31 May 2019 11:50:49 +0200 Subject: Solve some of connection issues --- json/jsonwrite.cc | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'json/jsonwrite.cc') diff --git a/json/jsonwrite.cc b/json/jsonwrite.cc index b35a61cf..f41fbebc 100644 --- a/json/jsonwrite.cc +++ b/json/jsonwrite.cc @@ -92,12 +92,10 @@ void write_module(std::ostream &f, Context *ctx) bool first2 = true; for (auto &conn : c->ports) { auto &p = conn.second; - if (p.net) { - std::string direction = (p.type == PORT_IN) ? "input" : (p.type == PORT_OUT) ? "output" : "inout"; - f << stringf("%s\n", first2 ? "" : ","); - f << stringf(" %s: \"%s\"", get_name(conn.first, ctx).c_str(), direction.c_str()); - first2 = false; - } + std::string direction = (p.type == PORT_IN) ? "input" : (p.type == PORT_OUT) ? "output" : "inout"; + f << stringf("%s\n", first2 ? "" : ","); + f << stringf(" %s: \"%s\"", get_name(conn.first, ctx).c_str(), direction.c_str()); + first2 = false; } f << stringf("\n },\n"); f << stringf(" \"connections\": {"); @@ -105,11 +103,13 @@ void write_module(std::ostream &f, Context *ctx) for (auto &conn : c->ports) { auto &p = conn.second; - if (p.net) { - f << stringf("%s\n", first2 ? "" : ","); - f << stringf(" %s: %d", get_name(conn.first,ctx).c_str(), fn(p.net->name)); - first2 = false; - } + f << stringf("%s\n", first2 ? "" : ","); + if (p.net) + f << stringf(" %s: [ %d ]", get_name(conn.first,ctx).c_str(), fn(p.net->name)); + else + f << stringf(" %s: [ ]", get_name(conn.first,ctx).c_str()); + + first2 = false; } f << stringf("\n }\n"); -- cgit v1.2.3 From aa0568628ffb373d07dcf01586ae643500509780 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sat, 1 Jun 2019 11:41:34 +0200 Subject: Add writing routing data to json --- json/jsonwrite.cc | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'json/jsonwrite.cc') diff --git a/json/jsonwrite.cc b/json/jsonwrite.cc index f41fbebc..bedb2449 100644 --- a/json/jsonwrite.cc +++ b/json/jsonwrite.cc @@ -48,7 +48,7 @@ std::string get_name(IdString name, Context *ctx) return get_string(name.c_str(ctx)); } -void write_parameters(std::ostream &f, Context *ctx, const std::unordered_map ¶meters, bool for_module=false) +bool write_parameters(std::ostream &f, Context *ctx, const std::unordered_map ¶meters, bool for_module=false) { bool first = true; for (auto ¶m : parameters) { @@ -57,7 +57,27 @@ void write_parameters(std::ostream &f, Context *ctx, const std::unordered_mapwires) { + routing += first2 ? "" : ";"; + routing += ctx->getWireName(item.first).c_str(ctx); + routing += ","; + if (item.second.pip != PipId()) + routing += ctx->getPipName(item.second.pip).c_str(ctx); + first2 = false; + } + + f << stringf("%s\n", first ? "" : ","); + f << stringf(" \"NEXTPNR_ROUTING\": "); + f << get_string(routing); +} + void write_module(std::ostream &f, Context *ctx) { f << stringf(" %s: {\n", get_string("top").c_str()); @@ -128,7 +148,8 @@ void write_module(std::ostream &f, Context *ctx) f << stringf(" \"hide_name\": %s,\n", w->name.c_str(ctx)[0] == '$' ? "1" : "0"); f << stringf(" \"bits\": [ %d ] ,\n", fn(pair.first)); f << stringf(" \"attributes\": {"); - write_parameters(f, ctx, w->attrs); + bool first2 = write_parameters(f, ctx, w->attrs); + write_routing(f, ctx, w.get(), first2); f << stringf("\n }\n"); f << stringf(" }"); first = false; -- cgit v1.2.3 From d5d8213871d8cb68b2e4ef9b3557879c80ff5b51 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sat, 1 Jun 2019 15:52:32 +0200 Subject: Added support for attributes/properties types --- json/jsonwrite.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'json/jsonwrite.cc') diff --git a/json/jsonwrite.cc b/json/jsonwrite.cc index bedb2449..8c1f914f 100644 --- a/json/jsonwrite.cc +++ b/json/jsonwrite.cc @@ -48,13 +48,16 @@ std::string get_name(IdString name, Context *ctx) return get_string(name.c_str(ctx)); } -bool write_parameters(std::ostream &f, Context *ctx, const std::unordered_map ¶meters, bool for_module=false) +bool write_parameters(std::ostream &f, Context *ctx, const std::unordered_map ¶meters, bool for_module=false) { bool first = true; for (auto ¶m : parameters) { f << stringf("%s\n", first ? "" : ","); f << stringf(" %s%s: ", for_module ? "" : " ", get_name(param.first,ctx).c_str()); - f << get_string(param.second); + if (param.second.isString()) + f << get_string(param.second); + else + f << param.second.num; first = false; } return first; -- cgit v1.2.3 From 1894cb549c368ccd5c932535852d6d9367136865 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sun, 2 Jun 2019 16:46:07 +0200 Subject: preserve constraints --- json/jsonwrite.cc | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'json/jsonwrite.cc') diff --git a/json/jsonwrite.cc b/json/jsonwrite.cc index 8c1f914f..7143bf93 100644 --- a/json/jsonwrite.cc +++ b/json/jsonwrite.cc @@ -81,6 +81,30 @@ void write_routing(std::ostream &f, Context *ctx, NetInfo *net, bool first) f << get_string(routing); } +void write_constraints(std::ostream &f, Context *ctx, CellInfo *cell, bool first) +{ + std::string constr; + constr += std::to_string(cell->constr_x) + ";"; + constr += std::to_string(cell->constr_y) + ";"; + constr += std::to_string(cell->constr_z) + ";"; + constr += std::to_string(cell->constr_abs_z ? 1:0) + ";"; + constr += cell->constr_parent!=nullptr ? cell->constr_parent->name.c_str(ctx) : ""; + f << stringf("%s\n", first ? "" : ","); + f << stringf(" \"NEXTPNR_CONSTRAINT\": "); + f << get_string(constr); + + constr = ""; + for(auto &item : cell->constr_children) + { + if (!constr.empty()) constr += std::string(";"); + constr += item->name.c_str(ctx); + } + f << stringf(",\n"); + f << stringf(" \"NEXTPNR_CONSTR_CHILDREN\": "); + f << get_string(constr); + +} + void write_module(std::ostream &f, Context *ctx) { f << stringf(" %s: {\n", get_string("top").c_str()); @@ -109,7 +133,8 @@ void write_module(std::ostream &f, Context *ctx) write_parameters(f, ctx, c->params); f << stringf("\n },\n"); f << stringf(" \"attributes\": {"); - write_parameters(f, ctx, c->attrs); + bool first3 = write_parameters(f, ctx, c->attrs); + write_constraints(f, ctx, c.get(), first3); f << stringf("\n },\n"); f << stringf(" \"port_directions\": {"); bool first2 = true; @@ -123,7 +148,6 @@ void write_module(std::ostream &f, Context *ctx) f << stringf("\n },\n"); f << stringf(" \"connections\": {"); first2 = true; - for (auto &conn : c->ports) { auto &p = conn.second; f << stringf("%s\n", first2 ? "" : ","); -- cgit v1.2.3 From 82ed1803c726e912730c3053179f179b90c9b694 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Sun, 2 Jun 2019 18:38:20 +0200 Subject: use NEXTPNR_BEL, since BEL is initial placement --- json/jsonwrite.cc | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'json/jsonwrite.cc') diff --git a/json/jsonwrite.cc b/json/jsonwrite.cc index 7143bf93..e62a7d2a 100644 --- a/json/jsonwrite.cc +++ b/json/jsonwrite.cc @@ -102,6 +102,11 @@ void write_constraints(std::ostream &f, Context *ctx, CellInfo *cell, bool first f << stringf(",\n"); f << stringf(" \"NEXTPNR_CONSTR_CHILDREN\": "); f << get_string(constr); + if (cell->bel != BelId()) { + f << stringf(",\n"); + f << stringf(" \"NEXTPNR_BEL\": "); + f << get_string(ctx->getBelName(cell->bel).c_str(ctx)); + } } -- cgit v1.2.3 From 44d6f16b66e5f7b89e8cf5711744d6e5f6a40b4a Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Mon, 3 Jun 2019 21:01:05 +0200 Subject: Support ecp5 read write additional cell info --- json/jsonwrite.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'json/jsonwrite.cc') diff --git a/json/jsonwrite.cc b/json/jsonwrite.cc index e62a7d2a..9f29d510 100644 --- a/json/jsonwrite.cc +++ b/json/jsonwrite.cc @@ -89,6 +89,19 @@ void write_constraints(std::ostream &f, Context *ctx, CellInfo *cell, bool first constr += std::to_string(cell->constr_z) + ";"; constr += std::to_string(cell->constr_abs_z ? 1:0) + ";"; constr += cell->constr_parent!=nullptr ? cell->constr_parent->name.c_str(ctx) : ""; +#ifdef ARCH_ECP5 + constr += ";"; + constr += std::to_string(cell->sliceInfo.using_dff ? 1:0) + ";"; + constr += std::to_string(cell->sliceInfo.has_l6mux ? 1:0) + ";"; + constr += std::to_string(cell->sliceInfo.is_carry ? 1:0) + ";"; + constr += std::string(cell->sliceInfo.clk_sig.c_str(ctx)) + ";"; + constr += std::string(cell->sliceInfo.lsr_sig.c_str(ctx)) + ";"; + constr += std::string(cell->sliceInfo.clkmux.c_str(ctx)) + ";"; + constr += std::string(cell->sliceInfo.lsrmux.c_str(ctx)) + ";"; + constr += std::string(cell->sliceInfo.srmode.c_str(ctx)) + ";"; + constr += std::to_string(cell->sliceInfo.sd0) + ";"; + constr += std::to_string(cell->sliceInfo.sd1) + ";"; +#endif f << stringf("%s\n", first ? "" : ","); f << stringf(" \"NEXTPNR_CONSTRAINT\": "); f << get_string(constr); -- cgit v1.2.3 From d5f804832f1accf318e8f62a9989149f5bc0b34a Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Mon, 3 Jun 2019 21:13:47 +0200 Subject: hacky way to support ECP5 for now --- json/jsonwrite.cc | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'json/jsonwrite.cc') diff --git a/json/jsonwrite.cc b/json/jsonwrite.cc index 9f29d510..eb1ed3a4 100644 --- a/json/jsonwrite.cc +++ b/json/jsonwrite.cc @@ -79,6 +79,11 @@ void write_routing(std::ostream &f, Context *ctx, NetInfo *net, bool first) f << stringf("%s\n", first ? "" : ","); f << stringf(" \"NEXTPNR_ROUTING\": "); f << get_string(routing); +#ifdef ARCH_ECP5 + f << stringf(",\n"); + f << stringf(" \"NEXTPNR_IS_GLOBAL\": "); + f << std::to_string(net->is_global ? 1:0); +#endif } void write_constraints(std::ostream &f, Context *ctx, CellInfo *cell, bool first) -- cgit v1.2.3 From 3ae50f85b15437b92b0ab3e6e9c243ea0556fdfc Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Tue, 4 Jun 2019 20:08:43 +0200 Subject: Use index as unique identifier for nets --- json/jsonwrite.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'json/jsonwrite.cc') diff --git a/json/jsonwrite.cc b/json/jsonwrite.cc index eb1ed3a4..2aaba756 100644 --- a/json/jsonwrite.cc +++ b/json/jsonwrite.cc @@ -142,8 +142,6 @@ void write_module(std::ostream &f, Context *ctx) // TODO: Top level ports f << stringf("\n },\n"); - auto fn = ctx->nets.hash_function(); - f << stringf(" \"cells\": {"); bool first = true; for (auto &pair : ctx->cells) { @@ -175,7 +173,7 @@ void write_module(std::ostream &f, Context *ctx) auto &p = conn.second; f << stringf("%s\n", first2 ? "" : ","); if (p.net) - f << stringf(" %s: [ %d ]", get_name(conn.first,ctx).c_str(), fn(p.net->name)); + f << stringf(" %s: [ %d ]", get_name(conn.first,ctx).c_str(), p.net->name.index); else f << stringf(" %s: [ ]", get_name(conn.first,ctx).c_str()); @@ -196,7 +194,7 @@ void write_module(std::ostream &f, Context *ctx) f << stringf("%s\n", first ? "" : ","); f << stringf(" %s: {\n", get_name(w->name, ctx).c_str()); f << stringf(" \"hide_name\": %s,\n", w->name.c_str(ctx)[0] == '$' ? "1" : "0"); - f << stringf(" \"bits\": [ %d ] ,\n", fn(pair.first)); + f << stringf(" \"bits\": [ %d ] ,\n", pair.first.index); f << stringf(" \"attributes\": {"); bool first2 = write_parameters(f, ctx, w->attrs); write_routing(f, ctx, w.get(), first2); -- cgit v1.2.3 From 1093d7e1228272ca73114bbc4415c48d6cba76ed Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 7 Jun 2019 11:48:15 +0200 Subject: WIP saving/loading attributes --- json/jsonwrite.cc | 74 +++---------------------------------------------------- 1 file changed, 3 insertions(+), 71 deletions(-) (limited to 'json/jsonwrite.cc') diff --git a/json/jsonwrite.cc b/json/jsonwrite.cc index 2aaba756..811a2eec 100644 --- a/json/jsonwrite.cc +++ b/json/jsonwrite.cc @@ -48,7 +48,7 @@ std::string get_name(IdString name, Context *ctx) return get_string(name.c_str(ctx)); } -bool write_parameters(std::ostream &f, Context *ctx, const std::unordered_map ¶meters, bool for_module=false) +void write_parameters(std::ostream &f, Context *ctx, const std::unordered_map ¶meters, bool for_module=false) { bool first = true; for (auto ¶m : parameters) { @@ -60,72 +60,6 @@ bool write_parameters(std::ostream &f, Context *ctx, const std::unordered_mapwires) { - routing += first2 ? "" : ";"; - routing += ctx->getWireName(item.first).c_str(ctx); - routing += ","; - if (item.second.pip != PipId()) - routing += ctx->getPipName(item.second.pip).c_str(ctx); - first2 = false; - } - - f << stringf("%s\n", first ? "" : ","); - f << stringf(" \"NEXTPNR_ROUTING\": "); - f << get_string(routing); -#ifdef ARCH_ECP5 - f << stringf(",\n"); - f << stringf(" \"NEXTPNR_IS_GLOBAL\": "); - f << std::to_string(net->is_global ? 1:0); -#endif -} - -void write_constraints(std::ostream &f, Context *ctx, CellInfo *cell, bool first) -{ - std::string constr; - constr += std::to_string(cell->constr_x) + ";"; - constr += std::to_string(cell->constr_y) + ";"; - constr += std::to_string(cell->constr_z) + ";"; - constr += std::to_string(cell->constr_abs_z ? 1:0) + ";"; - constr += cell->constr_parent!=nullptr ? cell->constr_parent->name.c_str(ctx) : ""; -#ifdef ARCH_ECP5 - constr += ";"; - constr += std::to_string(cell->sliceInfo.using_dff ? 1:0) + ";"; - constr += std::to_string(cell->sliceInfo.has_l6mux ? 1:0) + ";"; - constr += std::to_string(cell->sliceInfo.is_carry ? 1:0) + ";"; - constr += std::string(cell->sliceInfo.clk_sig.c_str(ctx)) + ";"; - constr += std::string(cell->sliceInfo.lsr_sig.c_str(ctx)) + ";"; - constr += std::string(cell->sliceInfo.clkmux.c_str(ctx)) + ";"; - constr += std::string(cell->sliceInfo.lsrmux.c_str(ctx)) + ";"; - constr += std::string(cell->sliceInfo.srmode.c_str(ctx)) + ";"; - constr += std::to_string(cell->sliceInfo.sd0) + ";"; - constr += std::to_string(cell->sliceInfo.sd1) + ";"; -#endif - f << stringf("%s\n", first ? "" : ","); - f << stringf(" \"NEXTPNR_CONSTRAINT\": "); - f << get_string(constr); - - constr = ""; - for(auto &item : cell->constr_children) - { - if (!constr.empty()) constr += std::string(";"); - constr += item->name.c_str(ctx); - } - f << stringf(",\n"); - f << stringf(" \"NEXTPNR_CONSTR_CHILDREN\": "); - f << get_string(constr); - if (cell->bel != BelId()) { - f << stringf(",\n"); - f << stringf(" \"NEXTPNR_BEL\": "); - f << get_string(ctx->getBelName(cell->bel).c_str(ctx)); - } - } void write_module(std::ostream &f, Context *ctx) @@ -154,8 +88,7 @@ void write_module(std::ostream &f, Context *ctx) write_parameters(f, ctx, c->params); f << stringf("\n },\n"); f << stringf(" \"attributes\": {"); - bool first3 = write_parameters(f, ctx, c->attrs); - write_constraints(f, ctx, c.get(), first3); + write_parameters(f, ctx, c->attrs); f << stringf("\n },\n"); f << stringf(" \"port_directions\": {"); bool first2 = true; @@ -196,8 +129,7 @@ void write_module(std::ostream &f, Context *ctx) f << stringf(" \"hide_name\": %s,\n", w->name.c_str(ctx)[0] == '$' ? "1" : "0"); f << stringf(" \"bits\": [ %d ] ,\n", pair.first.index); f << stringf(" \"attributes\": {"); - bool first2 = write_parameters(f, ctx, w->attrs); - write_routing(f, ctx, w.get(), first2); + write_parameters(f, ctx, w->attrs); f << stringf("\n }\n"); f << stringf(" }"); first = false; -- cgit v1.2.3 From d9b0bac248a12466cd2b62d02ec11b2e60d25019 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 7 Jun 2019 16:11:11 +0200 Subject: Save top level attrs and store current step --- json/jsonwrite.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'json/jsonwrite.cc') 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_mapattrs.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 -- cgit v1.2.3 From 856760599e51bd4c6da34112c993dc8bfb995f36 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 12 Jun 2019 18:34:34 +0200 Subject: Use properties for settings and save in json --- json/jsonwrite.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'json/jsonwrite.cc') diff --git a/json/jsonwrite.cc b/json/jsonwrite.cc index 19c43d7c..ac54bc4e 100644 --- a/json/jsonwrite.cc +++ b/json/jsonwrite.cc @@ -69,10 +69,9 @@ void write_module(std::ostream &f, Context *ctx) 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\": {"); + f << stringf(" \"settings\": {"); write_parameters(f, ctx, ctx->settings, true); - f << stringf("\n },\n");*/ + f << stringf("\n },\n"); f << stringf(" \"attributes\": {"); write_parameters(f, ctx, ctx->attrs, true); f << stringf("\n },\n"); -- cgit v1.2.3 From 92da4a91de0b602b0414754bd3ae05fdd70acbe7 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 21 Jun 2019 09:43:47 +0200 Subject: Preserve ports --- json/jsonwrite.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'json/jsonwrite.cc') diff --git a/json/jsonwrite.cc b/json/jsonwrite.cc index ac54bc4e..552cd398 100644 --- a/json/jsonwrite.cc +++ b/json/jsonwrite.cc @@ -76,11 +76,20 @@ void write_module(std::ostream &f, Context *ctx) write_parameters(f, ctx, ctx->attrs, true); f << stringf("\n },\n"); f << stringf(" \"ports\": {"); - // TODO: Top level ports + bool first = true; + for (auto &pair : ctx->ports) { + auto &c = pair.second; + f << stringf("%s\n", first ? "" : ","); + f << stringf(" %s: {\n", get_name(c.name, ctx).c_str()); + f << stringf(" \"direction\": \"%s\",\n", c.type == PORT_IN ? "input" : c.type == PORT_INOUT ? "inout" : "output"); + f << stringf(" \"bits\": [ %d ]\n", pair.first.index); + f << stringf(" }"); + first = false; + } f << stringf("\n },\n"); f << stringf(" \"cells\": {"); - bool first = true; + first = true; for (auto &pair : ctx->cells) { auto &c = pair.second; f << stringf("%s\n", first ? "" : ","); -- cgit v1.2.3 From be47fc3e9a81a4890b05223ae18803cb07674dc9 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Tue, 25 Jun 2019 18:19:25 +0200 Subject: clangformat run --- json/jsonwrite.cc | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'json/jsonwrite.cc') diff --git a/json/jsonwrite.cc b/json/jsonwrite.cc index 552cd398..0b7a5b25 100644 --- a/json/jsonwrite.cc +++ b/json/jsonwrite.cc @@ -43,17 +43,15 @@ std::string get_string(std::string str) return newstr + "\""; } -std::string get_name(IdString name, Context *ctx) -{ - return get_string(name.c_str(ctx)); -} +std::string get_name(IdString name, Context *ctx) { return get_string(name.c_str(ctx)); } -void write_parameters(std::ostream &f, Context *ctx, const std::unordered_map ¶meters, bool for_module=false) +void write_parameters(std::ostream &f, Context *ctx, const std::unordered_map ¶meters, + bool for_module = false) { bool first = true; for (auto ¶m : parameters) { f << stringf("%s\n", first ? "" : ","); - f << stringf(" %s%s: ", for_module ? "" : " ", get_name(param.first,ctx).c_str()); + f << stringf(" %s%s: ", for_module ? "" : " ", get_name(param.first, ctx).c_str()); if (param.second.isString()) f << get_string(param.second); else @@ -65,7 +63,7 @@ void write_parameters(std::ostream &f, Context *ctx, const std::unordered_mapattrs.find(ctx->id("module")); - if (val != ctx->attrs.end()) + 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()); @@ -81,16 +79,17 @@ void write_module(std::ostream &f, Context *ctx) auto &c = pair.second; f << stringf("%s\n", first ? "" : ","); f << stringf(" %s: {\n", get_name(c.name, ctx).c_str()); - f << stringf(" \"direction\": \"%s\",\n", c.type == PORT_IN ? "input" : c.type == PORT_INOUT ? "inout" : "output"); + f << stringf(" \"direction\": \"%s\",\n", + c.type == PORT_IN ? "input" : c.type == PORT_INOUT ? "inout" : "output"); f << stringf(" \"bits\": [ %d ]\n", pair.first.index); f << stringf(" }"); first = false; - } + } f << stringf("\n },\n"); f << stringf(" \"cells\": {"); first = true; - for (auto &pair : ctx->cells) { + for (auto &pair : ctx->cells) { auto &c = pair.second; f << stringf("%s\n", first ? "" : ","); f << stringf(" %s: {\n", get_name(c->name, ctx).c_str()); @@ -118,9 +117,9 @@ void write_module(std::ostream &f, Context *ctx) auto &p = conn.second; f << stringf("%s\n", first2 ? "" : ","); if (p.net) - f << stringf(" %s: [ %d ]", get_name(conn.first,ctx).c_str(), p.net->name.index); - else - f << stringf(" %s: [ ]", get_name(conn.first,ctx).c_str()); + f << stringf(" %s: [ %d ]", get_name(conn.first, ctx).c_str(), p.net->name.index); + else + f << stringf(" %s: [ ]", get_name(conn.first, ctx).c_str()); first2 = false; } @@ -146,7 +145,7 @@ void write_module(std::ostream &f, Context *ctx) f << stringf(" }"); first = false; } - + f << stringf("\n }\n"); f << stringf(" }"); } @@ -154,7 +153,8 @@ void write_module(std::ostream &f, Context *ctx) void write_context(std::ostream &f, Context *ctx) { f << stringf("{\n"); - f << stringf(" \"creator\": %s,\n", get_string( "Next Generation Place and Route (git sha1 " GIT_COMMIT_HASH_STR ")").c_str()); + f << stringf(" \"creator\": %s,\n", + get_string("Next Generation Place and Route (git sha1 " GIT_COMMIT_HASH_STR ")").c_str()); f << stringf(" \"modules\": {\n"); write_module(f, ctx); f << stringf("\n }"); @@ -166,7 +166,7 @@ void write_context(std::ostream &f, Context *ctx) bool write_json_file(std::ostream &f, std::string &filename, Context *ctx) { try { - using namespace JsonWriter; + using namespace JsonWriter; if (!f) log_error("failed to open JSON file.\n"); write_context(f, ctx); -- cgit v1.2.3