aboutsummaryrefslogtreecommitdiffstats
path: root/ecp5
diff options
context:
space:
mode:
authorgatecat <gatecat@ds0.me>2022-02-16 13:53:47 +0000
committergatecat <gatecat@ds0.me>2022-02-16 15:10:57 +0000
commit30fd86ce69fa65e89dec119e23b5bccb54de70a3 (patch)
tree7700f5ce4d8b40255aa54e08d2c4489e74b906ff /ecp5
parent02e6d2dbca0433e6f873c6af635cee701e84f5f5 (diff)
downloadnextpnr-30fd86ce69fa65e89dec119e23b5bccb54de70a3.tar.gz
nextpnr-30fd86ce69fa65e89dec119e23b5bccb54de70a3.tar.bz2
nextpnr-30fd86ce69fa65e89dec119e23b5bccb54de70a3.zip
refactor: New NetInfo and CellInfo constructors
Diffstat (limited to 'ecp5')
-rw-r--r--ecp5/cells.cc18
-rw-r--r--ecp5/globals.cc23
-rw-r--r--ecp5/pack.cc58
3 files changed, 36 insertions, 63 deletions
diff --git a/ecp5/cells.cc b/ecp5/cells.cc
index b0ae2065..e5ab4d4b 100644
--- a/ecp5/cells.cc
+++ b/ecp5/cells.cc
@@ -34,13 +34,9 @@ void add_port(const Context *ctx, CellInfo *cell, std::string name, PortType dir
std::unique_ptr<CellInfo> create_ecp5_cell(Context *ctx, IdString type, std::string name)
{
static int auto_idx = 0;
- std::unique_ptr<CellInfo> new_cell = std::unique_ptr<CellInfo>(new CellInfo());
- if (name.empty()) {
- new_cell->name = ctx->id("$nextpnr_" + type.str(ctx) + "_" + std::to_string(auto_idx++));
- } else {
- new_cell->name = ctx->id(name);
- }
- new_cell->type = type;
+ IdString name_id =
+ name.empty() ? ctx->id("$nextpnr_" + type.str(ctx) + "_" + std::to_string(auto_idx++)) : ctx->id(name);
+ std::unique_ptr<CellInfo> new_cell = std::make_unique<CellInfo>(ctx, name_id, type);
auto copy_bel_ports = [&]() {
// First find a Bel of the target type
@@ -465,11 +461,11 @@ void nxio_to_tr(Context *ctx, CellInfo *nxio, CellInfo *trio, std::vector<std::u
if (ctx->ports.count(nxio->name)) {
IdString tn_netname = nxio->name;
NPNR_ASSERT(!ctx->nets.count(tn_netname));
- std::unique_ptr<NetInfo> toplevel_net{new NetInfo};
+ ctx->net_aliases.erase(tn_netname);
+ NetInfo *toplevel_net = ctx->createNet(tn_netname);
toplevel_net->name = tn_netname;
- connect_port(ctx, toplevel_net.get(), trio, ctx->id("B"));
- ctx->ports[nxio->name].net = toplevel_net.get();
- ctx->nets[tn_netname] = std::move(toplevel_net);
+ connect_port(ctx, toplevel_net, trio, ctx->id("B"));
+ ctx->ports[nxio->name].net = toplevel_net;
}
CellInfo *tbuf = net_driven_by(
diff --git a/ecp5/globals.cc b/ecp5/globals.cc
index 8ee49c02..cc2208e0 100644
--- a/ecp5/globals.cc
+++ b/ecp5/globals.cc
@@ -456,11 +456,10 @@ class Ecp5GlobalRouter
dccptr = net->driver.cell;
} else {
auto dcc = create_ecp5_cell(ctx, id_DCCA, "$gbuf$" + net->name.str(ctx));
- std::unique_ptr<NetInfo> glbnet = std::unique_ptr<NetInfo>(new NetInfo);
- glbnet->name = ctx->id("$glbnet$" + net->name.str(ctx));
- glbnet->driver.cell = dcc.get();
- glbnet->driver.port = id_CLKO;
- dcc->ports[id_CLKO].net = glbnet.get();
+ glbptr = ctx->createNet(ctx->id("$glbnet$" + net->name.str(ctx)));
+ glbptr->driver.cell = dcc.get();
+ glbptr->driver.port = id_CLKO;
+ dcc->ports[id_CLKO].net = glbptr;
std::vector<PortRef> keep_users;
for (auto user : net->users) {
if (dcs_cell != nullptr && user.cell != dcs_cell) {
@@ -473,8 +472,8 @@ class Ecp5GlobalRouter
} else if (is_logic_port(user)) {
keep_users.push_back(user);
} else {
- glbnet->users.push_back(user);
- user.cell->ports.at(user.port).net = glbnet.get();
+ glbptr->users.push_back(user);
+ user.cell->ports.at(user.port).net = glbptr;
}
}
net->users = keep_users;
@@ -485,13 +484,11 @@ class Ecp5GlobalRouter
clki_pr.cell = dcc.get();
net->users.push_back(clki_pr);
if (net->clkconstr) {
- glbnet->clkconstr = std::unique_ptr<ClockConstraint>(new ClockConstraint());
- glbnet->clkconstr->low = net->clkconstr->low;
- glbnet->clkconstr->high = net->clkconstr->high;
- glbnet->clkconstr->period = net->clkconstr->period;
+ glbptr->clkconstr = std::unique_ptr<ClockConstraint>(new ClockConstraint());
+ glbptr->clkconstr->low = net->clkconstr->low;
+ glbptr->clkconstr->high = net->clkconstr->high;
+ glbptr->clkconstr->period = net->clkconstr->period;
}
- glbptr = glbnet.get();
- ctx->nets[glbnet->name] = std::move(glbnet);
dccptr = dcc.get();
ctx->cells[dcc->name] = std::move(dcc);
}
diff --git a/ecp5/pack.cc b/ecp5/pack.cc
index 85d92336..79644d13 100644
--- a/ecp5/pack.cc
+++ b/ecp5/pack.cc
@@ -761,17 +761,14 @@ class Ecp5Packer
carry->users.end());
connect_port(ctx, carry, feedin.get(), id_A0);
- std::unique_ptr<NetInfo> new_carry(new NetInfo());
- new_carry->name = ctx->id(feedin->name.str(ctx) + "$COUT");
- connect_port(ctx, new_carry.get(), feedin.get(), ctx->id("COUT"));
+ NetInfo *new_carry = ctx->createNet(ctx->id(feedin->name.str(ctx) + "$COUT"));
+ connect_port(ctx, new_carry, feedin.get(), ctx->id("COUT"));
chain_in.cell->ports[chain_in.port].net = nullptr;
- connect_port(ctx, new_carry.get(), chain_in.cell, chain_in.port);
+ connect_port(ctx, new_carry, chain_in.cell, chain_in.port);
CellInfo *feedin_ptr = feedin.get();
IdString feedin_name = feedin->name;
ctx->cells[feedin_name] = std::move(feedin);
- IdString new_carry_name = new_carry->name;
- ctx->nets[new_carry_name] = std::move(new_carry);
return feedin_ptr;
}
@@ -789,11 +786,10 @@ class Ecp5Packer
carry->driver.cell = nullptr;
connect_port(ctx, carry, feedout.get(), ctx->id("S0"));
- std::unique_ptr<NetInfo> new_cin(new NetInfo());
- new_cin->name = ctx->id(feedout->name.str(ctx) + "$CIN");
+ NetInfo *new_cin = ctx->createNet(ctx->id(feedout->name.str(ctx) + "$CIN"));
new_cin->driver = carry_drv;
- carry_drv.cell->ports.at(carry_drv.port).net = new_cin.get();
- connect_port(ctx, new_cin.get(), feedout.get(), ctx->id("CIN"));
+ carry_drv.cell->ports.at(carry_drv.port).net = new_cin;
+ connect_port(ctx, new_cin, feedout.get(), ctx->id("CIN"));
if (chain_next) {
// Loop back into LUT4_1 for feedthrough
@@ -805,24 +801,17 @@ class Ecp5Packer
}),
carry->users.end());
- std::unique_ptr<NetInfo> new_cout(new NetInfo());
- new_cout->name = ctx->id(feedout->name.str(ctx) + "$COUT");
- connect_port(ctx, new_cout.get(), feedout.get(), ctx->id("COUT"));
+ NetInfo *new_cout = ctx->createNet(ctx->id(feedout->name.str(ctx) + "$COUT"));
+ connect_port(ctx, new_cout, feedout.get(), ctx->id("COUT"));
chain_next->cell->ports[chain_next->port].net = nullptr;
- connect_port(ctx, new_cout.get(), chain_next->cell, chain_next->port);
-
- IdString new_cout_name = new_cout->name;
- ctx->nets[new_cout_name] = std::move(new_cout);
+ connect_port(ctx, new_cout, chain_next->cell, chain_next->port);
}
CellInfo *feedout_ptr = feedout.get();
IdString feedout_name = feedout->name;
ctx->cells[feedout_name] = std::move(feedout);
- IdString new_cin_name = new_cin->name;
- ctx->nets[new_cin_name] = std::move(new_cin);
-
return feedout_ptr;
}
@@ -1384,16 +1373,14 @@ class Ecp5Packer
std::unique_ptr<CellInfo> gnd_cell = create_ecp5_cell(ctx, ctx->id("LUT4"), "$PACKER_GND");
gnd_cell->params[ctx->id("INIT")] = Property(0, 16);
- std::unique_ptr<NetInfo> gnd_net = std::unique_ptr<NetInfo>(new NetInfo);
- gnd_net->name = ctx->id("$PACKER_GND_NET");
+ auto gnd_net = std::make_unique<NetInfo>(ctx->id("$PACKER_GND_NET"));
gnd_net->driver.cell = gnd_cell.get();
gnd_net->driver.port = ctx->id("Z");
gnd_cell->ports.at(ctx->id("Z")).net = gnd_net.get();
std::unique_ptr<CellInfo> vcc_cell = create_ecp5_cell(ctx, ctx->id("LUT4"), "$PACKER_VCC");
vcc_cell->params[ctx->id("INIT")] = Property(65535, 16);
- std::unique_ptr<NetInfo> vcc_net = std::unique_ptr<NetInfo>(new NetInfo);
- vcc_net->name = ctx->id("$PACKER_VCC_NET");
+ auto vcc_net = std::make_unique<NetInfo>(ctx->id("$PACKER_VCC_NET"));
vcc_net->driver.cell = vcc_cell.get();
vcc_net->driver.port = ctx->id("Z");
vcc_cell->ports.at(ctx->id("Z")).net = vcc_net.get();
@@ -1967,12 +1954,9 @@ class Ecp5Packer
IdString eckname = ctx->id(ecknet->name.str(ctx) + "$eclk" + std::to_string(bank) + "_" +
std::to_string(free_eclk));
- std::unique_ptr<NetInfo> promoted_ecknet(new NetInfo);
- promoted_ecknet->name = eckname;
+ NetInfo *promoted_ecknet = ctx->createNet(eckname);
promoted_ecknet->attrs[ctx->id("ECP5_IS_GLOBAL")] = 1; // Prevents router etc touching this special net
- eclk.buf = promoted_ecknet.get();
- NPNR_ASSERT(!ctx->nets.count(eckname));
- ctx->nets[eckname] = std::move(promoted_ecknet);
+ eclk.buf = promoted_ecknet;
// Insert TRELLIS_ECLKBUF to isolate edge clock from general routing
std::unique_ptr<CellInfo> eclkbuf =
@@ -2052,17 +2036,13 @@ class Ecp5Packer
ci->ports[port].name = port;
ci->ports[port].type = PORT_IN;
}
-
- std::unique_ptr<CellInfo> zero_cell{new CellInfo};
- std::unique_ptr<NetInfo> zero_net{new NetInfo};
IdString name = ctx->id(ci->name.str(ctx) + "$zero$" + port.str(ctx));
- zero_cell->type = ctx->id("GND");
- zero_cell->name = name;
- zero_net->name = name;
- zero_cell->ports[ctx->id("GND")].type = PORT_OUT;
- connect_port(ctx, zero_net.get(), zero_cell.get(), ctx->id("GND"));
- connect_port(ctx, zero_net.get(), ci, port);
- ctx->nets[name] = std::move(zero_net);
+
+ auto zero_cell = std::make_unique<CellInfo>(ctx, name, ctx->id("GND"));
+ NetInfo *zero_net = ctx->createNet(name);
+ zero_cell->addOutput(ctx->id("GND"));
+ connect_port(ctx, zero_net, zero_cell.get(), ctx->id("GND"));
+ connect_port(ctx, zero_net, ci, port);
new_cells.push_back(std::move(zero_cell));
}