Preserve ports

This commit is contained in:
Miodrag Milanovic 2019-06-21 09:43:47 +02:00
parent ff257a0929
commit 92da4a91de
3 changed files with 21 additions and 3 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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 ? "" : ",");