diff options
author | Miodrag Milanović <mmicko@gmail.com> | 2020-11-30 10:56:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-30 10:56:59 +0100 |
commit | 8b5c0dc1e49b692b0bb598a90034c27db653622d (patch) | |
tree | afd13c654df1faa0b5df9f11be74eede087fa564 /common/design_utils.cc | |
parent | 1afa494e69e3c8af3dd5d1685b9cd2b1d3bea4d0 (diff) | |
parent | 2fe8bebc6ce464afadef2403a8331031e16c5a5d (diff) | |
download | nextpnr-8b5c0dc1e49b692b0bb598a90034c27db653622d.tar.gz nextpnr-8b5c0dc1e49b692b0bb598a90034c27db653622d.tar.bz2 nextpnr-8b5c0dc1e49b692b0bb598a90034c27db653622d.zip |
Merge pull request #524 from daveshah1/nextpnr-nexus
Upstreaming basic support for Nexus devices
Diffstat (limited to 'common/design_utils.cc')
-rw-r--r-- | common/design_utils.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/common/design_utils.cc b/common/design_utils.cc index dd866758..16cc2710 100644 --- a/common/design_utils.cc +++ b/common/design_utils.cc @@ -30,6 +30,13 @@ void replace_port(CellInfo *old_cell, IdString old_name, CellInfo *rep_cell, IdS if (!old_cell->ports.count(old_name)) return; PortInfo &old = old_cell->ports.at(old_name); + + // Create port on the replacement cell if it doesn't already exist + if (!rep_cell->ports.count(rep_name)) { + rep_cell->ports[rep_name].name = rep_name; + rep_cell->ports[rep_name].type = old.type; + } + PortInfo &rep = rep_cell->ports.at(rep_name); NPNR_ASSERT(old.type == rep.type); @@ -157,4 +164,33 @@ void rename_net(Context *ctx, NetInfo *net, IdString new_name) net->name = new_name; } +void replace_bus(Context *ctx, CellInfo *old_cell, IdString old_name, int old_offset, bool old_brackets, + CellInfo *new_cell, IdString new_name, int new_offset, bool new_brackets, int width) +{ + for (int i = 0; i < width; i++) { + IdString old_port = ctx->id(stringf(old_brackets ? "%s[%d]" : "%s%d", old_name.c_str(ctx), i + old_offset)); + IdString new_port = ctx->id(stringf(new_brackets ? "%s[%d]" : "%s%d", new_name.c_str(ctx), i + new_offset)); + replace_port(old_cell, old_port, new_cell, new_port); + } +} + +void copy_port(Context *ctx, CellInfo *old_cell, IdString old_name, CellInfo *new_cell, IdString new_name) +{ + if (!old_cell->ports.count(old_name)) + return; + new_cell->ports[new_name].name = new_name; + new_cell->ports[new_name].type = old_cell->ports.at(old_name).type; + connect_port(ctx, old_cell->ports.at(old_name).net, new_cell, new_name); +} + +void copy_bus(Context *ctx, CellInfo *old_cell, IdString old_name, int old_offset, bool old_brackets, + CellInfo *new_cell, IdString new_name, int new_offset, bool new_brackets, int width) +{ + for (int i = 0; i < width; i++) { + IdString old_port = ctx->id(stringf(old_brackets ? "%s[%d]" : "%s%d", old_name.c_str(ctx), i + old_offset)); + IdString new_port = ctx->id(stringf(new_brackets ? "%s[%d]" : "%s%d", new_name.c_str(ctx), i + new_offset)); + copy_port(ctx, old_cell, old_port, new_cell, new_port); + } +} + NEXTPNR_NAMESPACE_END |