diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/log.h | 4 | ||||
-rw-r--r-- | common/nextpnr.cc | 11 | ||||
-rw-r--r-- | common/nextpnr.h | 57 | ||||
-rw-r--r-- | common/route.cc | 59 |
4 files changed, 70 insertions, 61 deletions
diff --git a/common/log.h b/common/log.h index 7d87c038..8afa94d4 100644 --- a/common/log.h +++ b/common/log.h @@ -63,9 +63,9 @@ void log_warning(const char *format, ...) NXP_ATTRIBUTE(format(printf, 1, 2)); void log_warning_noprefix(const char *format, ...) NXP_ATTRIBUTE(format(printf, 1, 2)); NXP_NORETURN void log_error(const char *format, ...) - NXP_ATTRIBUTE(format(printf, 1, 2)); + NXP_ATTRIBUTE(format(printf, 1, 2), noreturn); NXP_NORETURN void log_cmd_error(const char *format, ...) - NXP_ATTRIBUTE(format(printf, 1, 2)); + NXP_ATTRIBUTE(format(printf, 1, 2), noreturn); void log_spacer(); void log_push(); diff --git a/common/nextpnr.cc b/common/nextpnr.cc index 0b1008ac..dbe2a6f7 100644 --- a/common/nextpnr.cc +++ b/common/nextpnr.cc @@ -23,7 +23,7 @@ NEXTPNR_NAMESPACE_BEGIN Context *IdString::global_ctx = nullptr; -void IdString::set(Context *ctx, const std::string &s) +void IdString::set(const Context *ctx, const std::string &s) { auto it = ctx->idstring_str_to_idx->find(s); if (it == ctx->idstring_str_to_idx->end()) { @@ -35,14 +35,17 @@ void IdString::set(Context *ctx, const std::string &s) } } -const std::string &IdString::str(Context *ctx) const +const std::string &IdString::str(const Context *ctx) const { return *ctx->idstring_idx_to_str->at(index); } -const char *IdString::c_str(Context *ctx) const { return str(ctx).c_str(); } +const char *IdString::c_str(const Context *ctx) const +{ + return str(ctx).c_str(); +} -void IdString::initialize_add(Context *ctx, const char *s, int idx) +void IdString::initialize_add(const Context *ctx, const char *s, int idx) { assert(ctx->idstring_str_to_idx->count(s) == 0); assert(int(ctx->idstring_idx_to_str->size()) == idx); diff --git a/common/nextpnr.h b/common/nextpnr.h index c2352c1d..b8305247 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -49,27 +49,19 @@ struct IdString static Context *global_ctx; - static void initialize_arch(Context *ctx); - static void initialize_add(Context *ctx, const char *s, int idx); + static void initialize_arch(const Context *ctx); + static void initialize_add(const Context *ctx, const char *s, int idx); IdString() {} - void set(Context *ctx, const std::string &s); + void set(const Context *ctx, const std::string &s); - IdString(Context *ctx, const std::string &s) - { - assert(global_ctx != nullptr); - set(global_ctx, s); - } + IdString(const Context *ctx, const std::string &s) { set(ctx, s); } - IdString(Context *ctx, const char *s) - { - assert(global_ctx != nullptr); - set(global_ctx, s); - } + IdString(const Context *ctx, const char *s) { set(ctx, s); } - const std::string &str(Context *ctx) const; - const char *c_str(Context *ctx) const; + const std::string &str(const Context *ctx) const; + const char *c_str(const Context *ctx) const; bool operator<(const IdString &other) const { return index < other.index; } @@ -119,35 +111,45 @@ struct IdString operator const char *() const __attribute__((deprecated)) { - return c_str(); + assert(global_ctx != nullptr); + return c_str(global_ctx); } operator const std::string &() const __attribute__((deprecated)) { - return str(); + assert(global_ctx != nullptr); + return str(global_ctx); } bool operator==(const std::string &s) const __attribute__((deprecated)) { - return str() == s; + assert(global_ctx != nullptr); + return str(global_ctx) == s; } bool operator==(const char *s) const __attribute__((deprecated)) { - return str() == s; + assert(global_ctx != nullptr); + return str(global_ctx) == s; } bool operator!=(const std::string &s) const __attribute__((deprecated)) { - return str() != s; + assert(global_ctx != nullptr); + return str(global_ctx) != s; } bool operator!=(const char *s) const __attribute__((deprecated)) { - return str() != s; + assert(global_ctx != nullptr); + return str(global_ctx) != s; } - size_t size() const __attribute__((deprecated)) { return str().size(); } + size_t size() const __attribute__((deprecated)) + { + assert(global_ctx != nullptr); + return str(global_ctx).size(); + } }; NEXTPNR_NAMESPACE_END @@ -234,11 +236,14 @@ struct Context : Arch { // -------------------------------------------------------------- - std::unordered_map<std::string, int> *idstring_str_to_idx; - std::vector<const std::string *> *idstring_idx_to_str; + mutable std::unordered_map<std::string, int> *idstring_str_to_idx; + mutable std::vector<const std::string *> *idstring_idx_to_str; - IdString id(const std::string &s) { return IdString(this, s); } - IdString id(const char *s) { return IdString(this, s); } + IdString id(const std::string &s) const override + { + return IdString(this, s); + } + IdString id(const char *s) const override { return IdString(this, s); } // -------------------------------------------------------------- diff --git a/common/route.cc b/common/route.cc index 080440d6..e1b60f84 100644 --- a/common/route.cc +++ b/common/route.cc @@ -71,21 +71,21 @@ struct Router auto net_info = ctx->nets.at(net_name); if (verbose) - log("Routing net %s.\n", net_name.c_str()); + log("Routing net %s.\n", net_name.c_str(ctx)); if (verbose) - log(" Source: %s.%s.\n", net_info->driver.cell->name.c_str(), - net_info->driver.port.c_str()); + log(" Source: %s.%s.\n", net_info->driver.cell->name.c_str(ctx), + net_info->driver.port.c_str(ctx)); auto src_bel = net_info->driver.cell->bel; if (src_bel == BelId()) log_error("Source cell %s (%s) is not mapped to a bel.\n", - net_info->driver.cell->name.c_str(), - net_info->driver.cell->type.c_str()); + net_info->driver.cell->name.c_str(ctx), + net_info->driver.cell->type.c_str(ctx)); if (verbose) - log(" Source bel: %s\n", ctx->getBelName(src_bel).c_str()); + log(" Source bel: %s\n", ctx->getBelName(src_bel).c_str(ctx)); IdString driver_port = net_info->driver.port; @@ -98,12 +98,12 @@ struct Router if (src_wire == WireId()) log_error("No wire found for port %s (pin %s) on source cell %s " "(bel %s).\n", - net_info->driver.port.c_str(), driver_port.c_str(), - net_info->driver.cell->name.c_str(), - ctx->getBelName(src_bel).c_str()); + net_info->driver.port.c_str(ctx), driver_port.c_str(ctx), + net_info->driver.cell->name.c_str(ctx), + ctx->getBelName(src_bel).c_str(ctx)); if (verbose) - log(" Source wire: %s\n", ctx->getWireName(src_wire).c_str()); + log(" Source wire: %s\n", ctx->getWireName(src_wire).c_str(ctx)); std::unordered_map<WireId, DelayInfo> src_wires; src_wires[src_wire] = DelayInfo(); @@ -112,19 +112,19 @@ struct Router for (auto &user_it : net_info->users) { if (verbose) - log(" Route to: %s.%s.\n", user_it.cell->name.c_str(), - user_it.port.c_str()); + log(" Route to: %s.%s.\n", user_it.cell->name.c_str(ctx), + user_it.port.c_str(ctx)); auto dst_bel = user_it.cell->bel; if (dst_bel == BelId()) log_error("Destination cell %s (%s) is not mapped to a bel.\n", - user_it.cell->name.c_str(), - user_it.cell->type.c_str()); + user_it.cell->name.c_str(ctx), + user_it.cell->type.c_str(ctx)); if (verbose) log(" Destination bel: %s\n", - ctx->getBelName(dst_bel).c_str()); + ctx->getBelName(dst_bel).c_str(ctx)); IdString user_port = user_it.port; @@ -139,13 +139,13 @@ struct Router if (dst_wire == WireId()) log_error("No wire found for port %s (pin %s) on destination " "cell %s (bel %s).\n", - user_it.port.c_str(), user_port.c_str(), - user_it.cell->name.c_str(), - ctx->getBelName(dst_bel).c_str()); + user_it.port.c_str(ctx), user_port.c_str(ctx), + user_it.cell->name.c_str(ctx), + ctx->getBelName(dst_bel).c_str(ctx)); if (verbose) { log(" Destination wire: %s\n", - ctx->getWireName(dst_wire).c_str()); + ctx->getWireName(dst_wire).c_str(ctx)); log(" Path delay estimate: %.2f\n", float(ctx->estimateDelay(src_wire, dst_wire))); } @@ -225,12 +225,12 @@ struct Router if (visited.count(dst_wire) == 0) { if (verbose) log("Failed to route %s -> %s.\n", - ctx->getWireName(src_wire).c_str(), - ctx->getWireName(dst_wire).c_str()); + ctx->getWireName(src_wire).c_str(ctx), + ctx->getWireName(dst_wire).c_str(ctx)); else if (ripup) log_info("Failed to route %s -> %s.\n", - ctx->getWireName(src_wire).c_str(), - ctx->getWireName(dst_wire).c_str()); + ctx->getWireName(src_wire).c_str(ctx), + ctx->getWireName(dst_wire).c_str(ctx)); ripup_net(ctx, net_name); failedDest = dst_wire; return; @@ -249,7 +249,7 @@ struct Router while (1) { if (verbose) log(" %8.2f %s\n", float(visited[cursor].delay), - ctx->getWireName(cursor).c_str()); + ctx->getWireName(cursor).c_str(ctx)); if (src_wires.count(cursor)) break; @@ -386,7 +386,7 @@ bool route_design(Context *ctx, bool verbose) for (auto net_name : netsQueue) { if (printNets) - log_info(" routing net %s. (%d users)\n", net_name.c_str(), + log_info(" routing net %s. (%d users)\n", net_name.c_str(ctx), int(ctx->nets.at(net_name)->users.size())); Router router(ctx, net_name, verbose, false); @@ -398,7 +398,7 @@ bool route_design(Context *ctx, bool verbose) if (!router.routedOkay) { if (printNets) log_info(" failed to route to %s.\n", - ctx->getWireName(router.failedDest).c_str()); + ctx->getWireName(router.failedDest).c_str(ctx)); ripupQueue.insert(net_name); } @@ -429,7 +429,8 @@ bool route_design(Context *ctx, bool verbose) for (auto net_name : ripupQueue) { if (printNets) - log_info(" routing net %s. (%d users)\n", net_name.c_str(), + log_info(" routing net %s. (%d users)\n", + net_name.c_str(ctx), int(ctx->nets.at(net_name)->users.size())); Router router(ctx, net_name, verbose, true, @@ -441,7 +442,7 @@ bool route_design(Context *ctx, bool verbose) if (!router.routedOkay) log_error("Net %s is impossible to route.\n", - net_name.c_str()); + net_name.c_str(ctx)); for (auto it : router.rippedNets) netsQueue.insert(it); @@ -451,7 +452,7 @@ bool route_design(Context *ctx, bool verbose) log_info(" ripped up %d other nets:\n", int(router.rippedNets.size())); for (auto n : router.rippedNets) - log_info(" %s (%d users)\n", n.c_str(), + log_info(" %s (%d users)\n", n.c_str(ctx), int(ctx->nets.at(n)->users.size())); } else { log_info(" ripped up %d other nets.\n", |