diff options
author | Miodrag Milanovic <mmicko@gmail.com> | 2019-06-21 09:43:47 +0200 |
---|---|---|
committer | Miodrag Milanovic <mmicko@gmail.com> | 2019-06-21 09:43:47 +0200 |
commit | 92da4a91de0b602b0414754bd3ae05fdd70acbe7 (patch) | |
tree | 694fbffad464c0bbe158809327250125bf2a1cc7 /json | |
parent | ff257a092930492a1260cf0c1f79d76c3d098612 (diff) | |
download | nextpnr-92da4a91de0b602b0414754bd3ae05fdd70acbe7.tar.gz nextpnr-92da4a91de0b602b0414754bd3ae05fdd70acbe7.tar.bz2 nextpnr-92da4a91de0b602b0414754bd3ae05fdd70acbe7.zip |
Preserve ports
Diffstat (limited to 'json')
-rw-r--r-- | json/jsonparse.cc | 8 | ||||
-rw-r--r-- | json/jsonwrite.cc | 13 |
2 files changed, 18 insertions, 3 deletions
diff --git a/json/jsonparse.cc b/json/jsonparse.cc index 92bbf92f..76854bf9 100644 --- a/json/jsonparse.cc +++ b/json/jsonparse.cc @@ -717,6 +717,12 @@ static void insert_iobuf(Context *ctx, NetInfo *net, PortType type, const string assert(false); } ctx->cells[iobuf->name] = std::move(iobuf); + + PortInfo pinfo; + pinfo.name = net->name; + pinfo.net = net; + pinfo.type = type; + ctx->ports[net->name] = pinfo; } void json_import_toplevel_port(Context *ctx, const string &modname, const std::vector<IdString> &netnames, @@ -726,7 +732,7 @@ void json_import_toplevel_port(Context *ctx, const string &modname, const std::v JsonNode *nets_node = node->data_dict.at("bits"); json_import_ports( ctx, modname, netnames, "Top Level IO", portname, dir_node, nets_node, - [ctx](PortType type, const std::string &name, NetInfo *net) { insert_iobuf(ctx, net, type, name); }); + [ctx](PortType type, const std::string &name, NetInfo *net) { insert_iobuf(ctx, net, type, name); }); } void json_import(Context *ctx, string modname, JsonNode *node) 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 ? "" : ","); |