diff --git a/ice40/arch_place.cc b/ice40/arch_place.cc index 25044525..60fa928e 100644 --- a/ice40/arch_place.cc +++ b/ice40/arch_place.cc @@ -139,8 +139,8 @@ bool PlaceValidityChecker::isValidBelForCell(CellInfo *cell, BelId bel) return ctx->getBelPackagePin(bel) != ""; } else if (cell->type == id_sb_gb) { bool is_reset = false, is_cen = false; - assert(cell->ports.at("GLOBAL_BUFFER_OUTPUT").net != nullptr); - for (auto user : cell->ports.at("GLOBAL_BUFFER_OUTPUT").net->users) { + assert(cell->ports.at(ctx->id("GLOBAL_BUFFER_OUTPUT")).net != nullptr); + for (auto user : cell->ports.at(ctx->id("GLOBAL_BUFFER_OUTPUT")).net->users) { if (is_reset_port(ctx, user)) is_reset = true; if (is_enable_port(ctx, user)) @@ -148,7 +148,7 @@ bool PlaceValidityChecker::isValidBelForCell(CellInfo *cell, BelId bel) } IdString glb_net = ctx->getWireName( ctx->getWireBelPin(bel, PIN_GLOBAL_BUFFER_OUTPUT)); - int glb_id = std::stoi(std::string("") + glb_net.str().back()); + int glb_id = std::stoi(std::string("") + glb_net.str(ctx).back()); if (is_reset && is_cen) return false; else if (is_reset) diff --git a/ice40/bitstream.cc b/ice40/bitstream.cc index 8e34335c..61bbe27d 100644 --- a/ice40/bitstream.cc +++ b/ice40/bitstream.cc @@ -441,7 +441,7 @@ void write_asc(const Context *ctx, std::ostream &out) cell.second, ctx->id(std::string("INIT_") + get_hexdigit(w))); assert(init != ""); - for (int i = 0; i < init.size(); i++) { + for (size_t i = 0; i < init.size(); i++) { bool val = (init.at((init.size() - 1) - i) == '1'); bits.at(i) = val; } @@ -458,7 +458,7 @@ void write_asc(const Context *ctx, std::ostream &out) } // Write symbols - const bool write_symbols = 1; + //const bool write_symbols = 1; for (auto wire : ctx->getWires()) { IdString net = ctx->getWireNet(wire, false); if (net != IdString()) diff --git a/ice40/cells.cc b/ice40/cells.cc index 0ae25e12..056c33f8 100644 --- a/ice40/cells.cc +++ b/ice40/cells.cc @@ -36,7 +36,7 @@ CellInfo *create_ice_cell(Context *ctx, IdString type, std::string name) static int auto_idx = 0; CellInfo *new_cell = new CellInfo(); if (name.empty()) { - new_cell->name = IdString(ctx, "$nextpnr_" + type.str() + "_" + + new_cell->name = ctx->id( "$nextpnr_" + type.str(ctx) + "_" + std::to_string(auto_idx++)); } else { new_cell->name = ctx->id(name); @@ -132,13 +132,13 @@ CellInfo *create_ice_cell(Context *ctx, IdString type, std::string name) void lut_to_lc(const Context *ctx, CellInfo *lut, CellInfo *lc, bool no_dff) { - lc->params["LUT_INIT"] = lut->params["LUT_INIT"]; - replace_port(lut, "I0", lc, "I0"); - replace_port(lut, "I1", lc, "I1"); - replace_port(lut, "I2", lc, "I2"); - replace_port(lut, "I3", lc, "I3"); + lc->params[ctx->id("LUT_INIT")] = lut->params[ctx->id("LUT_INIT")]; + replace_port(lut, ctx->id("I0"), lc, ctx->id("I0")); + replace_port(lut, ctx->id("I1"), lc, ctx->id("I1")); + replace_port(lut, ctx->id("I2"), lc, ctx->id("I2")); + replace_port(lut, ctx->id("I3"), lc, ctx->id("I3")); if (no_dff) { - replace_port(lut, "O", lc, "O"); + replace_port(lut, ctx->id("O"), lc, ctx->id("O")); lc->params[ctx->id("DFF_ENABLE")] = "0"; } } @@ -149,7 +149,7 @@ void dff_to_lc(const Context *ctx, CellInfo *dff, CellInfo *lc, lc->params[ctx->id("DFF_ENABLE")] = "1"; std::string config = dff->type.str(ctx).substr(6); auto citer = config.begin(); - replace_port(dff, "C", lc, "CLK"); + replace_port(dff, ctx->id("C"), lc, ctx->id("CLK")); if (citer != config.end() && *citer == 'N') { lc->params[ctx->id("NEG_CLK")] = "1"; @@ -159,7 +159,7 @@ void dff_to_lc(const Context *ctx, CellInfo *dff, CellInfo *lc, } if (citer != config.end() && *citer == 'E') { - replace_port(dff, "E", lc, "CEN"); + replace_port(dff, ctx->id("E"), lc, ctx->id("CEN")); ++citer; } @@ -174,12 +174,12 @@ void dff_to_lc(const Context *ctx, CellInfo *dff, CellInfo *lc, if (*citer == 'S') { citer++; - replace_port(dff, "S", lc, "SR"); + replace_port(dff, ctx->id("S"), lc, ctx->id("SR")); lc->params[ctx->id("SET_NORESET")] = "1"; } else { assert(*citer == 'R'); citer++; - replace_port(dff, "R", lc, "SR"); + replace_port(dff, ctx->id("R"), lc, ctx->id("SR")); lc->params[ctx->id("SET_NORESET")] = "0"; } } @@ -188,28 +188,28 @@ void dff_to_lc(const Context *ctx, CellInfo *dff, CellInfo *lc, if (pass_thru_lut) { lc->params[ctx->id("LUT_INIT")] = "2"; - replace_port(dff, "D", lc, "I0"); + replace_port(dff, ctx->id("D"), lc, ctx->id("I0")); } - replace_port(dff, "Q", lc, "O"); + replace_port(dff, ctx->id("Q"), lc, ctx->id("O")); } void nxio_to_sb(Context *ctx, CellInfo *nxio, CellInfo *sbio) { if (nxio->type == ctx->id("$nextpnr_ibuf")) { sbio->params[ctx->id("PIN_TYPE")] = "1"; - auto pu_attr = nxio->attrs.find("PULLUP"); + auto pu_attr = nxio->attrs.find(ctx->id("PULLUP")); if (pu_attr != nxio->attrs.end()) sbio->params[ctx->id("PULLUP")] = pu_attr->second; - replace_port(nxio, "O", sbio, "D_IN_0"); + replace_port(nxio, ctx->id("O"), sbio, ctx->id("D_IN_0")); } else if (nxio->type == ctx->id("$nextpnr_obuf")) { sbio->params[ctx->id("PIN_TYPE")] = "25"; - replace_port(nxio, "I", sbio, "D_OUT_0"); + replace_port(nxio, ctx->id("I"), sbio, ctx->id("D_OUT_0")); } else if (nxio->type == ctx->id("$nextpnr_iobuf")) { // N.B. tristate will be dealt with below sbio->params[ctx->id("PIN_TYPE")] = "25"; - replace_port(nxio, "I", sbio, "D_OUT_0"); - replace_port(nxio, "O", sbio, "D_IN_0"); + replace_port(nxio, ctx->id("I"), sbio, ctx->id("D_OUT_0")); + replace_port(nxio, ctx->id("O"), sbio, ctx->id("D_IN_0")); } else { assert(false); } @@ -219,11 +219,11 @@ void nxio_to_sb(Context *ctx, CellInfo *nxio, CellInfo *sbio) [](const Context *ctx, const CellInfo *cell) { return cell->type == ctx->id("$_TBUF_"); }, - "Y"); + ctx->id("Y")); if (tbuf) { sbio->params[ctx->id("PIN_TYPE")] = "41"; - replace_port(tbuf, "A", sbio, "D_OUT_0"); - replace_port(tbuf, "E", sbio, "OUTPUT_ENABLE"); + replace_port(tbuf, ctx->id("A"), sbio, ctx->id("D_OUT_0")); + replace_port(tbuf, ctx->id("E"), sbio, ctx->id("OUTPUT_ENABLE")); ctx->nets.erase(donet->name); if (!donet->users.empty()) log_error( diff --git a/ice40/pack.cc b/ice40/pack.cc index 5022fc59..868b0fd8 100644 --- a/ice40/pack.cc +++ b/ice40/pack.cc @@ -41,7 +41,7 @@ static void pack_lut_lutffs(Context *ctx) log_info("cell '%s' is of type '%s'\n", ci->name.c_str(ctx), ci->type.c_str(ctx)); if (is_lut(ctx, ci)) { - CellInfo *packed = create_ice_cell(ctx, "ICESTORM_LC", + CellInfo *packed = create_ice_cell(ctx, ctx->id("ICESTORM_LC"), ci->name.str(ctx) + "_LC"); std::copy(ci->attrs.begin(), ci->attrs.end(), std::inserter(packed->attrs, packed->attrs.begin())); @@ -53,7 +53,7 @@ static void pack_lut_lutffs(Context *ctx) // See if we can pack into a DFF // TODO: LUT cascade NetInfo *o = ci->ports.at(ctx->id("O")).net; - CellInfo *dff = net_only_drives(ctx, o, is_ff, "D", true); + CellInfo *dff = net_only_drives(ctx, o, is_ff, ctx->id("D"), true); auto lut_bel = ci->attrs.find(ctx->id("BEL")); bool packed_dff = false; if (dff) { @@ -100,7 +100,7 @@ static void pack_nonlut_ffs(Context *ctx) for (auto cell : sorted(ctx->cells)) { CellInfo *ci = cell.second; if (is_ff(ctx, ci)) { - CellInfo *packed = create_ice_cell(ctx, "ICESTORM_LC", + CellInfo *packed = create_ice_cell(ctx, ctx->id("ICESTORM_LC"), ci->name.str(ctx) + "_DFFLC"); std::copy(ci->attrs.begin(), ci->attrs.end(), std::inserter(packed->attrs, packed->attrs.begin())); @@ -131,18 +131,18 @@ static void pack_carries(Context *ctx) CellInfo *ci = cell.second; if (is_carry(ctx, ci)) { packed_cells.insert(cell.first); - CellInfo *carry_ci_lc = net_only_drives(ctx, ci->ports.at("CI").net, - is_lc, "I3", false); - if (!ci->ports.at("I0").net) + CellInfo *carry_ci_lc = net_only_drives(ctx, ci->ports.at(ctx->id("CI")).net, + is_lc, ctx->id("I3"), false); + if (!ci->ports.at(ctx->id("I0")).net) log_error("SB_CARRY '%s' has disconnected port I0\n", cell.first.c_str(ctx)); - if (!ci->ports.at("I1").net) + if (!ci->ports.at(ctx->id("I1")).net) log_error("SB_CARRY '%s' has disconnected port I1\n", cell.first.c_str(ctx)); std::unordered_set i0_matches, i1_matches; - auto &i0_usrs = ci->ports.at("I0").net->users; - auto &i1_usrs = ci->ports.at("I1").net->users; + auto &i0_usrs = ci->ports.at(ctx->id("I0")).net->users; + auto &i1_usrs = ci->ports.at(ctx->id("I1")).net->users; // Find logic cells connected to both I0 and I1 for (auto usr : i0_usrs) { if (is_lc(ctx, usr.cell) && usr.port == ctx->id("I1")) @@ -173,8 +173,8 @@ static void pack_carries(Context *ctx) carry_lc = ctx->cells.at(*carry_lcs.begin()); } carry_lc->attrs[ctx->id("CARRY_ENABLE")] = "1"; - replace_port(ci, "CI", carry_lc, "CIN"); - replace_port(ci, "CO", carry_lc, "COUT"); + replace_port(ci, ctx->id("CI"), carry_lc, ctx->id("CIN")); + replace_port(ci, ctx->id("CO"), carry_lc, ctx->id("COUT")); i0_usrs.erase(std::remove_if(i0_usrs.begin(), i0_usrs.end(), [ci, ctx](const PortRef &pr) { @@ -205,29 +205,29 @@ static void pack_ram(Context *ctx) for (auto cell : sorted(ctx->cells)) { CellInfo *ci = cell.second; if (is_ram(ctx, ci)) { - CellInfo *packed = create_ice_cell(ctx, "ICESTORM_RAM", + CellInfo *packed = create_ice_cell(ctx, ctx->id("ICESTORM_RAM"), ci->name.str(ctx) + "_RAM"); packed_cells.insert(ci->name); new_cells.push_back(packed); for (auto param : ci->params) packed->params[param.first] = param.second; - packed->params["NEG_CLK_W"] = + packed->params[ctx->id("NEG_CLK_W")] = std::to_string(ci->type == ctx->id("SB_RAM40_4KNW") || ci->type == ctx->id("SB_RAM40_4KNRNW")); - packed->params["NEG_CLK_R"] = + packed->params[ctx->id("NEG_CLK_R")] = std::to_string(ci->type == ctx->id("SB_RAM40_4KNR") || ci->type == ctx->id("SB_RAM40_4KNRNW")); packed->type = ctx->id("ICESTORM_RAM"); for (auto port : ci->ports) { PortInfo &pi = port.second; - std::string newname = pi.name; + std::string newname = pi.name.str(ctx); size_t bpos = newname.find('['); if (bpos != std::string::npos) { newname = newname.substr(0, bpos) + "_" + newname.substr(bpos + 1, (newname.size() - bpos) - 2); } - replace_port(ci, pi.name, packed, newname); + replace_port(ci, ctx->id(pi.name.c_str(ctx)), packed, ctx->id(newname)); } } } @@ -268,14 +268,14 @@ static void pack_constants(Context *ctx) { log_info("Packing constants..\n"); - CellInfo *gnd_cell = create_ice_cell(ctx, "ICESTORM_LC", "$PACKER_GND"); + CellInfo *gnd_cell = create_ice_cell(ctx, ctx->id("ICESTORM_LC"), "$PACKER_GND"); gnd_cell->params[ctx->id("LUT_INIT")] = "0"; NetInfo *gnd_net = new NetInfo; - gnd_net->name = "$PACKER_GND_NET"; + gnd_net->name = ctx->id("$PACKER_GND_NET"); gnd_net->driver.cell = gnd_cell; gnd_net->driver.port = ctx->id("O"); - CellInfo *vcc_cell = create_ice_cell(ctx, "ICESTORM_LC", "$PACKER_VCC"); + CellInfo *vcc_cell = create_ice_cell(ctx, ctx->id("ICESTORM_LC"), "$PACKER_VCC"); vcc_cell->params[ctx->id("LUT_INIT")] = "1"; NetInfo *vcc_net = new NetInfo; vcc_net->name = ctx->id("$PACKER_VCC_NET"); @@ -336,12 +336,12 @@ static void pack_io(Context *ctx) CellInfo *sb = nullptr; if (ci->type == ctx->id("$nextpnr_ibuf") || ci->type == ctx->id("$nextpnr_iobuf")) { - sb = net_only_drives(ctx, ci->ports.at("O").net, is_sb_io, - "PACKAGE_PIN", true, ci); + sb = net_only_drives(ctx, ci->ports.at(ctx->id("O")).net, is_sb_io, + ctx->id("PACKAGE_PIN"), true, ci); } else if (ci->type == ctx->id("$nextpnr_obuf")) { - sb = net_only_drives(ctx, ci->ports.at("I").net, is_sb_io, - "PACKAGE_PIN", true, ci); + sb = net_only_drives(ctx, ci->ports.at(ctx->id("I")).net, is_sb_io, + ctx->id("PACKAGE_PIN"), true, ci); } if (sb != nullptr) { // Trivial case, SB_IO used. Just destroy the net and the @@ -349,14 +349,14 @@ static void pack_io(Context *ctx) log_info("%s feeds SB_IO %s, removing %s %s.\n", ci->name.c_str(ctx), sb->name.c_str(ctx), ci->type.c_str(ctx), ci->name.c_str(ctx)); - NetInfo *net = sb->ports.at("PACKAGE_PIN").net; + NetInfo *net = sb->ports.at(ctx->id("PACKAGE_PIN")).net; if (net != nullptr) { ctx->nets.erase(net->name); - sb->ports.at("PACKAGE_PIN").net = nullptr; + sb->ports.at(ctx->id("PACKAGE_PIN")).net = nullptr; } } else { // Create a SB_IO buffer - sb = create_ice_cell(ctx, "SB_IO", + sb = create_ice_cell(ctx, ctx->id("SB_IO"), ci->name.str(ctx) + "$sb_io"); nxio_to_sb(ctx, ci, sb); new_cells.push_back(sb); @@ -379,7 +379,7 @@ static void insert_global(Context *ctx, NetInfo *net, bool is_reset, { std::string glb_name = net->name.str(ctx) + std::string("_$glb_") + (is_reset ? "sr" : (is_cen ? "ce" : "clk")); - CellInfo *gb = create_ice_cell(ctx, "SB_GB", "$gbuf_" + glb_name); + CellInfo *gb = create_ice_cell(ctx, ctx->id("SB_GB"), "$gbuf_" + glb_name); gb->ports[ctx->id("USER_SIGNAL_TO_GLOBAL_BUFFER")].net = net; PortRef pr; pr.cell = gb; @@ -496,16 +496,16 @@ static void pack_intosc(Context *ctx) for (auto cell : sorted(ctx->cells)) { CellInfo *ci = cell.second; if (is_sb_lfosc(ctx, ci)) { - CellInfo *packed = create_ice_cell(ctx, "ICESTORM_LFOSC", + CellInfo *packed = create_ice_cell(ctx, ctx->id("ICESTORM_LFOSC"), ci->name.str(ctx) + "_OSC"); packed_cells.insert(ci->name); new_cells.push_back(packed); - replace_port(ci, "CLKLFEN", packed, "CLKLFEN"); - replace_port(ci, "CLKLFPU", packed, "CLKLFPU"); - if (bool_or_default(ci->attrs, "ROUTE_THROUGH_FABRIC")) { - replace_port(ci, "CLKLF", packed, "CLKLF_FABRIC"); + replace_port(ci, ctx->id("CLKLFEN"), packed, ctx->id("CLKLFEN")); + replace_port(ci, ctx->id("CLKLFPU"), packed, ctx->id("CLKLFPU")); + if (bool_or_default(ci->attrs, ctx->id("ROUTE_THROUGH_FABRIC"))) { + replace_port(ci, ctx->id("CLKLF"), packed, ctx->id("CLKLF_FABRIC")); } else { - replace_port(ci, "CLKLF", packed, "CLKLF"); + replace_port(ci, ctx->id("CLKLF"), packed, ctx->id("CLKLF")); } } } diff --git a/ice40/pcf.cc b/ice40/pcf.cc index 13fe199e..51f67364 100644 --- a/ice40/pcf.cc +++ b/ice40/pcf.cc @@ -52,7 +52,7 @@ bool apply_pcf(Context *ctx, std::istream &in) args_end++; std::string cell = words.at(args_end); std::string pin = words.at(args_end + 1); - auto fnd_cell = ctx->cells.find(cell); + auto fnd_cell = ctx->cells.find(ctx->id(cell)); if (fnd_cell == ctx->cells.end()) { log_warning("unmatched pcf constraint %s\n", cell.c_str()); } else { @@ -60,10 +60,10 @@ bool apply_pcf(Context *ctx, std::istream &in) if (pin_bel == BelId()) log_error("package does not have a pin named %s\n", pin.c_str()); - fnd_cell->second->attrs["BEL"] = - ctx->getBelName(pin_bel).str(); + fnd_cell->second->attrs[ctx->id("BEL")] = + ctx->getBelName(pin_bel).str(ctx); log_info("constrained '%s' to bel '%s'\n", cell.c_str(), - fnd_cell->second->attrs["BEL"].c_str()); + fnd_cell->second->attrs[ctx->id("BEL")].c_str()); } } else { log_error("unsupported pcf command '%s'\n", cmd.c_str());