Getting rid of users of old IdString API

Signed-off-by: Clifford Wolf <clifford@clifford.at>
This commit is contained in:
Clifford Wolf 2018-06-18 15:53:18 +02:00
parent 71d07fd0bf
commit 0dd185a141
8 changed files with 80 additions and 65 deletions

View File

@ -63,9 +63,9 @@ void log_warning(const char *format, ...) NXP_ATTRIBUTE(format(printf, 1, 2));
void log_warning_noprefix(const char *format, ...) void log_warning_noprefix(const char *format, ...)
NXP_ATTRIBUTE(format(printf, 1, 2)); NXP_ATTRIBUTE(format(printf, 1, 2));
NXP_NORETURN void log_error(const char *format, ...) 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_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_spacer();
void log_push(); void log_push();

View File

@ -23,7 +23,7 @@ NEXTPNR_NAMESPACE_BEGIN
Context *IdString::global_ctx = nullptr; 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); auto it = ctx->idstring_str_to_idx->find(s);
if (it == ctx->idstring_str_to_idx->end()) { 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); 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(ctx->idstring_str_to_idx->count(s) == 0);
assert(int(ctx->idstring_idx_to_str->size()) == idx); assert(int(ctx->idstring_idx_to_str->size()) == idx);

View File

@ -49,27 +49,19 @@ struct IdString
static Context *global_ctx; static Context *global_ctx;
static void initialize_arch(Context *ctx); static void initialize_arch(const Context *ctx);
static void initialize_add(Context *ctx, const char *s, int idx); static void initialize_add(const Context *ctx, const char *s, int idx);
IdString() {} 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) IdString(const Context *ctx, const std::string &s) { set(ctx, s); }
{
assert(global_ctx != nullptr);
set(global_ctx, s);
}
IdString(Context *ctx, const char *s) IdString(const Context *ctx, const char *s) { set(ctx, s); }
{
assert(global_ctx != nullptr);
set(global_ctx, s);
}
const std::string &str(Context *ctx) const; const std::string &str(const Context *ctx) const;
const char *c_str(Context *ctx) const; const char *c_str(const Context *ctx) const;
bool operator<(const IdString &other) const { return index < other.index; } bool operator<(const IdString &other) const { return index < other.index; }
@ -119,35 +111,45 @@ struct IdString
operator const char *() const __attribute__((deprecated)) 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)) 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)) 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)) 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)) 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)) 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 NEXTPNR_NAMESPACE_END
@ -234,11 +236,14 @@ struct Context : Arch
{ {
// -------------------------------------------------------------- // --------------------------------------------------------------
std::unordered_map<std::string, int> *idstring_str_to_idx; mutable std::unordered_map<std::string, int> *idstring_str_to_idx;
std::vector<const std::string *> *idstring_idx_to_str; mutable std::vector<const std::string *> *idstring_idx_to_str;
IdString id(const std::string &s) { return IdString(this, s); } IdString id(const std::string &s) const override
IdString id(const char *s) { return IdString(this, s); } {
return IdString(this, s);
}
IdString id(const char *s) const override { return IdString(this, s); }
// -------------------------------------------------------------- // --------------------------------------------------------------

View File

@ -71,21 +71,21 @@ struct Router
auto net_info = ctx->nets.at(net_name); auto net_info = ctx->nets.at(net_name);
if (verbose) if (verbose)
log("Routing net %s.\n", net_name.c_str()); log("Routing net %s.\n", net_name.c_str(ctx));
if (verbose) if (verbose)
log(" Source: %s.%s.\n", net_info->driver.cell->name.c_str(), log(" Source: %s.%s.\n", net_info->driver.cell->name.c_str(ctx),
net_info->driver.port.c_str()); net_info->driver.port.c_str(ctx));
auto src_bel = net_info->driver.cell->bel; auto src_bel = net_info->driver.cell->bel;
if (src_bel == BelId()) if (src_bel == BelId())
log_error("Source cell %s (%s) is not mapped to a bel.\n", log_error("Source cell %s (%s) is not mapped to a bel.\n",
net_info->driver.cell->name.c_str(), net_info->driver.cell->name.c_str(ctx),
net_info->driver.cell->type.c_str()); net_info->driver.cell->type.c_str(ctx));
if (verbose) 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; IdString driver_port = net_info->driver.port;
@ -98,12 +98,12 @@ struct Router
if (src_wire == WireId()) if (src_wire == WireId())
log_error("No wire found for port %s (pin %s) on source cell %s " log_error("No wire found for port %s (pin %s) on source cell %s "
"(bel %s).\n", "(bel %s).\n",
net_info->driver.port.c_str(), driver_port.c_str(), net_info->driver.port.c_str(ctx), driver_port.c_str(ctx),
net_info->driver.cell->name.c_str(), net_info->driver.cell->name.c_str(ctx),
ctx->getBelName(src_bel).c_str()); ctx->getBelName(src_bel).c_str(ctx));
if (verbose) 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; std::unordered_map<WireId, DelayInfo> src_wires;
src_wires[src_wire] = DelayInfo(); src_wires[src_wire] = DelayInfo();
@ -112,19 +112,19 @@ struct Router
for (auto &user_it : net_info->users) { for (auto &user_it : net_info->users) {
if (verbose) if (verbose)
log(" Route to: %s.%s.\n", user_it.cell->name.c_str(), log(" Route to: %s.%s.\n", user_it.cell->name.c_str(ctx),
user_it.port.c_str()); user_it.port.c_str(ctx));
auto dst_bel = user_it.cell->bel; auto dst_bel = user_it.cell->bel;
if (dst_bel == BelId()) if (dst_bel == BelId())
log_error("Destination cell %s (%s) is not mapped to a bel.\n", log_error("Destination cell %s (%s) is not mapped to a bel.\n",
user_it.cell->name.c_str(), user_it.cell->name.c_str(ctx),
user_it.cell->type.c_str()); user_it.cell->type.c_str(ctx));
if (verbose) if (verbose)
log(" Destination bel: %s\n", log(" Destination bel: %s\n",
ctx->getBelName(dst_bel).c_str()); ctx->getBelName(dst_bel).c_str(ctx));
IdString user_port = user_it.port; IdString user_port = user_it.port;
@ -139,13 +139,13 @@ struct Router
if (dst_wire == WireId()) if (dst_wire == WireId())
log_error("No wire found for port %s (pin %s) on destination " log_error("No wire found for port %s (pin %s) on destination "
"cell %s (bel %s).\n", "cell %s (bel %s).\n",
user_it.port.c_str(), user_port.c_str(), user_it.port.c_str(ctx), user_port.c_str(ctx),
user_it.cell->name.c_str(), user_it.cell->name.c_str(ctx),
ctx->getBelName(dst_bel).c_str()); ctx->getBelName(dst_bel).c_str(ctx));
if (verbose) { if (verbose) {
log(" Destination wire: %s\n", log(" Destination wire: %s\n",
ctx->getWireName(dst_wire).c_str()); ctx->getWireName(dst_wire).c_str(ctx));
log(" Path delay estimate: %.2f\n", log(" Path delay estimate: %.2f\n",
float(ctx->estimateDelay(src_wire, dst_wire))); float(ctx->estimateDelay(src_wire, dst_wire)));
} }
@ -225,12 +225,12 @@ struct Router
if (visited.count(dst_wire) == 0) { if (visited.count(dst_wire) == 0) {
if (verbose) if (verbose)
log("Failed to route %s -> %s.\n", log("Failed to route %s -> %s.\n",
ctx->getWireName(src_wire).c_str(), ctx->getWireName(src_wire).c_str(ctx),
ctx->getWireName(dst_wire).c_str()); ctx->getWireName(dst_wire).c_str(ctx));
else if (ripup) else if (ripup)
log_info("Failed to route %s -> %s.\n", log_info("Failed to route %s -> %s.\n",
ctx->getWireName(src_wire).c_str(), ctx->getWireName(src_wire).c_str(ctx),
ctx->getWireName(dst_wire).c_str()); ctx->getWireName(dst_wire).c_str(ctx));
ripup_net(ctx, net_name); ripup_net(ctx, net_name);
failedDest = dst_wire; failedDest = dst_wire;
return; return;
@ -249,7 +249,7 @@ struct Router
while (1) { while (1) {
if (verbose) if (verbose)
log(" %8.2f %s\n", float(visited[cursor].delay), 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)) if (src_wires.count(cursor))
break; break;
@ -386,7 +386,7 @@ bool route_design(Context *ctx, bool verbose)
for (auto net_name : netsQueue) { for (auto net_name : netsQueue) {
if (printNets) 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())); int(ctx->nets.at(net_name)->users.size()));
Router router(ctx, net_name, verbose, false); Router router(ctx, net_name, verbose, false);
@ -398,7 +398,7 @@ bool route_design(Context *ctx, bool verbose)
if (!router.routedOkay) { if (!router.routedOkay) {
if (printNets) if (printNets)
log_info(" failed to route to %s.\n", 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); ripupQueue.insert(net_name);
} }
@ -429,7 +429,8 @@ bool route_design(Context *ctx, bool verbose)
for (auto net_name : ripupQueue) { for (auto net_name : ripupQueue) {
if (printNets) 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())); int(ctx->nets.at(net_name)->users.size()));
Router router(ctx, net_name, verbose, true, Router router(ctx, net_name, verbose, true,
@ -441,7 +442,7 @@ bool route_design(Context *ctx, bool verbose)
if (!router.routedOkay) if (!router.routedOkay)
log_error("Net %s is impossible to route.\n", log_error("Net %s is impossible to route.\n",
net_name.c_str()); net_name.c_str(ctx));
for (auto it : router.rippedNets) for (auto it : router.rippedNets)
netsQueue.insert(it); netsQueue.insert(it);
@ -451,7 +452,7 @@ bool route_design(Context *ctx, bool verbose)
log_info(" ripped up %d other nets:\n", log_info(" ripped up %d other nets:\n",
int(router.rippedNets.size())); int(router.rippedNets.size()));
for (auto n : router.rippedNets) 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())); int(ctx->nets.at(n)->users.size()));
} else { } else {
log_info(" ripped up %d other nets.\n", log_info(" ripped up %d other nets.\n",

View File

@ -26,7 +26,7 @@ Arch::Arch(ArchArgs) {}
std::string Arch::getChipName() { return "Dummy"; } std::string Arch::getChipName() { return "Dummy"; }
void IdString::initialize_arch(Context *ctx) {} void IdString::initialize_arch(const Context *ctx) {}
// --------------------------------------------------------------- // ---------------------------------------------------------------

View File

@ -73,6 +73,9 @@ struct Arch
std::string getChipName(); std::string getChipName();
virtual IdString id(const std::string &s) const { abort(); }
virtual IdString id(const char *s) const { abort(); }
BelId getBelByName(IdString name) const; BelId getBelByName(IdString name) const;
IdString getBelName(BelId bel) const; IdString getBelName(BelId bel) const;
void bindBel(BelId bel, IdString cell); void bindBel(BelId bel, IdString cell);

View File

@ -54,7 +54,7 @@ BelType belTypeFromId(IdString id)
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
void IdString::initialize_arch(Context *ctx) void IdString::initialize_arch(const Context *ctx)
{ {
#define X(t) initialize_add(ctx, #t, PIN_##t); #define X(t) initialize_add(ctx, #t, PIN_##t);
#include "portpins.inc" #include "portpins.inc"

View File

@ -477,6 +477,9 @@ struct Arch
std::string getChipName(); std::string getChipName();
virtual IdString id(const std::string &s) const { abort(); }
virtual IdString id(const char *s) const { abort(); }
// ------------------------------------------------- // -------------------------------------------------
BelId getBelByName(IdString name) const; BelId getBelByName(IdString name) const;
@ -484,7 +487,7 @@ struct Arch
IdString getBelName(BelId bel) const IdString getBelName(BelId bel) const
{ {
assert(bel != BelId()); assert(bel != BelId());
return chip_info->bel_data[bel.index].name.get(); return id(chip_info->bel_data[bel.index].name.get());
} }
void bindBel(BelId bel, IdString cell) void bindBel(BelId bel, IdString cell)
@ -576,7 +579,7 @@ struct Arch
IdString getWireName(WireId wire) const IdString getWireName(WireId wire) const
{ {
assert(wire != WireId()); assert(wire != WireId());
return chip_info->wire_data[wire.index].name.get(); return id(chip_info->wire_data[wire.index].name.get());
} }
void bindWire(WireId wire, IdString net) void bindWire(WireId wire, IdString net)