diff options
-rw-r--r-- | common/nextpnr.h | 3 | ||||
-rw-r--r-- | json/jsonparse.cc | 8 | ||||
-rw-r--r-- | json/jsonwrite.cc | 13 |
3 files changed, 21 insertions, 3 deletions
diff --git a/common/nextpnr.h b/common/nextpnr.h index e4461cb4..6950ac76 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -548,6 +548,9 @@ struct BaseCtx std::unordered_map<IdString, std::unique_ptr<NetInfo>> nets; std::unordered_map<IdString, std::unique_ptr<CellInfo>> cells; + // Top-level ports + std::unordered_map<IdString, PortInfo> ports; + // Floorplanning regions std::unordered_map<IdString, std::unique_ptr<Region>> region; 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 ? "" : ","); |