From 30fd86ce69fa65e89dec119e23b5bccb54de70a3 Mon Sep 17 00:00:00 2001 From: gatecat Date: Wed, 16 Feb 2022 13:53:47 +0000 Subject: refactor: New NetInfo and CellInfo constructors --- machxo2/cells.cc | 10 +++------- machxo2/pack.cc | 15 ++++++--------- 2 files changed, 9 insertions(+), 16 deletions(-) (limited to 'machxo2') diff --git a/machxo2/cells.cc b/machxo2/cells.cc index 7334234d..534d8e3c 100644 --- a/machxo2/cells.cc +++ b/machxo2/cells.cc @@ -41,13 +41,9 @@ void add_port(const Context *ctx, CellInfo *cell, IdString id, PortType dir) std::unique_ptr create_machxo2_cell(Context *ctx, IdString type, std::string name) { static int auto_idx = 0; - std::unique_ptr new_cell = std::unique_ptr(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); + auto new_cell = std::make_unique(ctx, name_id, type); if (type == id_FACADE_SLICE) { new_cell->params[id_MODE] = std::string("LOGIC"); diff --git a/machxo2/pack.cc b/machxo2/pack.cc index c53229ba..0c2c9459 100644 --- a/machxo2/pack.cc +++ b/machxo2/pack.cc @@ -183,17 +183,16 @@ static void pack_constants(Context *ctx) const_cell->params[id_LUT0_INITVAL] = Property(0, 16); const_cell->params[id_LUT1_INITVAL] = Property(0xFFFF, 16); - std::unique_ptr gnd_net = std::unique_ptr(new NetInfo); - gnd_net->name = ctx->id("$PACKER_GND_NET"); + NetInfo *gnd_net = ctx->createNet(ctx->id("$PACKER_GND_NET")); gnd_net->driver.cell = const_cell.get(); gnd_net->driver.port = id_F0; - const_cell->ports.at(id_F0).net = gnd_net.get(); + const_cell->ports.at(id_F0).net = gnd_net; - std::unique_ptr vcc_net = std::unique_ptr(new NetInfo); + NetInfo *vcc_net = ctx->createNet(ctx->id("$PACKER_VCC_NET")); vcc_net->name = ctx->id("$PACKER_VCC_NET"); vcc_net->driver.cell = const_cell.get(); vcc_net->driver.port = id_F1; - const_cell->ports.at(id_F1).net = vcc_net.get(); + const_cell->ports.at(id_F1).net = vcc_net; std::vector dead_nets; @@ -201,20 +200,18 @@ static void pack_constants(Context *ctx) NetInfo *ni = net.second.get(); if (ni->driver.cell != nullptr && ni->driver.cell->type == ctx->id("GND")) { IdString drv_cell = ni->driver.cell->name; - set_net_constant(ctx, ni, gnd_net.get(), false); + set_net_constant(ctx, ni, gnd_net, false); dead_nets.push_back(net.first); ctx->cells.erase(drv_cell); } else if (ni->driver.cell != nullptr && ni->driver.cell->type == ctx->id("VCC")) { IdString drv_cell = ni->driver.cell->name; - set_net_constant(ctx, ni, vcc_net.get(), true); + set_net_constant(ctx, ni, vcc_net, true); dead_nets.push_back(net.first); ctx->cells.erase(drv_cell); } } ctx->cells[const_cell->name] = std::move(const_cell); - ctx->nets[gnd_net->name] = std::move(gnd_net); - ctx->nets[vcc_net->name] = std::move(vcc_net); for (auto dn : dead_nets) { ctx->nets.erase(dn); -- cgit v1.2.3