Add fast IdString <-> PortPin conversion
Signed-off-by: Clifford Wolf <clifford@clifford.at>
This commit is contained in:
parent
7e879953d6
commit
9c275d0a65
@ -28,7 +28,15 @@ void IdString::initialize()
|
||||
{
|
||||
database_str_to_idx = new std::unordered_map<std::string, int>;
|
||||
database_idx_to_str = new std::vector<const std::string*>;
|
||||
auto insert_rc = database_str_to_idx->insert({std::string(), 0});
|
||||
initialize_add("", 0);
|
||||
initialize_chip();
|
||||
}
|
||||
|
||||
void IdString::initialize_add(const char *s, int idx)
|
||||
{
|
||||
assert(database_str_to_idx->count(s) == 0);
|
||||
assert(database_idx_to_str->size() == idx);
|
||||
auto insert_rc = database_str_to_idx->insert({s, idx});
|
||||
database_idx_to_str->push_back(&insert_rc.first->first);
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,9 @@ struct IdString
|
||||
static std::unordered_map<std::string, int> *database_str_to_idx;
|
||||
static std::vector<const std::string*> *database_idx_to_str;
|
||||
|
||||
void initialize();
|
||||
static void initialize();
|
||||
static void initialize_chip();
|
||||
static void initialize_add(const char *s, int idx);
|
||||
|
||||
IdString() {}
|
||||
|
||||
|
@ -24,6 +24,9 @@ NEXTPNR_NAMESPACE_BEGIN
|
||||
Chip::Chip(ChipArgs) {}
|
||||
|
||||
std::string Chip::getChipName() { return "Dummy"; }
|
||||
|
||||
void IdString::initialize_chip() {}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
BelId Chip::getBelByName(IdString name) const { return BelId(); }
|
||||
|
@ -52,27 +52,25 @@ BelType belTypeFromId(IdString id)
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
void IdString::initialize_chip()
|
||||
{
|
||||
#define X(t) initialize_add(#t, PIN_##t);
|
||||
#include "portpins.inc"
|
||||
#undef X
|
||||
}
|
||||
|
||||
IdString portPinToId(PortPin type)
|
||||
{
|
||||
#define X(t) \
|
||||
if (type == PIN_##t) \
|
||||
return #t;
|
||||
|
||||
#include "portpins.inc"
|
||||
|
||||
#undef X
|
||||
return IdString();
|
||||
IdString ret;
|
||||
if (type > 0 && type < PIN_MAXIDX)
|
||||
ret.index = type;
|
||||
return ret;
|
||||
}
|
||||
|
||||
PortPin portPinFromId(IdString id)
|
||||
{
|
||||
#define X(t) \
|
||||
if (id == #t) \
|
||||
return PIN_##t;
|
||||
|
||||
#include "portpins.inc"
|
||||
|
||||
#undef X
|
||||
if (id.index > 0 && id.index < PIN_MAXIDX)
|
||||
return PortPin(id.index);
|
||||
return PIN_NONE;
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,7 @@ enum PortPin
|
||||
#define X(t) PIN_##t,
|
||||
#include "portpins.inc"
|
||||
#undef X
|
||||
PIN_MAXIDX
|
||||
};
|
||||
|
||||
IdString portPinToId(PortPin type);
|
||||
|
Loading…
Reference in New Issue
Block a user